flat assembler
Message board for the users of flat assembler.

Index > Main > what is the name for instruction like this.

Author
Thread Post new topic Reply to topic
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner 21 Mar 2006, 06:07
recently, i saw Nikolay Petrov code on http://board.flatassembler.net/topic.php?t=4968
Code:
cmp     ecx,[edx+4*(eax+1)]
mov     ecx,[edx+4*(eax+2)] 
mov     [edx+4*(eax+1)],ecx
    

i didn't know we could code like this in assembly language. so i start wondering, where (any web) got information regarding something like above.
maybe, mov ecx,edx*eax ;would works?

so, i tried something like this
Code:
mov  ecx,[edx+4*((ebx/10)*2)]
    

it gets assembled, but from olly, i saw
MOV ECX,DWORD PTR DS:[EDX]

i search on intel pdf but didn't found examples like above, so, am wish to know like if anyone got any reference that could tell maybe like.

wat reg we could use, how many reg we could use, are + - * / works? or how many level () we could use, does % works? and so on for instruction like above.

thanks.
Post 21 Mar 2006, 06:07
View user's profile Send private message Visit poster's website Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 21 Mar 2006, 07:49
Code:
mov  ecx,[edx+4*((ebx/10)*2)]    

It doesn't get assembled: Invalid use of symbol

You can only scale memory addresses and they are very limited:
Code:
mov eax,[402000h]               ; Displacement
mov eax,[esi]                   ; Base or Index
mov eax,[esi+402000h]           ; Displacement+(Base or Index)
mov eax,[esi*8+402000h]         ; Base*Scale+Displacement
mov eax,[esi*8+esi]             ; Base*Scale+Index
mov eax,[esi*8+esi+402000h]     ; Base*Scale+Displacement+Index
                                ; While scale can be any of x1, x2, x4, x8
; LEA works the same way but it doesn't access memory
; It only calculates the address and puts it to a register
    


'/' works only on some (or all) variables or constants YOU define, but you can't divide a register.
Post 21 Mar 2006, 07:49
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8358
Location: Kraków, Poland
Tomasz Grysztar 21 Mar 2006, 07:49
The instruction sample you gave does not assemble with the latest fasm's versions, there was a bug that caused older versions to ignore register divided by some value, while it should signalize an error.

As for the allowed addressing modes, I'd recommend checking out Intel manuals. In general, with 32-bit addressing you can specify address in a form [base+index*scale+displacement], where base and index are registers, scale can be 1,2,4 or 8 and displacement (offset) can be a 32-bit number. fasm is able to do the calculations on expressions with scaled registers, so for example:
Code:
mov ecx,[((edx+ecx*3)+(edx+ecx*5))/2]    

gets reduced to
Code:
mov ecx,[edx+ecx*4]    

and thus assembles correctly. Also:
Code:
mov eax,[ecx*5]    

assembles, as it can be transformed into:
Code:
mov eax,[ecx+ecx*4]    
Post 21 Mar 2006, 07:49
View user's profile Send private message Visit poster's website Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner 21 Mar 2006, 16:07
oh yeah, i am using fasm 1.65.8
getting 1.65.17 now

btw, thanks a lot!!
i look at the intel manuals under the MOV section, maybe due to my ignorant, i didn't found any examples showing something like above Crying or Very sad

maybe they are in another section, i check them again later.
Post 21 Mar 2006, 16:07
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8358
Location: Kraków, Poland
Tomasz Grysztar 21 Mar 2006, 16:17
It is not related to MOV or any particular instruction, it's about the addressing modes and it affects almost any instruction. You should find detailed information on this nearer the beginnning of Intel Manuals.
Post 21 Mar 2006, 16:17
View user's profile Send private message Visit poster's website Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend 21 Mar 2006, 20:35
Also I may add that there is one exception. ESP cannot be index register. So it cannot be multiplied and combination like [esp+esp] will not work.
Post 21 Mar 2006, 20:35
View user's profile Send private message Visit poster's website 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.