Author Topic: Index addressing  (Read 6878 times)

nobody

  • Guest
Index addressing
« on: August 03, 2005, 05:34:55 PM »
Hi.
I'm new in NASM and i''ve problem with syntax addressing  for egzample ...
i want to do something like this:

mov [address],[base + bx*a+cx*b]

ax,bx contain indices

and i receive error massage, the same thing is with ( gas addr(%eax,%ebx,a) in NASM should be [addr+ebx*a+eax] and i receive error again ) what should i do to FIX it ... PLEASE help :-)

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Index addressing
« Reply #1 on: August 03, 2005, 07:06:44 PM »
Not going to work with ax, cx - the rules for 16-bit addressing are different (if you need to use 16-bit regs, lookitup). Nor with more than one index!

[addr + ebx * a  +  eax] ought to work, provided that "a" is one of 1, 2, 4, 8.

If you can't get it working, post the exact code you're trying.

Best,
Frank

nobody

  • Guest
Re: Index addressing
« Reply #2 on: August 03, 2005, 08:00:24 PM »
Thank You .. code is exremely simple because i'm just learning assembler, it's multiplying of two integer matrices, looking for determinant etc. but if i WANT :-D to use 16-bit registers .. i should use only one index ?? ( i've no opportunity to check it out now, and i can't find nothing about this in manual)

Lukas

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Index addressing
« Reply #3 on: August 03, 2005, 10:45:53 PM »
Only one index in 32-bit code. No index at all in 16-bit instructions. 16-bit addressing consists of an offset (address) plus an (optional) base register, plus an (optional) index register. Base registers are bx and bp, index registers are si and di. So [addr + bx + si] is okay, but not [addr + si + di]. Quite lame!

You can use 32-bit instructions in 16-bit code. There's a "penalty" in the form of an address size override byte, but it's worth it (in many cases). Make sure the upper bits of registers are clear, and make sure the total offset doesn't exceed 0FFFFh, or you'll get a segment overrun exception.

Best,
Frank