I am trying to move data around from a hardcoded address to a register. When i did mov eax,offset ahia and i checked with a debugger, eax contains 00404000h. That is the address pointing to 7Fh obviously. So i tried this
.data
ahia db 7Fh
.code
main proc
mov eax,offset ahia //eax = 00404000h
mov bl,byte ptr [00404000h]
But when i checked with a debugger, ebx/bl don't hold 7Fh. What's wrong here? Is there any particular steps i forgot in manipulating data to and from a hardcoded address.
"mov bl,byte ptr [00404000h]" will turn to "mov bl,0" when it compiles.
If I understand what you want to do, all you should have to do is "mov bl,ahia" for it to work. If you want to keep that address in eax, change "byte ptr [00404000h]" to "byte ptr [eax]."
You need to move the address into a register first, and then specify the register name in brackets as the source operand for the move instruction. You don't need the byte ptr because MASM can determine the proper size from the destination register.
Heres what i did
pushad
mov ecx,offset ahia
movzx ebx,byte ptr [ecx]
mov ecx,00404000h
mov [ecx],ebx
popadĀ
ECX will now hold 00404000h and [ECX] will now hold 7Fh
But it seems alot of instructions for something so simple.
What i want is to put a byte into offset 00404000h. And the byte might not always be constant. Is there an easier way to do this?
Also how can i do it using a local variable?
mov [ecx],ebx
popad
should be
mov [ecx],bl
popad
because you are storing to an 8 bit variable, db not a 32 bit, dd.
kyoy,
to hold offset values use edi/esi but no other registers.
it may help.
Maybe some relocation?
Are you sure that when you step the line "mov bl,byte ptr [00404000h]", eax is aliasing [00404000h]?