flat assembler
Message board for the users of flat assembler.
Index
> Main > Relative jumps |
Author |
|
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$+$-$$ |
|||
25 Aug 2023, 08:16 |
|
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 } |
|||
25 Aug 2023, 09:15 |
|
Roman 25 Aug 2023, 14:59
Everybody's jump now !
Techno. I don't know about jz near ! I always thinking only jmp have short,near and far variants. But jz only short. |
|||
25 Aug 2023, 14:59 |
|
Overclick 25 Aug 2023, 15:38
Roman wrote: Everybody's jump now ! 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 |
|||
25 Aug 2023, 15:38 |
|
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. 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. |
|||
26 Aug 2023, 18:13 |
|
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 |
|||
26 Aug 2023, 20:32 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.