I am new to assembly and I'm trying to figure out how to print an array to the screen. I have an array called "Array" of size 10 elements.
This is the rest of my code:
section .data
msg db "The array: "
len equ $- msg
Array DB '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'
section .text
global _start
_start:
mov eax, 4
mov ebx, 1
mov ecx, msg ;prints msg
mov edx, len
int 0x80
jmp printArray ;calls print array function
jmp Exit ;calls exit function
printArray:
mov ebx, offset Array ;address array with ebx
mov ecx, 10 ; load counter with 10
jmp Again ; go to Again function
ret
Again:
mov eax, 4
mov ebx, 1
int 0x80
inc ebx ;increments ebx to get next element in array
dec ecx
;; compares the counter to 0
cmp ecx, 0
jnz Again
Exit:
mov eax, 1
mov ebx, 0
int 0x80
It prints msg and constructs the array, but I need help looping through the array and printing the elements to the screen.
I hope a simple example like this can be useful for others who are starting out. Thanks for any help!