OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Apr 24, 2024 6:20 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 25 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: 8086, 80386 and x86-64 compatible instructions
PostPosted: Mon Feb 03, 2014 10:27 am 
Offline
Member
Member

Joined: Thu Jul 05, 2012 5:12 am
Posts: 923
Location: Finland
I have tried to find it in the old Intel 8086 manual but it always ends up being a "not used" instruction. Is it like an undocumented instruction that has always worked? It is hard to believe that NASM has this kind of bug because it has been in use so long. I want to be wrong.

_________________
Undefined behavior since 2012


Top
 Profile  
 
 Post subject: Re: 8086, 80386 and x86-64 compatible instructions
PostPosted: Mon Feb 03, 2014 11:28 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 27, 2004 11:00 pm
Posts: 874
Location: WA
it is an s:w instruction -- that is the last two bits of the first byte indicate the size of the operands:
00 - 8-bit immediate, 8-bit destination
01 - 16-bit immediate, 16-bit destination
10 - nonsense on 8086 (would be 8-bit immediate sign extended to 8-bit destination)
11 - 8-bit immediate sign extended to 16-bit destination -- this is the encoding nasm is using, to represent 8-bit '01' sign extended and ANDed to the 16-bit AX


8086 does support sign-extended immediates using s:w, but doesn't list this as an s:w instruction (well, i don't have a proper "manual" but my 1982 intel catalog does list the full instruction set), so it is likely supported, but undocumented, though I don't have any way to confirm that

_________________
## ---- ----- ------ Intel Manuals
OSdev wiki


Top
 Profile  
 
 Post subject: Re: 8086, 80386 and x86-64 compatible instructions
PostPosted: Mon Feb 03, 2014 11:31 am 
Offline
Member
Member
User avatar

Joined: Fri Dec 15, 2006 5:26 pm
Posts: 437
Location: Church Stretton Uk
Instructions like and ax, 2 have always been available. It used to be the case that the only shift instructions with immediate operands were those with shifted the contents of a register by one bit, as in shl ax, 1. All other shifts had to be of the form shl ax,cl, and it had to be the cl register.

Similarly, in/out instructions could only take an immediate operand in the port number was below 0x80. For other ports, the port number had to be loaded into the dx register. out dx,al or in al,dx. Push and pop instructions could never take immediate operands.

And so on.

Anyway, except for a real mode boot loader, all of that has been left behind now.

_________________
The continuous image of a connected set is connected.


Top
 Profile  
 
 Post subject: Re: 8086, 80386 and x86-64 compatible instructions
PostPosted: Mon Feb 03, 2014 11:36 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 27, 2004 11:00 pm
Posts: 874
Location: WA
mathematician wrote:
Instructions like and ax, 2 have always been available. It used to be the case that the only shift instructions with immediate operands were those with shifted the contents of a register by one bit, as in shl ax, 1. All other shifts had to be of the form shl ax,cl, and it had to be the cl register.

Similarly, in/out instructions could only take an immediate operand in the port number was below 0x80. For other ports, the port number had to be loaded into the dx register. out dx,al or in al,dx. Push and pop instructions could never take immediate operands.

irrelevant -- we are not discussing whether or not
AND R/M16, imm16
is legal on 8086, we are talking about whether
AND R/M16, imm8
is legal on 8086 -- did 8086 support sign-extended immediate on AND instruction, that is the question (the manuals don't list it, but nasm emitted it)




edit:
found this on nasm page:
Code:
AND              rm16,imm8                8086,LOCK

indicates at least nasm thinks its available on 8086 (so, not a bug in nasm, its intentional, so either they were wrong about its support or it is valid, just officially undocumented, most likely the later

_________________
## ---- ----- ------ Intel Manuals
OSdev wiki


Top
 Profile  
 
 Post subject: Re: 8086, 80386 and x86-64 compatible instructions
PostPosted: Mon Feb 03, 2014 12:06 pm 
Offline
Member
Member

Joined: Thu Jul 05, 2012 5:12 am
Posts: 923
Location: Finland
It is not just 8086 but I wonder whether it is available on 80286. Why on earth the 8086 manual left just the "AND" undocumented if it was available? AND is the "83 MOD 100 R/M".


Attachments:
8086.png
8086.png [ 29.36 KiB | Viewed 3551 times ]

_________________
Undefined behavior since 2012
Top
 Profile  
 
 Post subject: Re: 8086, 80386 and x86-64 compatible instructions
PostPosted: Mon Feb 03, 2014 12:20 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5143
Opcode 83 /4 isn't specifically mentioned in any 8086 or 8088 manuals I can find, but it (along with opcode 82) is present in the opcode matrix in the IBM 5150 technical reference manual.

If you can find someone to solder new capacitors into my Toshiba T1000SE, I can test these opcodes on a real 8086 to confirm that they work. :mrgreen:


Top
 Profile  
 
 Post subject: Re: 8086, 80386 and x86-64 compatible instructions
PostPosted: Mon Feb 03, 2014 12:44 pm 
Offline
Member
Member
User avatar

Joined: Wed Oct 27, 2004 11:00 pm
Posts: 874
Location: WA
Octocontrabass wrote:
Opcode 83 /4 isn't specifically mentioned in any 8086 or 8088 manuals I can find, but it (along with opcode 82) is present in the opcode matrix in the IBM 5150 technical reference manual.

82?? that would certainly be a strange instruction (that would be the nonsense instruction i mentioned before about sign extended an 8-bit immediate to 8 bits...

_________________
## ---- ----- ------ Intel Manuals
OSdev wiki


Top
 Profile  
 
 Post subject: Re: 8086, 80386 and x86-64 compatible instructions
PostPosted: Mon Feb 03, 2014 1:55 pm 
Offline
Member
Member
User avatar

Joined: Mon Jan 26, 2009 2:48 am
Posts: 792
Funny that TEST r/m16, imm8 has never been supported.


Top
 Profile  
 
 Post subject: Re: 8086, 80386 and x86-64 compatible instructions
PostPosted: Mon Feb 03, 2014 2:36 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5143
That's because TEST r/m8, imm8 and TEST r/m16, imm16 are opcodes F6 /0 and F7 /0. Had those instructions been mapped to opcodes 80 and 81, it probably would be supported by now.


Top
 Profile  
 
 Post subject: Re: 8086, 80386 and x86-64 compatible instructions
PostPosted: Tue Feb 04, 2014 9:53 am 
Offline
Member
Member

Joined: Thu Jul 05, 2012 5:12 am
Posts: 923
Location: Finland
For me the "83 /4" is suspicious enough and I simply stop using it if I want to have 8086/80286 compatible code. It may work but the 8086 manual explicitly says it is not used and the 80286 manual does not mention it. Enough reasons for me.

_________________
Undefined behavior since 2012


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 56 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group