I'm studying x86 Assembly with NASM,so I started by the basics. I created the code below and wanted to understand its output:
section .data
msg db 'Testing', 0xA
size db 8
array db 21, 22, 17, 3
section .text
global _start
_start:
; sys_WRITE the string
mov eax, 4
mov ebx, 1
mov ecx, msg
mov edx, [size]
int 0x80
; Exit - Return code is the first element of array
mov eax, 1
mov ebx, [array]
int 0x80
This is the output:
Testing
.shstrtab.text.data
%
I tried to define the size of the string in a Byte in the .data section, so it gives this output. I already figured out that it happens because, when I load a byte to the edx register, which is of size dword, some garbage stays in the remaining bits. (The solution is just to declare size as dd, but that's not what this is about).
But I wanted to understand, why it doesn't happen with the array? When I check with echo $?, the value is 21. Shouldn't it be garbage?
I'm trying to understand this topic in a elemental level, I'm aware of the solution, but I don't know why the above happens.
Can someone explain? Thank you!
(The % is probably because I'm using a theme of Oh-My-Zsh)