Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. default rel
  2.  
  3. ; We use these functions (printf and scanf) from an external library
  4. extern _printf
  5. extern _scanf
  6.  
  7.  
  8. ; Begin the "code" section of our output OBJ file
  9. section .text
  10.  
  11.  
  12.  
  13. ; Mark the label "main" as an exported/global symbol
  14. global _main
  15.  
  16. ; "main" marks the spot where our code actually is (i.e., calling "main()" takes you here)
  17. _main:
  18.     ; Boilerplate "function prologue"
  19.     push    rbp
  20.     mov     rbp, rsp
  21.     sub     rsp, 32             ; create shared shadow space
  22.    
  23.     lea     rdi, [prompt1]
  24.     call    _printf
  25.  
  26.     mov     rdx, 50
  27. .while:
  28.     mov     rsi, [guess]
  29.     lea     rdi, [fmt]
  30.     call    _scanf
  31.  
  32.     cmp     rdx, rsi
  33.  
  34.     ; je      .end ; if it is equal jump to the end.
  35.     ; jl      .too_low ; if it is low jump to the too_low
  36.     ; jg      .too_high ; if it is high jump to the too_high
  37.  
  38.     mov     rsi, [guess]
  39.     lea     rdi, [fmt]
  40.     call    _printf
  41. .too_low:
  42.     lea     rdi, [too_low_promt]
  43.     call    _printf
  44.     jmp     .while
  45. .too_high:
  46.     lea     rdi, [too_high_promt]
  47.     call    _printf
  48.     jmp     .while
  49. .end:
  50.     lea     rdi, [output]
  51.     call    _printf
  52.     ; Boilerplate "function epilogue"/return
  53.     mov     rsp, rbp
  54.     pop     rbp
  55.     ret
  56.  
  57. ; Begin the "data" section of our output OBJ file
  58. section .data
  59.  
  60.     guess:  dd 0
  61.     prompt1: db "I'm thinking of a number between 1 and 100. What is it? ", 0
  62.     promt2: db "Wrong answer, guess again!", 10, 0
  63.     too_low_promt: db "Your answer is too low!", 10, 0
  64.     too_high_promt: db "Your answer is too high!", 10, 0
  65.     output: db "You got it right.", 10, 0
  66.     fmt: dd "%d", 0
  67.     num: dd 50
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement