flat assembler
Message board for the users of flat assembler.

Index > Main > Relative jumps

Author
Thread Post new topic Reply to topic
Overclick



Joined: 11 Jul 2020
Posts: 670
Location: Ukraine
Overclick 25 Aug 2023, 07:59
Hi
error: value out of range.
Code:
use16   ;SMM
begin:
   ...
   jmp finish
finish:
    

How to force it to generate relative jump E9 00 00?


Description:
Filesize: 31.96 KB
Viewed: 3141 Time(s)

Capture.PNG


Post 25 Aug 2023, 07:59
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 25 Aug 2023, 08:16
This description may mislead, as it is incomplete - even though 16-bit JMP calculates the target relative to the address of next instruction, it also truncates the address to 16 bits. It is therefore impossible to jump outside the 0-0FFFFh range with such jump and if your surrounding code is placed at a higher address, you get such error.

To force generation of 16-bit jump, switch ORG temporarily to a low value (of course I would recommend using the actual value of where this code is going to be executed at), and restore it after. To force E9 opcode specifically, use the NEAR prefix:
Code:
label prev$ at $
org 100h
use16
begin:
   jmp near finish
finish:
org prev$+$-$$    
Post 25 Aug 2023, 08:16
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 670
Location: Ukraine
Overclick 25 Aug 2023, 09:15
Thanks for your answer but it is too complicated for me. I was thinking there is some easy solution like use16 supposed to be.
I think this way is better then
Code:
macro jnz16 par
{
        local lab
        lab = $
        dw 0x850F          ;E9 for jmp
        dw par-lab-4
}
    
Post 25 Aug 2023, 09:15
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1852
Roman 25 Aug 2023, 14:59
Everybody's jump now ! Smile
Techno.

I don't know about jz near !
I always thinking only jmp have short,near and far variants.
But jz only short.
Post 25 Aug 2023, 14:59
View user's profile Send private message Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 670
Location: Ukraine
Overclick 25 Aug 2023, 15:38
Roman wrote:
Everybody's jump now ! Smile
I always thinking only jmp have short,near and far variants.
But jz only short.

As I said it's error: value out of range. Because it uses base offset or I don't know what.
Maybe I need to try jnz finish and 0xFFFF. But my macro-solution is ok anyway.
That 16-bit jump opcodes used in SMM (SMRAM) even if 32 bit extended. So I just following that principles
Post 25 Aug 2023, 15:38
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 2572
Furs 26 Aug 2023, 18:13
Overclick wrote:
As I said it's error: value out of range. Because it uses base offset or I don't know what.
No.

Tomasz said it truncates the address. Here's an example. Suppose your jump is at address 0x123456. Jump is 4 bytes, so the code after jump is at 0x12345A. That's where you want the jump target to be.

But if the CPU executes the jump, it will be 0x345A, because it truncates it to 16 bits. It's not a nop in this case. It will jump to 0x345A not 0x12345A.

If your code is indeed in 16 bits of address, then use org to accurately tell FASM where it is, then you won't get error.
Post 26 Aug 2023, 18:13
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 26 Aug 2023, 20:32
Moreover, if you use the truncated address as the target, fasm will accept the jump, because it is then semantically correct expression of what the instruction actually does:
Code:
org 0x123456
use16
jmp near word 3459h    
Post 26 Aug 2023, 20:32
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.