Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

register indirect mode in Assembly

Status
Not open for further replies.

posterise

Technical User
Jun 8, 2006
4
US
Is it allowed to do the following?:

mov CX, [EAX]
mov [EAX], CX

???

mov W1, [EAX]
mov [EAX],W1
where W1 is not doubleword (word or byte)

In plain english, what is the real difference between direct and indirect access mode ?
I can't find examples of invalid descriptions and the reasons why.
 
All of the above are correct.

Indirect addressing, as it says, lets you get the memory
value that is pointed by the given register.

So if EAX = 100

mov ebx,[eax] gets the 100th dword relativ to DS into
EBX.

mov [eax],ebx puts the contents of EBX into the double
word at address DS:100

Succes, Tessa
 
Thank you TessaBonting, but I don't understand what exactly happens in case I try to do this kind of thing:
mov W1, [EAX] W1 - type of the W1: word or byte
or
mov BX, [EAX]

if the number, that [EAX] points to, is a doubleword, is this number going to be just truncated when trying to put into BX or W1(which is in the memory), because BX and W1 can contain only word meaning ? Or because of the different types is it going to display an error, just like in case of move BX, EAX ?

(I just started learning Assembly recently, and don't get some of that abstract stuff)
 
TessaBonting said:
So if EAX = 100

mov ebx,[eax] gets the 100th dword relativ to DS into
EBX.
shouldn't that be the 25th dword??

posterize

most assemblers will fetch the byte/word (depends on the size of W1) from [EAX] and handle this correctly.

if W1 is a word and you want to be sure the assembler will
treat it that way you can explicitely tell it with what it
is dealing with:

mov W1,word ptr [EAX]

or in case of a byte sized variable:

mov W1,byte ptr [EAX]

i'm a 16bit programmer myself, so i'm not 100% convinced
if it will work for you. just try it and you'll see.
 
Thank you denc4

I've tried it in a program practically, and actually this is what is going on:
it accepts when I use mov BX, [EAX]
but it doesn't when I use
mov W1, [EAX] where W1 - word

Actually it gives the same number of the error which appears in case I put for expample add W1, W2
so, I guess that declaration is incorrect because parameters are affiliated only with the memory, which is incorrect
 
exactly.
to add a value in memory to another value in memory you have to use an intermediate step.

for example:
to add word at [eax] to W1 use:

mov ax,[eax]
add W1,ax

to add W2 to W1 use:

mov ax,W2
add W1,ax
 
yeah, after I tried that experimentally, practically, and also compared numbers of mistakes, I finally realized what is the difference between [EAX] and EAX - indirect and direct register access, - which I could not understand before, that's why in the first post I asked what it means in plain english.

Anyway, everybody, thanks for participation in the thread! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top