Adds print(), puts()
This commit is contained in:
@@ -1 +1,47 @@
|
||||
%include "src/constants.asm"
|
||||
|
||||
extern strlen
|
||||
|
||||
section .rodata
|
||||
mNL db NL
|
||||
section .text
|
||||
global print
|
||||
global puts
|
||||
|
||||
;----- print(*str[]) -----;
|
||||
; Prints given string to the console to stdout
|
||||
; Return value: Amount of printed characters
|
||||
; Used registers:
|
||||
; rax* syscall >> (ret) amount of printed characters
|
||||
; rdi* (arg) Pointer to str[] >> syscall arg (fd)
|
||||
; rsi* syscall arg (pointer to str[])
|
||||
; rdx* syscall arg (length of str[])
|
||||
print:
|
||||
sub rsp, SIZE_QWORD
|
||||
mov rsi, rdi
|
||||
call strlen
|
||||
mov rdx, rax
|
||||
mov rax, NR_write
|
||||
mov rdi, FD_stdout
|
||||
syscall
|
||||
add rsp, SIZE_QWORD
|
||||
ret
|
||||
|
||||
;----- puts(*str[]) -----;
|
||||
; Prints given string to the console to stdout and prints a new line
|
||||
; Return value: Amount of printed characters
|
||||
; Used registers:
|
||||
;
|
||||
puts:
|
||||
sub rsp, SIZE_QWORD
|
||||
call print
|
||||
mov rsi, mNL
|
||||
mov r10, rax
|
||||
mov rax, NR_write
|
||||
mov rdi, FD_stdout
|
||||
mov rdx, 1
|
||||
syscall
|
||||
mov rax, r10
|
||||
inc rax
|
||||
add rsp, SIZE_QWORD
|
||||
ret
|
||||
|
Reference in New Issue
Block a user