Вы находитесь на странице: 1из 2

1 bits 32 ; assembling for the 32 bits

architecture
2
3 ; declare the EntryPoint (a label defining
the very first instruction of the program)
4 global start
5
6 ; declare external functions needed by our
program
7 extern exit ; tell nasm that
exit exists even if we won't be defining it
8 import exit msvcrt.dll ; exit is a
function that ends the calling process. It is defined in msvcrt.dll
9 ; msvcrt.dll
contains exit, printf and all the other important C-runtime specific functions
10
11 ; our data is declared here (the variables
needed by our program)
12 segment data use32 class=data
13 ; ...
14 00000000 FE a db -2
15 00000001 0A00 b dw 10
16 00000003 06000000 c dd 6
17 00000007 0300000000000000 d dq 3
18 0000000F 0000000000000000 x dq 0
19
20 ; our code starts here
21 segment code use32 class=code
22 start:
23 ; ...
24 ;x=(a+b+d)-(a-c+d)+(b-c)
25 00000000 A0[00000000] mov al,[a];al=a
26 00000005 6698 cbw ; ax=a
27 00000007 660305[01000000] add ax,[b]
28 0000000E 98 cwde; eax=a+b
29 0000000F 99 cdq
30 00000010 0305[07000000] add eax,dword[d];
31 00000016 1315[0B000000] adc edx,dword[d+4]
32 ;edx:eax=a+b+d
33 0000001C A3[0F000000] mov dword[x],eax;
34 00000021 8915[13000000] mov dword[x+4],edx;
35 00000027 A0[00000000] mov al,[a];al=a
36 0000002C 6698 cbw ; ax=a
37 0000002E 98 cwde ; eax=a
38 0000002F 99 cdq
39 00000030 0305[07000000] add eax,dword[d];
40 00000036 1315[0B000000] adc edx,dword[d+4]
41 0000003C 2B05[03000000] sub eax,dword[c]
42 00000042 83DA00 sbb edx,0
43 00000045 2905[0F000000] sub dword[x],eax;
44 0000004B 1915[13000000] sbb dword[x+4],edx; x=(a+b+d)-(a-
c+d)
45 00000051 66A1[01000000] mov ax,[b];ax=b
46 00000057 98 cwde ; eax=b
47 00000058 99 cdq
48 00000059 2B05[03000000] sub eax,dword[c]
49 0000005F 83DA00 sbb edx,0
50 00000062 0105[0F000000] add dword[x],eax;
51 00000068 1115[13000000] adc dword[x+4],edx;
52 0000006E A1[0F000000] mov eax,dword[x]
53 00000073 8B15[13000000] mov edx,dword[x+4];
edx:eax=x=(a+b+d)-(a-c+d)+(b-c)
54 ; exit(0)
55 00000079 6A00 push dword 0 ; push the
parameter for exit onto the stack
56 0000007B FF15[00000000] call [exit] ; call exit to
terminate the program

Вам также может понравиться