Creating an array is simmilar to normal variables, however you just add more values with commas.
In order to access an element in an array, use the formula: [baseAddress + (index*size)]
The following code will iterate through an array of dwords:
section .data lst dd 0, 1, 2, 3, 4, 5 length dq 6 ; assume constants are definedsection .bss ; emptysection .text global _start_start: mov rsi, 0 ; i.e.t. int i = 0 loopStart: mov eax, dword[lst+(rsi*4)] ; recall the formula from above ; some code here inc rsi ; i.e.t. i++ cmp rsi, qword[length] ; i.e.t. i == length jne loopStart ; exit program mov rax, SYS_exit mov rdi, EXIT_GOOD syscall
Strings
Recall
Strings are just arrays of characters that end in a NULL terminator
Creating and managing a string in x86 is almost identical.
message1 db "Hello" , 0message2 db "Goodbye", NULL ; if NULL constant is defined
Since a char is 1 byte, strings will always use db to define them.
We know the loop is over when we reach the null terminator, therefore we don’t always need a length variable
You can also use the strings address itself as the index, if you need to traverse it in order:
mov rax, message1startCheck: cmp byte[rax], NULL je doneChecking ; some code here inc rax jmp startCheckdoneChecking:
You can also do math operations using strings, such as addition.
For instance, if you subtract 48 from a digit you get that digit as a number.
Reference an ASCII Table to see what you can do.