flat assembler
Message board for the users of flat assembler.

Index > Main > Weird code problem

Author
Thread Post new topic Reply to topic
shism2



Joined: 14 Sep 2005
Posts: 248
shism2
What's the difference between

Code:
mov     dword [ebx-1],-1
        cmp     eax,320
        ret
        db      0dbh


AND_______________________

mov     dword [dword ebx-1],-1 ; Why does this compile ?
        cmp     eax,320
        ret
        db      0dbh
    
Post 15 Aug 2007, 01:28
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
With "AND_______________________" commented compiles for me.

Which version are you using? The mine is 1.67.22
Post 15 Aug 2007, 01:39
View user's profile Send private message Reply with quote
shism2



Joined: 14 Sep 2005
Posts: 248
shism2
No no no.... The and I put in their intentionally.... I wanted to know the difference between the two...

mov dword [ebx-1],-1
cmp eax,320
ret
db 0dbh


AND

mov dword [dword ebx-1],-1 ; Why does this compile ?
cmp eax,320
ret
db 0dbh
Post 15 Aug 2007, 02:08
View user's profile Send private message Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22
mov dword [dword ebx-1],-1

It compiles because it's technically correct.
The [dword denotes that the address inside is a DWORD address which is true (being 32bit and all).

Replace
mov dword [dword ebx-1],-1
With
mov word [word ebx-1],-1
And you'll get an "Address Size Error"
Post 15 Aug 2007, 03:35
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
asmfan



Joined: 11 Aug 2006
Posts: 392
Location: Russian
asmfan
Somethind like this. Makes compiler to produce the full form of instruction, not the shortest possible.
Code:
.00401000: C743FFFFFFFFFF               mov         d,[ebx][-01],-1
.00401007: 3D40010000                   cmp         eax,000000140 ;'   @'
.0040100C: C3                           retn        
.0040100D: C783FFFFFFFFFFFFFFFF         mov         d,[ebx][-00000001],-1
.00401017: 3D40010000                   cmp         eax,000000140 ;'   @'
.0040101C: C3                           retn        
    

_________________
Any offers?
Post 15 Aug 2007, 06:58
View user's profile Send private message Reply with quote
shism2



Joined: 14 Sep 2005
Posts: 248
shism2
Asmfasm :

That's what you get when you look at the compiled code in a disasmbeller?
Post 15 Aug 2007, 11:44
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
shism2, I tested your code as you posted but I commented that line for obvious reasons.

My output is the same as asmfan, here my output with OllyDbg:
Code:
00401000 >/$ C743 FF FFFFFFFF        MOV DWORD PTR DS:[EBX-1],-1
00401007  |. 3D 40010000             CMP EAX,140
0040100C  \. C3                      RETN
0040100D     DB                      DB DB
0040100E   . C783 FFFFFFFF FFFFFFFF  MOV DWORD PTR DS:[EBX-1],-1
00401018   . 3D 40010000             CMP EAX,140
0040101D   . C3                      RETN
0040101E     DB                      DB DB    


And to clarify even more I tested exactly this:
Code:
format PE gui
mov     dword [ebx-1],-1
        cmp     eax,320 
        ret 
        db      0dbh 


;AND_______________________

mov     dword [dword ebx-1],-1 ; Why does this compile ? 
        cmp     eax,320 
        ret 
        db      0dbh    

Note that removing format also compiles fine and using "use32" also works, etc. Seems to work always.

I insist, which version are you using? Is exactly that code that gives you troubles?

[edit]Sorry, I'm clearly seriously stupid here... The difference is the size of the offset. With "dword" inside the square bracket you prevent fasm from using the short signed 8-bit immediate form. You also prevent the suppression of the offset when it is zero ("mov [dword ebx+0], eax" is not converted into "mov [ebx], eax" while "mov [ebx+0], eax" yes).

Sorry for misreading you[/edit]
Post 15 Aug 2007, 13:22
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Code:
use32

        mov     dword [ebx-1],-1
        cmp     eax,320
        ret
        db      0dbh

        nop
        nop
        nop
        nop
        nop

        mov     dword [dword ebx-1],-1 ; Why does this compile ?
        cmp     eax,320
        ret
        db      0dbh

        nop
        nop
        nop
        nop
        nop


00000000  C743FFFFFFFFFF    mov dword [ebx-1],$ffffffff
00000007  3D40010000        cmp eax,$140
0000000C  C3                ret
0000000D  DB9090909090      fist dword [eax+$90909090]

00000013  C783FFFFFFFFFFFF  mov dword [ebx+$ffffffff],$ffffffff
         -FFFF
0000001D  3D40010000        cmp eax,$140
00000022  C3                ret
00000023  DB9090909090      fist dword [eax+$90909090]
    


Works perfectly as supposed. The only "weird" thing is the syntax of some disassemblers. See correct FASM syntax coming from NDISASM. Idea

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 15 Aug 2007, 22:01
View user's profile Send private message Reply with quote
shism2



Joined: 14 Sep 2005
Posts: 248
shism2
I didn't know about this addressing. Thank you everyone.
Post 16 Aug 2007, 00:34
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. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.