flat assembler
Message board for the users of flat assembler.

Index > Main > 16bit code doesn't assemble at high addresses

Author
Thread Post new topic Reply to topic
pfranz



Joined: 13 Jan 2007
Posts: 116
Location: Italy
pfranz 21 Nov 2023, 00:09
I can't get calls and jumps to compile here:
Code:
org 100000h
use16
jmp $    
Is there any way?
Post 21 Nov 2023, 00:09
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 21 Nov 2023, 06:58
It depends what your intention is. If you need to actually jump to 10000h, you need to specify a 32-bit jump (this generates 66h prefix):
Code:
org 100000h
use16
jmp dword $    
The instruction without 66h prefix would truncate the target address. If this is what you intended, you need to tell the assembler:
Code:
org 100000h
use16
jmp $ and 0FFFFh    
Post 21 Nov 2023, 06:58
View user's profile Send private message Visit poster's website Reply with quote
pfranz



Joined: 13 Jan 2007
Posts: 116
Location: Italy
pfranz 21 Nov 2023, 20:02
No, I need to write position independent code that for other reasons has a high org, but can be in the low memory too.
I just need the assembler to calculate the relative offset byte (FE in this case) regardless of the org.
Post 21 Nov 2023, 20:02
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 21 Nov 2023, 20:42
A 16-bit jump is no longer position-independent if you put it at a high address, because it then truncates the target address (zeroing the upper half of EIP). If you want a code for a low memory, use an ORG setting in a low range. You can switch the ORG settings back and forth if needed (see another thread about the same issue, and there is more in some ancient ones).
Post 21 Nov 2023, 20:42
View user's profile Send private message Visit poster's website Reply with quote
pfranz



Joined: 13 Jan 2007
Posts: 116
Location: Italy
pfranz 22 Nov 2023, 18:49
Tomasz Grysztar wrote:
A 16-bit jump is no longer position-independent if you put it at a high address, because it then truncates the target address (zeroing the upper half of EIP).
I believe that in unREAL mode that is also used in flatassembler, 16bit code can run over $10000. Maybe a switch such as use16flat could allow these jumps and calls.
Switching org back and forth is complicated, I ended up redefining jumps and calls with a macro similarly to what is done in the recent thread.
Post 22 Nov 2023, 18:49
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 22 Nov 2023, 18:58
pfranz wrote:
Tomasz Grysztar wrote:
A 16-bit jump is no longer position-independent if you put it at a high address, because it then truncates the target address (zeroing the upper half of EIP).
I believe that in unREAL mode that is also used in flatassembler, 16bit code can run over $10000.
Yes, you could attempt that, but you'd have to be very careful. You'd need to make sure that all your jumps have 66h prefixes, to avoid accidental truncation of EIP, and keep the interrupts disabled (for reasons mentioned in my article), or use some convoluted framework to be able to restore the uppers bits of EIP when coming back from an interrupt handler. Not very practical, in my opinion.

But that's about real mode. If you make a 16-bit code segment in protected mode and give it a high limit, you should be able to run 16-bit code above 10000h just fine, but keep your 66h prefixes in place.
Post 22 Nov 2023, 18:58
View user's profile Send private message Visit poster's website Reply with quote
pfranz



Joined: 13 Jan 2007
Posts: 116
Location: Italy
pfranz 22 Nov 2023, 19:18
I don't have these problems, because my code is in a hybrid block that needs high org just for shared data, but then is copied and executed in the first 64k.
But this is not the issue: if you yourself say that in 16bit protected mode, addresses can be over 10000h, why don't you allow assembling of relative jumps and calls at high addresses?
Post 22 Nov 2023, 19:18
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 22 Nov 2023, 19:24
pfranz wrote:
I don't have these problems, because my code is in a hybrid block that needs high org just for shared data, but then is copied and executed in the first 64k.
But this is not the issue: if you yourself say that in 16bit protected mode, addresses can be over 10000h, why don't you allow assembling of relative jumps and calls at high addresses?
I do allow them. See my fist post above.
Post 22 Nov 2023, 19:24
View user's profile Send private message Visit poster's website Reply with quote
pfranz



Joined: 13 Jan 2007
Posts: 116
Location: Italy
pfranz 24 Nov 2023, 02:43
My bad, sorry, you had replied to my question but I hadn't understood the meaning of the prefix, because "dword" looked like "far" just as "pword" in 32bit jumps, and the "and" made me think of an absolute jump (because $ and 0xFFFF is in the first 64K page). I thought they were not relative jumps.
I looked at the generated code: the second is what I wanted, but looks counterintuitive. The first is the same, just adds the 66h prefix.
Post 24 Nov 2023, 02:43
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.