Permalink
Cannot retrieve contributors at this time
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?
Guessuing_Game/countDownLoop.asm
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
48 lines (46 sloc)
1.44 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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 |