Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- section .data
- text1 db "What is your name? "
- t1len equ $ - text1 ; save length of text1
- text2 db "Hello, "
- t2len equ $ - text2 ; save length of text2
- ;reserved data for the username
- section .bss
- name resb 32 ; Don't SKIMP on Buffer Size! 4-not enough!
- section .text
- global _start
- _start:
- call _printText1
- call _getName
- call _printText2
- mov rdi, name ; load name in rdi
- call _strprn ; print it!
- mov rax, 60
- mov rdi, 0
- syscall
- ;input Subroutines
- _getName:
- xor rax, rax ; zero rax
- xor rdi, rdi ; zero rdi
- mov rsi, name ; load rsi with name
- xor rdx, rdx ; zero rdx
- add rdx, 32 ; put length in rdx
- syscall
- ret
- ;prints the text to the screen
- _printText1:
- mov rax, 1
- mov rdi, 1
- mov rsi, text1
- mov rdx, t1len ; use declared length
- syscall
- ret
- _printText2:
- mov rax, 1
- mov rdi, 1
- mov rsi, text2
- mov rdx, t2len ; use declared length
- syscall
- ret
- ; load string in rdi before call
- _strprn:
- push rdi ; push string address onto stack
- call _strlen ; call strsz to get length
- pop rsi ; pop string to rsi (source index)
- mov rax, 0x1 ; put write/stdout number in rax (both 1)
- mov rdi,rax ; set destination index to rax (stdout)
- syscall ; call kernel
- ret
- ;adds the additional code form the site
- _strlen: ; NOTE: RDI IS THE DEFAULT SRC FOR SCASB
- xor rcx, rcx ; zero rcx
- not rcx ; set rcx = -1 (uses bitwise id: ~x = -x-1)
- xor eax, eax ; zero the al register (initialize to NUL)
- cld ; clear the direction flag
- repnz scasb ; get the string length (dec rcx through NUL)
- not rcx ; rev all bits of negative -> absolute value
- lea rdx, [rcx-1] ; length [rcx-1] into rdx, ready for write
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement