Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- section .data
- health db 100
- dmg db 5
- newline db 0xA,0x0
- com db 'Command? ',0x0
- fullstr db 'You have full health.',0x0
- medstr db 'You have medium health.',0x0
- lowstr db 'You have low health.',0x0
- deadstr db 'You have died!',0x0
- welcome db 'Welcome to my adventure!',0x0
- encounterstr db 'You see a monster.',0x0
- section .bss
- input resb 32 ;input buffer
- section .text
- global _start
- _start:
- call init
- mov rdi,welcome
- call println
- call tellHealth
- jmp exit
- init:
- mov r9,health;health
- mov r10,dmg;damage
- ret
- tellHealth: ;inform the player of how much health they have
- cmp r9,25
- jz .nohealth
- jle .lowhealth
- cmp r9,50
- jge .medhealth
- .fullhealth:
- mov rdi,fullstr
- call println
- ret
- .nohealth:
- mov rdi,deadstr
- call println
- jmp exit
- .lowhealth:
- mov rdi,lowstr
- call println
- ret
- .medhealth:
- cmp r9,100
- je .fullhealth
- mov rdi,medstr
- call println
- ret
- encounter: ;monster encounter
- mov rdi,encounterstr
- call println
- getCom: ;get command from user
- mov rdi,com
- call print
- call getInput
- getInput: ;get input from stdin and store in input buffer
- mov rax,0
- mov rdi,0
- mov rsi,input
- mov rdx,16
- syscall
- ret
- print:;print without newline
- push rdi
- call strlen
- mov rdi,1
- pop rsi
- mov rdx,rax
- mov rax,1
- syscall
- ret
- println:;print with a newline
- call print
- mov rdi,newline
- call print
- ret
- strlen: ;get length of strings that end with 0x0
- xor rax,rax ;zero rax
- .strlen_loop:
- cmp BYTE [rdi + rax],0x0
- je .strlen_break
- inc rax
- jmp .strlen_loop
- .strlen_break:
- inc rax
- ret
- exit:
- mov rax,60
- mov rdi,0
- syscall
- errExit:
- mov rax,60
- mov rdi,1
- syscall
Add Comment
Please, Sign In to add comment