<code>section .data
numbers db 240, 40, 80, 90, 30, 40
section .bss
digit resw 1
%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 dl, 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, 1
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
section .text
global _start
_start:
mov esi,numbers
;movzx r8d, byte [esi]
;printNumber r8d ; -> mov eax, r8d
;movzx r8d, byte[esi+1]
;printNumber r8d
;movzx r8d, byte[esi+2]
;printNumber r8d
</code>
<code>section .data
numbers db 240, 40, 80, 90, 30, 40
section .bss
digit resw 1
%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 dl, 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, 1
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
section .text
global _start
_start:
mov esi,numbers
;movzx r8d, byte [esi]
;printNumber r8d ; -> mov eax, r8d
;movzx r8d, byte[esi+1]
;printNumber r8d
;movzx r8d, byte[esi+2]
;printNumber r8d
</code>
section .data
numbers db 240, 40, 80, 90, 30, 40
section .bss
digit resw 1
%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 dl, 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, 1
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
section .text
global _start
_start:
mov esi,numbers
;movzx r8d, byte [esi]
;printNumber r8d ; -> mov eax, r8d
;movzx r8d, byte[esi+1]
;printNumber r8d
;movzx r8d, byte[esi+2]
;printNumber r8d
I want to print all elements in array ‘numbers’, but when I launch code, result is not 240,40,80 but 240, 48, 52.
Why 48 and 52 is in result and how can I fix it?
I feel like the previous value is affecting it, but I really don’t know how to fix it.
I want to print all elements in array..
New contributor
user25004318 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.