-
Notifications
You must be signed in to change notification settings - Fork 0
/
10.asm
28 lines (20 loc) · 1 KB
/
10.asm
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
; Hello World Program (Count to 10)
; Compile with: nasm -f elf helloworld-10.asm
; Link with (64 bit systems require elf_i386 option): ld -m elf_i386 helloworld-10.o -o helloworld-10
; Run with: ./helloworld-10
%include 'functions.asm'
SECTION .text
global _start
_start:
mov ecx, 0 ; ecx is initalised to zero.
nextNumber:
inc ecx ; increment ecx
mov eax, ecx ; move the address of our integer into eax
add eax, 48 ; add 48 to our number to convert from integer to ascii for printing
push eax ; push eax to the stack
mov eax, esp ; get the address of the character on the stack
call sprintLF ; call our print function
pop eax ; clean up the stack so we don't have unneeded bytes taking up space
cmp ecx, 10 ; have we reached 10 yet? compare our counter with decimal 10
jne nextNumber ; jump if not equal and keep counting
call quit