On Saturday, March 13, 2021 at 5:48:45 PM UTC+11, Rod Pemberton wrote:
> > I would now like to run 16-bit programs while
> > remaining in 80386 mode.
> >
> Sigh, don't we all,
Oh. I didn't realize someone else wanted to do
that. Why do you want to do that?
Note that I'm only talking about tiny memory
model.
> but how do you do that
> without processor support? Binary translation
> was the only solution I found.
We'll see.
> > Then I want to use 80386 instructions that never
> > disturb the high 16 bits of registers. I believe that
> > means putting a lot of db x'66' and db x'67' (or
> > something like that) in front of a lot of instructions
> > to make them do 16-bit operations instead of
> > 32-bit operations.
> While that (mixed-mode code using address/operand
> instruction overrides) will work for plenty of
> instructions, it won't work for the different
> addressing modes for 16-bit and 32-bit.
Sorry, I was mistaken about using prefixes. I don't
think that's what I want.
> 16-bit addressing modes work against 4 of 8
> 16-bit registers, using addition of two of the
> registers: bx, bp, si, di. 32-bit addressing
> modes work directly against 7 of 8 32-bit
> registers: eax, ebx, ecx, edx, ebp, esi, edi.
> I.e., how do you convert an address reference
> against bp+si to eax? esi? or, vice-versa?
In that case, I don't want to generate code that
does a bp+si. I will do two adds instead if
necessary. The final address reference will
then use eax or esi.
> I gave an example to you in 2018 of how
> code would need to be converted to work
> for both modes:
>
> ;32-bit code
> 00000028 89FB mov ebx,edi
> 0000002A 8B4720 mov eax,[edi+32]
>
> ;16-bit code
> 00000028 89FB mov bx,di
> 0000002A 8B4720 mov ax,[bx+0x20]
>
> In other words, I don't know how to fully convert
> 16-bit mode code to 32-bit mode code while using
> only address-size/operand-size overrides due to
> differences in addressing modes. This would seem
> to require binary translation to perform.
Ok, maybe the problem here is that there are
insufficient 16-bit only instructions. The same
problem exists in S/370. It uses 32-bit registers,
and the only instructions you can use that only
touch the lower 16 bits is ICM (insert 1 or 2
characters) and STCM (store 1 or 2 characters).
To do what I want (16-bit programming) on S/370
will require more instructions than just ICM and
STCM. Although I've just realized that I do have
another option for S/370. I can generate instructions
that change the upper 16-bits of 32-bit registers,
but then immediately restore them to their previous
values.
On a real 16-bit S/370, those instructions will simply
do nothing.
I think I can do the same with 80386. Or maybe we
can add some 16-bit instructions to the 80386. Is
that possible?
Thanks. Paul.