Guest User

Untitled

a guest
Aug 28th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. section .data
  2.     health db 100
  3.     dmg db 5
  4.  
  5.     newline db 0xA,0x0
  6.     com db 'Command? ',0x0
  7.     fullstr db 'You have full health.',0x0
  8.     medstr db 'You have medium health.',0x0
  9.     lowstr db 'You have low health.',0x0
  10.     deadstr db 'You have died!',0x0
  11.     welcome db 'Welcome to my adventure!',0x0
  12.     encounterstr db 'You see a monster.',0x0
  13.  
  14. section .bss
  15.     input resb 32 ;input buffer
  16.  
  17. section .text
  18.     global _start
  19.  
  20. _start:
  21.     call init
  22.    
  23.     mov rdi,welcome
  24.     call println
  25.     call tellHealth
  26.    
  27.     jmp exit
  28.  
  29. init:
  30.     mov r9,health;health
  31.     mov r10,dmg;damage
  32.     ret
  33.  
  34. tellHealth: ;inform the player of how much health they have
  35.     cmp r9,25
  36.     jz .nohealth
  37.     jle .lowhealth
  38.     cmp r9,50
  39.     jge .medhealth
  40. .fullhealth:
  41.     mov rdi,fullstr
  42.     call println
  43.     ret
  44. .nohealth:
  45.     mov rdi,deadstr
  46.     call println
  47.     jmp exit
  48. .lowhealth:
  49.     mov rdi,lowstr
  50.     call println
  51.     ret
  52. .medhealth:
  53.     cmp r9,100
  54.     je .fullhealth
  55.     mov rdi,medstr
  56.     call println
  57.     ret
  58.  
  59.  
  60. encounter: ;monster encounter
  61.     mov rdi,encounterstr
  62.     call println
  63.  
  64. getCom: ;get command from user
  65.     mov rdi,com
  66.     call print
  67.     call getInput
  68.  
  69. getInput: ;get input from stdin and store in input buffer
  70.     mov rax,0
  71.     mov rdi,0
  72.     mov rsi,input
  73.     mov rdx,16
  74.     syscall
  75.     ret
  76.  
  77. print:;print without newline
  78.     push rdi
  79.     call strlen
  80.     mov rdi,1
  81.     pop rsi
  82.     mov rdx,rax
  83.     mov rax,1
  84.     syscall
  85.     ret
  86.  
  87. println:;print with a newline
  88.     call print
  89.     mov rdi,newline
  90.     call print
  91.     ret
  92.  
  93. strlen: ;get length of strings that end with 0x0
  94.     xor rax,rax ;zero rax
  95. .strlen_loop:
  96.     cmp BYTE [rdi + rax],0x0
  97.     je .strlen_break
  98.     inc rax
  99.     jmp .strlen_loop
  100. .strlen_break:
  101.     inc rax
  102.     ret
  103.  
  104. exit:
  105.     mov rax,60
  106.     mov rdi,0
  107.     syscall
  108.  
  109. errExit:
  110.     mov rax,60
  111.     mov rdi,1
  112.     syscall
Add Comment
Please, Sign In to add comment