-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lab4.lst
37 lines (37 loc) · 2.58 KB
/
Lab4.lst
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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 , printf, scanf ,strtok ,strlen ; 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 import printf msvcrt.dll
11 import scanf msvcrt.dll
12 import strtok msvcrt.dll
13 import strlen msvcrt.dll
14
15 segment data use32 class=data
16 ; ...
17
18 00000000 256200 format db "%b",0
19 00000003 256400 format_ db "%d",0
20
21 segment code use32 class=code
22 start:
23 ; ...
24 00000000 50 push dword eax
25 00000001 68[00000000] push dword format
26 00000006 FF15[00000000] call [scanf]
27 0000000C 83C408 add esp , 4*2
28
29 0000000F 50 push dword eax
30 00000010 68[03000000] push dword format_
31 00000015 FF15[00000000] call [printf]
32 0000001B 83C408 add esp , 4*2
33
34 ; exit(0)
35 0000001E 6A00 push dword 0 ; push the parameter for exit onto the stack
36 00000020 FF15[00000000] call [exit] ; call exit to terminate the program
37