p.s. the x86
assembly reprex below assembled/inspected using NASM 2.15.05 + x86_64 Linux + GDB
section .data
Snippet db "KANG"
section .text
global _start
_start:
nop
; =============================================
mov ebx,Snippet ; at 0x804a000
add <byte|word|dword> [ebx],32
; =============================================
nop
"KANG"
pointed to by Snippet
is in memory from 0x804a000
to 0x804a003
:
(gdb) print (char) *0x804a000
$1 = 75 'K'
(gdb) print (char) *0x804a001
$2 = 65 'A'
(gdb) print (char) *0x804a002
$3 = 78 'N'
(gdb) print (char) *0x804a003
$4 = 71 'G'
(gdb)
Decoding ASCII, I am assuming KANG
is bit pattern 01001011 01000001 01001110 01000111
in memory from 0x804a000
to 0x804a003
When I leave out the size-specifier in the ADD
instruction NASM doesn't assemble as expected:
ss.asm:9: error: operation size not specified
The add <specifier> [ebx],32
instruction is supposed to convert the data at [ebx]
from uppercase to lowercase.
My confusion stems from the observation that irrespective of the size specifier used in the instruction, the result is always:
(gdb) print (char) *0x804a000
$1 = 107 'k'
(gdb) print (char) *0x804a001
$2 = 65 'A'
(gdb) print (char) *0x804a002
$3 = 78 'N'
(gdb) print (char) *0x804a003
$4 = 71 'G'
(gdb)
Considering the BYTE
tells NASM that we're only writing a single byte to the memory address in EBX. Whereas the WORD
and DWORD
specifiers tells that we're writing a word and a double word, respectively.
While I was expecting byte
to generate the above result. I was expecting the following operations (and results) for the other two size specifiers:
WORD
: I was expecting theWORD
specifier to manipulate 16 side by side bits (the 'K' and 'A' characters) starting at 0x804a000 with the operation0100101101000001B + 0000000000100000B == 0100101101100001B
resulting in"KaNG"
DWORD
: similarly I was expecting theDWORD
specifier to manipulate 32 side by side bits (the 'K','A','N', and 'G' characters) starting at 0x804a000 with the operation01001011010000010100111001000111B + 00000000000000000000000000100000B == 01001011010000010100111001100111B
resulting in"KANg"
Where is my understanding of the operation going wrong?