flat assembler
Message board for the users of flat assembler.

Index > Main > Array

Author
Thread Post new topic Reply to topic
Richi



Joined: 05 Sep 2008
Posts: 2
Richi
Hello,
I would like to get the address of the 2nd element of an array called B
It works with an immediate number:

mov di, offset B[1]

but it does not like this:

mov al, 1
mov di, offset B[al]

I checked in emu8086, di contains simply the offset of B, al is ignored.
What is the logic behind of it?
Post 05 Sep 2008, 05:59
View user's profile Send private message Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1605
Location: Ukraine
shoorick
in real mode not all registers can be used as indexing. also, displacement is 16-bit and must be summed with 16-bit numbers also

try this:
mov bx,1
lea di,[B + bx]

(fasm syntaxis)

btw, this will place byte from array into al, not its offset:
mov al,[B + bx]

i have use al instead di here, because di is 16-bit register and not designed to work with 8-bit values, as i see your array is sequence of bytes
Post 05 Sep 2008, 06:12
View user's profile Send private message Visit poster's website Reply with quote
Richi



Joined: 05 Sep 2008
Posts: 2
Richi
Thank you, I will try that! Is it not a problem that a 16 bit reg (bx) is forced into a 8 bit reg (al)?
mov al,[B + bx]
Post 05 Sep 2008, 06:55
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
As shoorick said, mov al, [B+bx] puts the byte at the address B+bx into al, not the address of that byte. Use lea instruction if you want to load the address.
Post 06 Sep 2008, 14:20
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.