I'm trying to print the third value of my array but I cant figure out how to print the value and not some crazy random number
I can print numbers 0-9 with just the normal technique but printing bigger numbers does not work. When i was debugging it showed that in printNumber
the eax
register was the memory address of numbers when it should have been the value
here's the code:
section .data
numbers db 20, 30, 40, 50, 60, 70
section .text
global _start
_start:
mov r8, numbers + 2
printNumber [r8] ; prints 117835012
printNumber 3000 ; prints 3000
printNumber macro:
section .bss
digit resb 0
%macro printNumber 1
mov eax, %1
%%printInt:
mov rcx, digit ;set rcx to digit memory address
mov rbx, 10 ; moving a newline into rbx
mov [rcx], rbx ; setting digit to rbx
inc rcx ; increment rcx position by one byte
%%storeLoop:
xor rdx, rdx ; zero out rdx
mov rbx, 10
div rbx ; rax / rbx (10)
; rdx holds the remainder of the divison
add rdx, 48 ; add 48 to rdx to make in ascii character
mov [rcx], dl ; get the character part of rdx
inc rcx ; increment digit position again
cmp rax, 0
jnz %%storeLoop ; continue looping until rax is 0
%%printLoop:
push rcx
;perform sys write
mov rax, SYSWRITE
mov rdi, 1
mov rsi, rcx
mov rdx, 1
syscall
pop rcx
dec rcx
cmp rcx, digit ; first byte of digit (10)
jge %%printLoop
%endmacro