The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: pro3carp3 on February 08, 2005, 04:09:08 PM

Title: Addressing mode syntax
Post by: pro3carp3 on February 08, 2005, 04:09:08 PM
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.
Title: Re: Addressing mode syntax
Post by: raymond on February 08, 2005, 06:02:14 PM
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
Title: Re: Addressing mode syntax
Post by: pro3carp3 on February 09, 2005, 03:25:55 PM
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.
Title: Re: Addressing mode syntax
Post by: Ratch on February 09, 2005, 05:34:01 PM
pro3carp3,

Here is one way to do it. Ratch

[attachment deleted by admin]