Author Topic: Nasm manual questions  (Read 7347 times)

Stefan

  • Guest
Nasm manual questions
« on: January 20, 2006, 10:26:22 AM »
Hello ...
In the nasm manual it says that a line like
mov ebx,[eax*5]
gets assembeled like
mov ebx,[eax*4+eax]

It also states that a line like ebx,[eax*5] appears illegal .. my question is .. why [eax*5] is illegal .. namely why it needs to be assembeled like [eax*4+eax] .. what is the difference?
I know so little that I am afraid to guess why that is .. is it because of the way the proccesor reads info from memory (like 4 bytes at once for example on 32-bit platforms)

Thank you in advance

Stefan

  • Guest
Re: Nasm manual questions
« Reply #1 on: January 20, 2006, 11:30:32 AM »
Also I wanted to ask ... in case I have in my bss section "someVar resb 1" ...
In my code I do

mov eax,[someVar]

Now the problem is evidently I want only a byte to be retrieved .. but I am afraid a whole dword might me put in eax ... "mov eax,byte [somevar]" fails to assemble

For now I AND eax,0xff ..and I get only the byte I need (although usually that byte is all I geteither way but I am afraid it's just coincidence)

Is there a proper way to get the byte directly into eax from someVar.
I could do mov al,[someVar] .. but I am curious on  how the byte,word,dword etc. specifications should be use .. Thank you

nobody

  • Guest
Re: Nasm manual questions
« Reply #2 on: January 20, 2006, 06:38:39 PM »
Read Intel's or AMD's processor manuals. In
particular, look for "mod r/b byte" and "sib
byte". They have the 4*reg+reg restriction.

nobody

  • Guest
Re: Nasm manual questions
« Reply #3 on: January 20, 2006, 06:43:44 PM »
movzx eax,byte [0] ; zero-extends
movsx eax,byte [0] ; sign-extends

The byte qualifier is needed because
you could also read from a word.