Adds print(), puts()

This commit is contained in:
2025-07-05 02:28:59 +02:00
parent b0a3da746f
commit 2e9d88ed76
3 changed files with 68 additions and 0 deletions

View File

@@ -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