Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- default rel
- ; We use these functions (printf and scanf) from an external library
- extern _printf
- extern _scanf
- ; Begin the "code" section of our output OBJ file
- section .text
- ; Mark the label "main" as an exported/global symbol
- global _main
- ; "main" marks the spot where our code actually is (i.e., calling "main()" takes you here)
- _main:
- ; Boilerplate "function prologue"
- push rbp
- mov rbp, rsp
- sub rsp, 32 ; create shared shadow space
- lea rdi, [prompt1]
- call _printf
- mov rdx, 50
- .while:
- mov rsi, [guess]
- lea rdi, [fmt]
- call _scanf
- cmp rdx, rsi
- ; je .end ; if it is equal jump to the end.
- ; jl .too_low ; if it is low jump to the too_low
- ; jg .too_high ; if it is high jump to the too_high
- mov rsi, [guess]
- lea rdi, [fmt]
- call _printf
- .too_low:
- lea rdi, [too_low_promt]
- call _printf
- jmp .while
- .too_high:
- lea rdi, [too_high_promt]
- call _printf
- jmp .while
- .end:
- lea rdi, [output]
- call _printf
- ; Boilerplate "function epilogue"/return
- mov rsp, rbp
- pop rbp
- ret
- ; Begin the "data" section of our output OBJ file
- section .data
- guess: dd 0
- prompt1: db "I'm thinking of a number between 1 and 100. What is it? ", 0
- promt2: db "Wrong answer, guess again!", 10, 0
- too_low_promt: db "Your answer is too low!", 10, 0
- too_high_promt: db "Your answer is too high!", 10, 0
- output: db "You got it right.", 10, 0
- fmt: dd "%d", 0
- num: dd 50
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement