gcc 어 셈 블 리
http://blog.chinaunix.net/u1/48280/showart_1423294.html
1.gcc
(1). gcc ?
- static void * __memcpy(void * to, const void * from, size_t n)
- {
- int d0,d1,d2;
- __asm__ __volatile__(
- "rep;movsl/n/t"
- "testb $2,%b4/n/t"
- "je 1f/n/t"
- "movsw/n"
- "1:/ttestb $1,%b4/n/t"
- "je 2f/n/t"
- "movsb/n"
- "2:"
- :"=&c" (d0), "=&D" (d1), "=&S" (d2)
- :"0" (n/4), "q" (n), "1" ((long) to), "2" ((long) from)
- :"memory");
- return (to);
- }
0,1,2 3,5,6 :
a. 3,5,6 n/4,to from ecx,edi,esi ;
b. 0,1,2 ecx,edi,esi d0,d1,d2 。
c. "&" , , 0 3 ecx, "0" ,
"0" (n/4) "c" (n/4), "=&c" 。
(2). gcc "&" ?
"&" ,
- int bar,foo;
- __asm__ __volatile__(
- "call func /n/t"
- "mov ebx,%1"
- :"=a" (foo)
- :"r" (bar));
gcc bar eax , "=a" "=&a", foo eax, bar 。
(3). _start main ?
main gcc , ld as _start。libc _start main 。
a. _start :as -o a.o a.s,ld -o a a.o; gcc -g -c a.s,ld -o a a.o。( gcc -g,
gcc -o a a.s gcc main , libc _start 。 gcc -o a a.s
, " _start" " main")
b. main C :gcc -o a a.s;gcc -o a a.c。
(4).section .previous
.section .previous , , section ( .text ),
。.section .previous 。
2. AT&T
(1).data,.section , , assembler
(2).section , .data,.text,.bss
(3).globl export,
(4).bss ,
(5) open,read int $80
(6)MOVL $FOO,%EAX FOO EAX , MOVL FOO,%EAX FOO EAX
(7).include " ",
(8) ? c :
- struct para
- {
- char Firstname[40];
- char Lastname[40];
- char Address[240];
- long Age;//4 bytes
- }
- :
- .section data
- record1:
- .ascii "Fredrick/0"
- .rept 31 #Padding to 40 bytes
- .byte 0
- .endr
- .ascii "Bartlett/0"
- .rept 31 #Padding to 40 bytes
- .byte 0
- .endr
- .ascii "4242 S Prairie/nTulsa, OK 55555/0"
- .rept 209 #Padding to 240 bytes
- .byte 0
- .endr
- .long 45
.rept n .endr n ,
(9) , :
as write-records.s -o write-records.o (gcc -g -c write-records.s)
as write-record.s -o write-record.o (gcc -g -c write-record.s)
ld write-record.o write-records.o -o write-records
(10) ?
#helloworld-lib.s
.section .data
helloworld:
.ascii "hello world/n/0"
.section .text
.globl _start
_start:
pushl $helloworld
call printf
pushl $0
call exit
as helloworld-lib.s -o helloworld-lib.o
ld -dynamic-linker /lib/ld-linux.so.2 -o helloworld-lib helloworld-lib.o -lc
:ld -shared write-record.o read-record.o -o librecord.so
(11)
as write-record.s -o write-record.o
as read-record.s -o read-record.o
ld -shared write-record.o read-record.o -o librecord.so
as write-records.s -o write-records.o
ld -L . -dynamic-linker /lib/ld-linux.so.2 -o write-records -lrecord write-records.o
write-records /etc/ld.so.conf , ldconfig
(12)
as --gstabs a.s -0 a.o gcc -g -c a.s
:
(1)
#Parameter #N <--- N*4+4(%ebp)
#...
#Parameter 2 <--- 12(%ebp)
#Parameter 1 <--- 8(%ebp)
#Return Address <--- 4(%ebp)
#Old %ebp <--- (%ebp)
#Local Variable 1 <--- -4(%ebp)
#Local Variable 2 <--- -8(%ebp) and (%esp)
(2)
- .include "external_func.s"
- .section .data
- data_array: # long
- .long 3,67,34,0
- data_strings: #
- .ascii "Hello there/0"
- data_long: # long
- .long 5
- .section .bss
- .lcomm my_buffer, 500 # 500
- .section .text
- .equ LINUX_SYSCALL, 0x80 # LINUX_SYSCALL 0x80
- .globl _start
- _start:
- pushl %edx
- movl data_long,%edx # data_long edx
- movl $data_long,%edx # data_long edx
- popl %edx
- pushl $3 #push second argument
- pushl $2 #push first argument
- call power #call the function
- addl $8, %esp #move the stack pointer back
- pushl %eax #save the first answer before,calling the next function
- movl $1, %eax #exit (%ebx is returned)
- int $LINUX_SYSCALL
- .type power, @function # power
- power:
- pushl %ebp #save old base pointer
- movl %esp, %ebp #make stack pointer the base pointer
- subl $4, %esp #get room for our local storage
- movl 8(%ebp), %eax #put first argument in %eax
- movl 12(%ebp), %ebx #put second argument in %ebx
- imull %ebx,%eax
- movl %ebp, %esp #restore the stack pointer
- popl %ebp #restore the base pointer
- ret
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
용감한 바로 가기 및 우분투 응용 프로그램안녕하세요 여러분, 이 기사에서는 모든 사이트에서 pwa를 생성하고 실행기 응용 프로그램으로 추가하는 방법을 설명하고 싶습니다. 일부 웹사이트는 PWA로 설치를 허용하지 않지만 유사한 애플리케이션을 원합니다. 1. ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.