GCC compiled C language in embedded compilation

xiaoxiao2021-03-06  39

GCC compiled C language in embedded compilation

--At & t and intel compilation syntax

Register Name: AT & T:% Eaxintel: EAX

The AT & T Syntax source address is on the left and the destination address reverse the EBXAT & T: MOVL% EAX,% EBXINTEL: MOV EBX, EBXINTEL: MOV EBX, EBXINTEL: MOV EBX, EBXINTEL: MOV EBX

AT & T syntax is prefixed before the prefix $. AT & T: MOVL $ 0x0h,% Eaxintel: Mov Eax, 0x0h

The AT & T syntax follows the suffix B, W, and L, W, L, represents bytes, words, double words, respectively, the pseudo-operator PTR, if not, if the GAS will Guessat & T: MOVW% AX,% BXintel: MOV BX, AX

Memory Addressing AT & T: IMMED32 (Basepointer, IndexPointer, IndexScale) Intel: [Basepointer IndexPointer * IndexScale Immed32]

Address Calculation Formula is: IMMED32 BASEPOINTER INDEXPOINTER * INDEXSCALE

Direct address

AT & T: _AINTEL: [_A]

Indirect Addressing AT & T: (% EAX) Intel: [EAX]

Relative to AT & T: _variable (% EAX) Intel: [EAX _VARIABLE]

AT & T: _Array (,% Eax, 4) Intel: [EAX * 4 Array]

C code: * (p 1) P Defined as Char * AT & T: 1 (% EAX) Where Eax Has The Value of Pintel: [EAX 1]

Structural array addressing, structural length is 8, subscript in EAX, the interior offset address is stored in EBX, _Array is the first address of the structure

AT & T: _Array (% EBX,% EAX, 8) Intel: [EBX EAX * 8 _Array] Function Internal Implementation Switch 1 R "The registers specified in (a) are the same int Main () {804842c: MOV 0xFfffff4 (% EBP),% ECX INT A = 10, B = 0; 804842F: MOV 0xfffffff0 (% EBP), % EDX Printf ("Before Swap: A =% 2D, B =% 2D / N", A, B); 8048432: MOV% ECX,% EBX __ASM __ ("NOP; 8048434: MOV% EDX,% ESI MOVL% 0 %% EAX; 8048436: NOP MOVL% 1,% 0; 8048437: MOV% EBX,% EAX MOVL %% EAX,% 1; 8048439: MOV% ESI,% EBX NOP; " 804843B: MOV% EAX,% ESI: 804843D: NOP "= r" (a), "= R" (b) 804843e: MOV% EBX,% EDX: 8048440: MOV% ESI,% ECX "0" (a) , "1"

(b) 8048442: MOV% EDX,% EAX: 8048444: MOV% EAX, 0xfffffff4 (% EBP) "% EAX" 8048447: MOV% ECX,% EAX); 8048449: MOV% EAX, 0xffffff0 (% EBP) Printf "After SWAP: A =% 2D, B =% 2D / N", A, B); RETURN 0;} 2, input and output Different registers, & indicates that the input and output need to allocate different registers int main () { INT A = 10, B = 0; Printf ("Before Swap: A =% 2D, B =% 2D / N", A, B); 804842B: MOV 0xfffffff8 (% EBP),% EDX __ASM __ ("NOP; 804842e : MOV 0xfffffff4 (% E BP),% EAX MOVL% 2,% 1; 8048431: NOP MOVL% 3,% 0; 8048432: MOV% EDX,% EBX NOP; "8048434: MOV% EAX,% ECX: 8048436: NOP" = & r " a), "= & r"

(b) 8048437: MOV% ECX,% EAX: 8048439: MOV% EBX,% EDX "R" (A), "R" (b) 804843b: MOV% EAX,% EAX); 804843D: MOV% EAX, 0xfffffff (% EBP) Printf ("After Swap: A =% 2D, B =% 2D / N", A, B); 8048440: MOV% EDX,% EAX RETURN 0; 8048442: MOV% EAX, 0xfffffff4 (% EBP) } 3, exchange functions, need indirect addressing #include

Void swap (int * x, int * y) 08048400 : {8048400: push% EBP __ASM __ ("NOP; 8048401: MOV% ESP,% EBP MOVL (% 0), %% EAX; 8048403: PUSH% EBX MOVL (% 1), %% EBX; 8048404: MOV 0x8 (% EBP),% ECX MOVL %% EBX, (% 0); 8048407: MOV 0xc (% EBP),% EDX MOVL %% EAX, (% 1 ); 804840a: NOP NOP; "804840b: MOV (% ECX),% EAX: 804840d: MOV (% EDX),% EBX: 804840F: MOV% EBX, (% ECX) "R" (x), "R" 8048411: MOV% EAX, (% EDX): 8048413: NOP "EAX "," EBX "," Memory "8048414: MOV (% ESP, 1),% EBX; EBX restore); 8048417: Leave; MOVL% EBP,% ESP;

POP EBP} 8048418: RET 8048419: LEA 0x0 (% ESI),% ESIINT Main () {INT A = 10, B = 0; Printf ("Before Swap: a =% 2D, B =% 2D / N", A , B); SWAP (& A, & B); Printf ("After Swap: A =% 2D, B =% 2D / N", A, B); RETURN 0;} 4, from assembly code Separate function

1> Get assembly code here with addition functions, source code is: int SUM (int A, int b) {INT C = A B; Return C;} The corresponding assembly code is disassembly of section .text: 00000000 : 0: 55 push% EBP 1: 89 E5 MOV% ESP,% EBP 3: 83 EC 04 SUB $ 0X4,% ESP 6: 8B 45 0C MOV 0xC (% EBP),% EAX 9: 03 45 08 Add 0x8 ( % EBP),% EAX C: 89 45 FC MOV% EAX, 0xfffffffc (% EBP) F: 8B 45 FC MOV 0xffffffFFFC (% EBP),% EAX 12: 89 C0 MOV% EAX,% EAX 14: C9 Leave 15: C3 RET 16: 89 F6 MOV% ESI,% ESI

2> Write an inline assembly language function analysis: Build a runtime stack for functions to make it smoothly running, due to the compiler to increase Routine Begin: Push% EBP; MOV% ESP,% EBPROUTINE END : Leave; RET removes the top 0, 1, 14, 15, and the return parameter is placed in EAX to set the output section to "= a" (r) with EAX register R. Return Type step: i Define Return_Type R variable II removes PUSH% EBP; MOV% ESP,% EBP; Leave; RETIII output section is: "= a" (r): $ VI SUMASSEMBLE.CINT SUM (int A, int b) {int R; __ASM __ ("SUB $ 0 X4, %% ESP; MOVL 0XC (%% EBP), %% EAX; ADDL 0x8 (%% EBP), %% EAX; MOVL %% EAX, 0xFffffc (%% EBP); MOVL 0xFffFFFC (%% EBP), %% EAX; MOVL %% EAX, %% EAX; ":" = a "(r)); Return R;

Disassembly of section .text:

转载请注明原文地址:https://www.9cbs.com/read-64508.html

New Post(0)