Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
; Assembly code to loop and print reducing numbers (count down)
section .data
message db "Count Down: ", 10 ; message countdown
messageLen equ $-message; length of message
newLine db 10 ; newline like endl in C++
section .bss
number resb 1 ; number variable 1 byte long
section .text
global _start
_start:
call printMessage ; call print message function
mov rax,9 ;Move integer 9 into rax register
loopNum: ; loop function
push rax ; push rax value on the stack
add rax,'0' ; convert integer in rax into ascii to print
mov [number],rax ;put the value in rax in the variable number
call print ; call print function
pop rax ; get rax back from the stack
dec rax ;decrement the value of rax by 1
cmp rax,0 ; compare rax with 0
jne loopNum ;if not equal to zero go to loopNum
call end ; call end function
printMessage:
mov eax,4 ; system call for print to screen
mov ebx, 1; standard out
mov ecx, message ; count down message
mov edx, messageLen ; length of message
int 80h ; interrupt
ret
print:
mov eax,4 ; system call for print to screen
mov ebx, 1 ; standard out
mov ecx, number ; number variable
mov edx, 1 ; size of number
int 80h ; interrupt
mov eax,4 ; system call for print to screen
mov ebx, 1 ; standard out
mov ecx, newLine; new line like endl C++
mov edx, 1 ; size of number
int 80h ; interrupt
ret
end:
mov eax,1 ; system call for exit
mov ebx,0 ; return value
int 80h ; interrupt
ret