Skip to content

Commit a33c79a

Browse files
initial commit
0 parents  commit a33c79a

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

loops.asm

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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

0 commit comments

Comments
 (0)