In this code:
global _start
section .bss
v1 resw 1
v2 resb 2 ;array of 2 chars
section .text
_start:
mov word[v1],500
mov word[v2],500
mov rax,60
mov rdi,0
syscall
Is this code correct or not?
Does word[v1] work the same way as word[v2]?
I'm using NASM on x86-64 Ubuntu.
Yes, they both do reserve the same amount of memory (2 bytes), so you can safely access them using mov word[...], ....
Note that this is roughly equal to writing uint8_t v1[2] vs. uint16_t v2[1] in C. But NASM doesn't enforce types so every memory reference is like using C memcpy() to do strict-aliasing-safe loads or stores that transfer N bytes without caring about the C type of the memory.
I strongly recommend to actually use resw, if you plan to use the allocated data as a word or an array of words, to avoid confusion and potential bugs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With