flat assembler
Message board for the users of flat assembler.

Index > Main > Jumps translation control

Author
Thread Post new topic Reply to topic
CodeX



Joined: 08 Feb 2006
Posts: 20
Location: Estonia
CodeX 08 Feb 2006, 13:28
Hi!

Does anyone know if it is possible to control jump translation logic in FASM? Is there some directive to define if compiler should use absolute or relative addressing?

The problem is that I need this piece of code:
...
jmp SomeLabel
SomeLabel: stc
...

to be treated like having an absolute addressing not relative. Something like this:
...
0B3A: jmp near 0B3D
0B3D: stc
0B3E: ...

Right now all I get is:
...
0B3A: jmp $+2 ;(or "jmp $+3" if I use "jmp word SomeLabel")
0B3D: stc
0B3E: ...

Thank you.
Post 08 Feb 2006, 13:28
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 08 Feb 2006, 13:46
There are no direct near jumps using absolute addressing in the Intel Architecture. Or did I misunderstood something?
Post 08 Feb 2006, 13:46
View user's profile Send private message Visit poster's website Reply with quote
CodeX



Joined: 08 Feb 2006
Posts: 20
Location: Estonia
CodeX 08 Feb 2006, 14:00
You're right, I need to refresh my knowledge of IA.

Thank you for giving such a quick answer Smile
You can remove a topic if you like to.
Post 08 Feb 2006, 14:00
View user's profile Send private message Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22 08 Feb 2006, 20:21
You can always use a CALL instead of a jmp

call SomeLabel

SomeLabel:
add esp,4 ;; clean the stack from the call
...
Post 08 Feb 2006, 20:21
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 08 Feb 2006, 21:11
CALL uses relative addressing the same as JMP.
Post 08 Feb 2006, 21:11
View user's profile Send private message Visit poster's website Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22 08 Feb 2006, 22:44
If I'm not mistaken a near Call has two encodings

Call RelOffset ; IP + Offset is encoded E8 ?
Call Reg/addr ; IP = Reg/Addr is encoded FF ?
Post 08 Feb 2006, 22:44
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 08 Feb 2006, 22:57
These are direct and indirect call, same as there is direct and indirect jump.
The opcodes are:
Code:
                JMP     CALL
Direct near     E9      E8
Direct far      EA      9A
Indirect near   FF /4   FF /2
Indirect far    FF /5   FF /3    

Near direct jumps are relative, far direct jumps are absolute.
The symmetry between JMP and CALL is broken only by the direct short jump - the JMP instruction with 8-bit displacement (opcode EB).
Post 08 Feb 2006, 22:57
View user's profile Send private message Visit poster's website Reply with quote
Giant



Joined: 10 Feb 2006
Posts: 14
Giant 11 Feb 2006, 01:11
The closest I've gotten to a direct jump is by using a temporary register. As in
mov eax,0x12345678
jmp eax

It is pretty compact and fast, if I am not mistaken.
Post 11 Feb 2006, 01:11
View user's profile Send private message Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend 11 Feb 2006, 11:16
Code:
        push     012345678h
        retn    
Post 11 Feb 2006, 11:16
View user's profile Send private message Visit poster's website Reply with quote
Giant



Joined: 10 Feb 2006
Posts: 14
Giant 12 Feb 2006, 02:51
I would advise against push xxxxxxx retn combination.

Although I haven't tested it first hand, according to Intel, every call should be matched up with a return. Pentiums have a call/return branch prediction buffer, and returning to an arbitrary location flushes it, causing all kinds of performance problems.
Post 12 Feb 2006, 02:51
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 14 Mar 2006, 14:20
You are correct - the mov eax,location \ jmp eax is better because it can be predicted by that tiny knowledge the CPU has been given.

push modifies the esp and writes over any information at current esp offset. Return again changes esp. Neither of the sequences change flags so overall the mov variant is better. Although the push variant is ALWAYS shorter 1 to 3 bytes is you want that Very Happy
Post 14 Mar 2006, 14:20
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.