VOGONS


First post, by superfury

User metadata
Rank l33t++
Rank
l33t++

Is the displacement signed or unsigned? So is the displacement 0xFFF8 in memory +FFF8 or -8? E.g. SS:BP+FFF8, does this wrap due to overflow or just substract? Which one is the correct one in disassembly? So does SS:[BP-4] exist as assembly, or is this simply SS:[BP+FFFC]?

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 1 of 6, by vladstamate

User metadata
Rank Oldbie
Rank
Oldbie

That is the same? You add the offset, and it will just wrap around 16bit causing it sometimes to look like a subtraction of the complemented value.

Base : 0x20
Offset: 0xFFF8

Base + Offset = 0x18
Base - 8 = 0x18

So yes in assembly you can have SS:[BP-4] but the assembler will translate that to SS:[BP+FFFC] (which is the 2's complement).

Last edited by vladstamate on 2017-09-22, 14:41. Edited 1 time in total.

YouTube channel: https://www.youtube.com/channel/UC7HbC_nq8t1S9l7qGYL0mTA
Collection: http://www.digiloguemuseum.com/index.html
Emulator: https://sites.google.com/site/capex86/
Raytracer: https://sites.google.com/site/opaqueraytracer/

Reply 2 of 6, by BloodyCactus

User metadata
Rank Oldbie
Rank
Oldbie

it wraps.

fff8 = -8

same thing.

use debug, spend 2 seconds writing test case. look at the code generated. its not hard.

--/\-[ Stu : Bloody Cactus :: [ https://bloodycactus.com :: http://kråketær.com ]-/\--

Reply 3 of 6, by superfury

User metadata
Rank l33t++
Rank
l33t++

What about 8-bit displacements? Are they ALWAYS signed? So a 8-bit displacmeents 0x80 substracts 128 from [(E)SI] etc.? Or is it always added(So e.g. SI(0x8000)+0x80 results in offset 0x8080)?

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 4 of 6, by vladstamate

User metadata
Rank Oldbie
Rank
Oldbie

The question you are asking is if the 8 bit displacement is sign extended. I assume so in the same manner the 8 bit jump offsets are sign extended for Jxx instructions.

Should be easy to find out with debug.exe.

YouTube channel: https://www.youtube.com/channel/UC7HbC_nq8t1S9l7qGYL0mTA
Collection: http://www.digiloguemuseum.com/index.html
Emulator: https://sites.google.com/site/capex86/
Raytracer: https://sites.google.com/site/opaqueraytracer/

Reply 6 of 6, by reenigne

User metadata
Rank Oldbie
Rank
Oldbie

Yes, 8 bit displacements in effective addresses are sign-extended (not zero-extended) to 16 bits. This is useful for compiled code because usually positive offsets from BP are arguments to the current function, and negative offsets from BP are local variables. With the displacement being signed, you can have ~128 bytes of each using single-byte displacements (which is nearly always enough). If the displacements were unsigned, then accesses to most local variables not in registers would be a byte longer.