File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ global main
2
+
3
+ extern printf
4
+
5
+ section .data
6
+ fmtStr: db '%i' , 0xA , 0
7
+
8
+ section .text
9
+ main:
10
+
11
+ mov edx , 10 ; Copy 10 to edx
12
+ looping:
13
+ push edx ; Save edx by pushing into stack
14
+
15
+ ; Load the first argument into the stack
16
+ sub esp , 4 ; Allocate space on the stack for one 4 byte parameter
17
+ mov [ esp ], edx ; Copy eax into the address of esp
18
+
19
+ ; Load the format string into the stack
20
+ sub esp , 4 ; Allocate space on the stack for one 4 byte parameter
21
+ lea eax , [ fmtStr ] ; Load string into eax
22
+ mov [ esp ], eax ; Copy eax into the address of esp
23
+
24
+ ; Call printf
25
+ call printf ; Call printf(3):
26
+ ; int printf(const char *format, ...);
27
+
28
+ ; Return the stack (pointer) to it's original position (0 elements)
29
+ add esp , 8 ; Pop the stack (There were 2 "sub esp,4")
30
+
31
+ pop edx ; Pop the stack and assign value to edx
32
+ dec edx ; Decrement edx by 1
33
+ cmp edx , 0 ; Is edx equal to 0? zf is set if edx is 0
34
+ jnz looping ; if flag does not have zf set, go to "looping"
35
+ ret
You can’t perform that action at this time.
0 commit comments