News:

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

Addressing mode syntax

Started by pro3carp3, February 08, 2005, 04:09:08 PM

Previous topic - Next topic

pro3carp3

Reference to contents of location:

mov eax, MemLoc


Reference to address of location:

mov eax, addr MemLoc


What is the syntax for indirect addressing?

mov eax, <MemLoc (pointer)>
mov eax, <BaseReg>
mov eax, <BaseReg + IndexReg>
mov eax, <BaseReg + Displacement>

etc...

In particular, I'm having trouble with the following task:

I have two dynamically created memory buffers that I want to reference dynamically in a loop where I switch from one to the other each time through the loop.  I have two dword pointers declared as:


Buffer  dd ?  ;pointer to Buffer 1
        dd ?  ;pointer to Buffer 2


I also have a dword variable that indicates the buffer to use:


UseBuffer dd ? ;0 = Buffer 1, 4 = Buffer 2
.

I want to set esi to the value in either the first or second buffer pointer by adding either zero or four to addr Buffer:


mov esi, <Buffer + UseBuffer>


Regardless of how I code this, I haven't been able to get it to work.  I don't get any errors in the compile process, but Ollydbg is unable to decode it.  (I'm using WinASM.)  Perhaps I had it right and it is an Ollydbg problem?  Either way, I can't tell what syntax is correct.  Any help is appreciated.
LGC

raymond

If you can use two registers, the easiest way would be to exchange them at the end (or start) of the loop. Ex.:
   mov  esi,pointer1
   mov  edi,pointer2
looptop:
   .....
   xchg esi,edi
   jmp  looptop


Another way, using a single register, would be to have a global memory variable set to 0 before you get into the loop. Then XOR it with 1 at the end (or start) of the loop. Ex. (using your buffer variable for the addresses):
   mov  switcher,0
looptop:
   mov  esi,switcher
   mov  esi,buffer[esi*4]
   ....
   xor  switcher,1
   jmp looptop


Raymond
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

pro3carp3

It appears my problem was related to Ollydbg.  I changed to non-debug output and opend the file in a seperate instance of Ollydbg and ran into a problem with a different section of code where the dissassembler was unable to interpret the opcodes and the original problem area was fine.  I changed back to debug output compilation and everything was fine again.
LGC

Ratch

pro3carp3,

Here is one way to do it. Ratch

[attachment deleted by admin]