flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > jge dword [ebx]

Author
Thread Post new topic Reply to topic
Posetf



Joined: 01 Mar 2004
Posts: 35
Location: London
Posetf
Hi,
I have been using jmp dword [ebx] quite successfully (I'm writing an interpreter) but jle dword [ebx] does not compile. Same on 1.51 and 1.64

Regards,
Pete
Post 25 Jan 2006, 12:48
View user's profile Send private message Visit poster's website Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 977
Location: Czechoslovakia
MazeGen
You can't use such conditional jump with memory or register operand. You should use something like

jnle over
jmp dword [ebx]
over:
Post 25 Jan 2006, 12:59
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
or use macro: (untested)
Code:
;allow double-negated jumps (same is also done in %FASMINC%/INCLUDE/IF.INC)
jnne equ je
jnnle equ jle
jnnl equ jl
jnnge equ jge
jnng equ jg
jnnae equ jae
jnna equ ja
jnnbe equ jbe
jnnb equ jb
;for every type of jump
irp cc, g ge l le ng nge nl nle a ae b be na nae nb nbe
{
  ;overload conditional jump instruction
  macro j#cc arg
  \{
    ;if it's indirect jump
    if op eqtype dword [something]
      local ..dest ;always don't forget local and ".." in macro's internal labels
      jn#cc ..dest
      jmp arg
      ..dest:
    else
      j#cc arg
    end if
  \}
}    

hope it works
[edit] fixed few bugs in code
Post 25 Jan 2006, 13:22
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
I had to change IRP to IRPS because with IRP throws "Invalid macro arguments" at "macro j#cc arg" line and I had to change "op" with "arg".
Post 25 Jan 2006, 14:20
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
ooops, yes. it's because "ebx eqtype something" is false. Then it could be bigger problem... You need to check if "arg" is "<size_operator> [any_allowed_address]", which would be much more tricky (maybe someone can find simple solution...).

At least, here is a corrected version which should work for register as address. (Not for things like "jge dword [eax+5]")
Code:
;allow double-negated jumps (same is also done in %FASMINC%/INCLUDE/IF.INC) 
jnne equ je 
jnnle equ jle 
jnnl equ jl 
jnnge equ jge 
jnng equ jg 
jnnae equ jae 
jnna equ ja 
jnnbe equ jbe 
jnnb equ jb 
;for every type of jump 
irp cc, g, ge, l, le, ng, nge, nl, nle, a, ae, b, be, na, nae, nb, nbe 
{ 
  ;overload conditional jump instruction 
  macro j#cc arg 
  \{ 
    ;if it's indirect jump 
    if arg eqtype dword [eax] 
      local ..dest ;always don't forget local and ".." in macro's internal labels 
      jn#cc ..dest 
      jmp arg 
      ..dest: 
    else 
      j#cc arg 
    end if 
  \} 
}    
Post 25 Jan 2006, 14:31
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Sorry Vid, it's my fault, you probably read my previous post. The problem was that when I trying to find the problem I'd changed "if arg eqtype dword [something]" to "if arg eqtupe dword **ptr**[something]" (without "**"). Thats works good for "jge dword ptr [ebx]" but not for "jge dword [ebx]", I thought that "ptr" in the eqtype was needed Razz.

However I note that IRP works fine with this code :S while in the first one you need IRPS :S:S, why happend this?

PS: Checked before posting, IRP works now because you use "," for every condition now

[edit]Another problem, if I put "jge dword[ebx]" twice I get "Error: already defined symbol" and the symbol is "..dest?0000001".

Preprocesor output:
Code:
use32

;jge dword[ebx]
        
        
        if dword[ebx]eqtype dword[eax]
        
        ;jnge ..dest?0000001
                
                
                if ..dest?0000001 eqtype dword[eax]
                
                jge ..dest?0000005
                jmp ..dest?0000001
                ..dest?0000005:
                else
                jnge ..dest?0000001
                end if
                
        jmp dword[ebx]
        ..dest?0000001:
        else
        jge dword[ebx]
        end if
        
;jge dword[ebx]
        
        
        if dword[ebx]eqtype dword[eax]
        
        ;jnge ..dest?0000001
                
                
                if ..dest?0000001 eqtype dword[eax]
                
                jge ..dest?0000005
                jmp ..dest?0000001
                ..dest?0000005:
                else
                jnge ..dest?0000001
                end if
                
        jmp dword[ebx]
        ..dest?0000001:
        else
        jge dword[ebx]
        end if    
[/edit]
Post 25 Jan 2006, 14:48
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
locodelassembly wrote:
Another problem, if I put "jge dword[ebx]" twice I get "Error: already defined symbol" and the symbol is "..dest?0000001".

Of course, i forgot to escape "local" (it should make symbol local for inner macro, not for irp). so it's
Code:
;allow double-negated jumps (same is also done in %FASMINC%/INCLUDE/IF.INC)  
jnne equ je  
jnnle equ jle  
jnnl equ jl  
jnnge equ jge  
jnng equ jg  
jnnae equ jae  
jnna equ ja  
jnnbe equ jbe  
jnnb equ jb  
;for every type of jump  
irp cc, g, ge, l, le, ng, nge, nl, nle, a, ae, b, be, na, nae, nb, nbe  
{  
  ;overload conditional jump instruction  
  macro j#cc arg  
  \{  
    ;if it's indirect jump  
    if arg eqtype dword [eax]  
      \local ..dest ;always don't forget local and ".." in macro's internal labels  
      jn#cc ..dest  
      jmp arg  
      ..dest:  
    else  
      j#cc arg  
    end if  
  \}  
}    
Post 25 Jan 2006, 15:05
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Posetf



Joined: 01 Mar 2004
Posts: 35
Location: London
Posetf
MazeGen wrote:
You can't use such conditional jump with memory or register operand. You should use something like

jnle over
jmp dword [ebx]
over:


Thanks, I'll do that.

Regards,
Pete
PS. vid: thanks for the macro but I shall stick with the above.
Post 25 Jan 2006, 20:17
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
posetf: yes, it's better solution, overdefining instruction syntax with macros kills readability. I wrote it just to show some example of macrofeatures.
Post 25 Jan 2006, 20:31
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
It could have been quite nice macro, but it's not in standard instruction set, so... i agree
Post 25 Jan 2006, 20:40
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.