Background:
I have been learning x86_64 assembly using NASM on a Linux system and was writing a subroutine for strlen(const char *str)
I wanted to copy one byte starting from a pointer stored in rax
and comparing it to 0
to find the end of the string, but when I used mov rbx, [rax]
I didn't get the results I wanted which I later learned to be a wrong approach as rbx
is quadword length and mov
will copy 8 bytes at a time. The suggested solution was to use bl
instead which did work.
I also found in AT&T syntax the movzbq
mnemonic to copy one byte and zero extend it to a quadword, which in my newbie eyes looked as a neater more accurate representation of the intended instruction as I am not only moving to bl
but also erasing the remaining 7 bytes.
Question:
Is there an equivalent to movzbq
and other AT&T mov
variants in NASM?
Which is a better code practice, movzbq rbx, [address]
or mov bl, [address]
?
Thank you,