Created
December 2, 2012 08:10
-
-
Save leopic/4187685 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
; constants | |
section .data | |
lblZero: db 'Zero'; | |
lblOne: db 'One '; | |
lblNumLength: db 0x4; | |
tmp: db 0; | |
; code | |
section .text | |
global _start | |
; linker needs this, 'main' | |
_start: | |
loop: | |
; user was already prompted for a single digit | |
; store user's input ; read | |
mov rax, 0 ; | |
mov rbx, 19 ; | |
mov rcx, tmp ; | |
mov rdx, 10 ; | |
syscall | |
; series of IFs | |
cmp rcx, 0 ; is input 0? 00 exits the program | |
je isZero | |
cmp rcx, 1 ; is input 1? | |
je isOne | |
jmp exit | |
; user typed 0 | |
isZero: | |
inc rcx ; flag for 0 | |
cmp rcx, 2 ; checking if this is the 2nd zero | |
je exit ; if so, we are outta here | |
mov rsi, lblZero ; | |
mov rcx, -1 ; | |
jmp print ; | |
; user typed 1 | |
isOne: | |
mov rsi, lblOne ; | |
mov rcx, -1 ; | |
jmp print ; | |
; prints the string into the screen ; sys_write | |
print: | |
mov rax, 1 ; | |
mov rdi, 1 ; | |
mov rdx, lblNumLength ; | |
syscall | |
jmp loop | |
; displays an error message | |
err: | |
; sys_write, not relevant to the Q | |
syscall | |
jmp loop | |
; shutsdown program ; sys_write ; sys_exit | |
exit: | |
; not relevant to the Q |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment