Skip to content

Commit

Permalink
Add macro to push string constant to the stack
Browse files Browse the repository at this point in the history
  • Loading branch information
ChillerDragon committed Aug 6, 2024
1 parent acb43cb commit 56fde58
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/macros.asm
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
%macro str_to_stack 1
; str_to_stack [fixed str]
; returns into rax a pointer to the stack
; containing the string
; it will also add a null byte in the end
;
; you have to free the stack value manually
; by doing
;
; mov rsp, rbp
;
%strlen _fmt_len %1
mov rbp, rsp
sub rsp, _fmt_len
sub rsp, 1 ; nullbyte

%assign letter_index 0
%rep _fmt_len

%assign letter_index letter_index+1

%substr letter %1, letter_index, 1
mov byte [rbp-((_fmt_len+2)-letter_index)], letter
%endrep

mov byte [rbp-1], 0

lea rax, [rbp-(_fmt_len+1)]
%endmacro

%macro stack_printer 1
; stack_printer [fixed str]
;
; moves a string onto the stack
; and then prints it
;
; example:
;
; stack_printer "hello world"
;
str_to_stack %1
print_c_str rax
mov rsp, rbp
%endmacro

; print_label [string]
; string has a have a matching l_string length definition
%macro print_label 1
Expand Down

0 comments on commit 56fde58

Please sign in to comment.