News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

access memory directly

Started by theZeroFlag, October 03, 2008, 04:27:55 PM

Previous topic - Next topic

theZeroFlag

ok I have a value in ax and a value in dx

I want ax to be the first 2 bytes of EBX
and i want dx to be the last 2 bytes of EBX

how do i do this?

qWord

Are you asking for moving ax in lowword of ebx and dx in highword of ebx ?
If so:
mov bx,dx
shl ebx,16
mov bx,ax

-> ebx == dx:ax

regards qWord



FPU in a trice: SmplMath
It's that simple!

theZeroFlag

ok thank you, that makes sense, we just havent studied the shl code yet.

i had though my professor had mentioned something about accessing it with bracket syntax like

      mov ax, intOperand1
      imul intOperand2
      mov WORD PTR [ebx], ax
      mov WORD PTR [ebx+2], dx

Mark Jones

Also when dealing with memory addresses, keep in mind that byte order written to (and read from) memory is reversed -- so if EAX was 0x00000012h, when written to memory it would be stored as 0x12000000h (and when read back into eax, would be 0x00000012h again.) So in this example, if you then wrote EBX to a memory offset, don't be surprised to see it stored reversed. When that value is read back into EDX from memory though, it would once again be in the correct order.

What may be really helpful is writing some simple code such as this, then stepping through its execution in a debugger such as OllyDbg. Then the effects of each instruction can be seen easily.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

qWord

Quotei had though my professor had mentioned something about accessing it with bracket syntax like

     mov ax, intOperand1
     imul intOperand2
     mov WORD PTR [ebx], ax
     mov WORD PTR [ebx+2], dx

the result is written to an 32bit memory-location pointed by ebx


PS: why starting two discussions with the same topic ?
FPU in a trice: SmplMath
It's that simple!

theZeroFlag

oh ok, i see what i was doing

i should have moved the offset of some piece of memory into EBX and then accessed from there

a little confusing but this is what i came up with

      mov ax, intOperand1
      imul intOperand2
      mov EBX, offset doubleResult
      mov WORD PTR [ebx], ax
      mov WORD PTR [ebx+2], dx