The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Kyoy on January 24, 2005, 03:35:14 AM

Title: writing to address
Post by: Kyoy on January 24, 2005, 03:35:14 AM
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.
Title: Re: writing to address
Post by: sheep on January 24, 2005, 04:28:20 AM
"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]."
Title: Re: writing to address
Post by: MichaelW on January 24, 2005, 07:54:03 AM
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.


Title: Re: writing to address
Post by: Kyoy on January 28, 2005, 01:37:57 AM
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?
Title: Re: writing to address
Post by: dsouza123 on January 28, 2005, 02:40:35 AM
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.
Title: Re: writing to address
Post by: ofg on February 04, 2005, 10:49:48 AM
kyoy,

to hold offset values use edi/esi but no other registers.
it may help.
Title: Re: writing to address
Post by: UncannyDude on February 04, 2005, 01:19:05 PM
Maybe some relocation?

Are you sure that when you step the line "mov bl,byte ptr [00404000h]", eax is aliasing [00404000h]?