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
|
||||
|
@@ -10,5 +10,6 @@ section .text
|
||||
; rax* syscall
|
||||
; rdi (arg) code to exit the program with
|
||||
exit:
|
||||
sub rsp, SIZE_QWORD
|
||||
mov rax, NR_exit
|
||||
syscall
|
||||
|
@@ -3,13 +3,22 @@
|
||||
; core.asm
|
||||
extern exit
|
||||
; console.asm
|
||||
extern print
|
||||
extern puts
|
||||
; string.asm
|
||||
extern strlen
|
||||
; convert.asm
|
||||
|
||||
section .rodata
|
||||
TEST_print equ 1
|
||||
TEST_strlen equ 1
|
||||
|
||||
; print()
|
||||
msgPrint db "TEST print()",NL,EOS
|
||||
|
||||
; puts()
|
||||
msgPuts db "TEST puts()",EOS
|
||||
|
||||
; strlen()
|
||||
strlenStr1 db "Hello",EOS
|
||||
strlenStr2 db "Hello, world!",NL,EOS
|
||||
@@ -25,6 +34,18 @@ _start:
|
||||
mov rbp, rsp
|
||||
sub rsp, SIZE_QWORD
|
||||
|
||||
;---
|
||||
;--- print()
|
||||
;---
|
||||
lea rdi, [rel msgPrint]
|
||||
call print
|
||||
|
||||
;---
|
||||
;--- puts()
|
||||
;---
|
||||
lea rdi, [rel msgPuts]
|
||||
call puts
|
||||
|
||||
;---
|
||||
;--- strlen()
|
||||
;---
|
||||
|
Reference in New Issue
Block a user