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