8086 Opcodes

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Locked
computertrick
Member
Member
Posts: 71
Joined: Wed May 29, 2013 1:07 pm

8086 Opcodes

Post by computertrick »

I have looked at the opcodes of a short jump to 0x00 with org set to 0x7c00 and the opcodes I get are

Code: Select all

E9 FD 83
I can understand if it said

Code: Select all

E9 00 7C
But where the hell does the FD and 83 come from? Can anyone explain this and prehap's suggest a good reference for opcodes of 8086 please? I have looked around and I am having trouble with understanding short jumps.
1100110100010011
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: 8086 Opcodes

Post by sortie »

Consult the Intel/AMD CPU documentation.
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: 8086 Opcodes

Post by iansjack »

And, when reading it, bear in mind that the jump is relative not absolute.

This is not a question about Operating System Development.
computertrick
Member
Member
Posts: 71
Joined: Wed May 29, 2013 1:07 pm

Re: 8086 Opcodes

Post by computertrick »

iansjack wrote:And, when reading it, bear in mind that the jump is relative not absolute.

This is not a question about Operating System Development.
It is related to operating system development because its on about the processor.
1100110100010011
Prochamber
Member
Member
Posts: 100
Joined: Wed Mar 13, 2013 2:27 am

Re: 8086 Opcodes

Post by Prochamber »

computertrick wrote:I have looked at the opcodes of a short jump to 0x00 with org set to 0x7c00 and the opcodes I get are

Code: Select all

E9 FD 83
I can understand if it said

Code: Select all

E9 00 7C
But where the hell does the FD and 83 come from? Can anyone explain this and prehap's suggest a good reference for opcodes of 8086 please? I have looked around and I am having trouble with understanding short jumps.
This is not jmp short 0x00 this is jmp word 0x0000. You cannot jump to the address 0x0000 with a short jump because a short jump must be within -128 to +127.

Let's analyze this command:
E9 FD 83

The first byte E9 or 1110 1001 means 'jmp near'
You can look this up 16-bit encodings in Appendix D of The Art of Assembly.
Chapter 6 is also a good reference for instructions just remember the examples code with be for MASM not NASM.

The next two bytes are the offset. This is relative not absolute. There are in 'little endian', i.e. least significant first, so they actually mean 0x83FD. The base offset is 0x7C00 and a near jump takes three bytes, therefore a base of 0x7C03. If you add 0x83FD you wrap right around back to zero.

If you are using NASM as your compiler you can use the 'ndisasm' command to disassemble your programs. Set the ORG point with '-o 0x7C00'.
TachyonOS - Violates causality on 95% of attempts. Runs at approximately 1.5c.
computertrick
Member
Member
Posts: 71
Joined: Wed May 29, 2013 1:07 pm

Re: 8086 Opcodes

Post by computertrick »

Prochamber wrote:
computertrick wrote:I have looked at the opcodes of a short jump to 0x00 with org set to 0x7c00 and the opcodes I get are

Code: Select all

E9 FD 83
I can understand if it said

Code: Select all

E9 00 7C
But where the hell does the FD and 83 come from? Can anyone explain this and prehap's suggest a good reference for opcodes of 8086 please? I have looked around and I am having trouble with understanding short jumps.
This is not jmp short 0x00 this is jmp word 0x0000. You cannot jump to the address 0x0000 with a short jump because a short jump must be within -128 to +127.

Let's analyze this command:
E9 FD 83

The first byte E9 or 1110 1001 means 'jmp near'
You can look this up 16-bit encodings in Appendix D of The Art of Assembly.
Chapter 6 is also a good reference for instructions just remember the examples code with be for MASM not NASM.

The next two bytes are the offset. This is relative not absolute. There are in 'little endian', i.e. least significant first, so they actually mean 0x83FD. The base offset is 0x7C00 and a near jump takes three bytes, therefore a base of 0x7C03. If you add 0x83FD you wrap right around back to zero.

If you are using NASM as your compiler you can use the 'ndisasm' command to disassemble your programs. Set the ORG point with '-o 0x7C00'.
Your right sorry I meant a near jump don't know why I put short jump. I see what you mean now.

Cheers
1100110100010011
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: 8086 Opcodes

Post by Gigasoft »

computertrick wrote:
iansjack wrote:And, when reading it, bear in mind that the jump is relative not absolute.

This is not a question about Operating System Development.
It is related to operating system development because its on about the processor.
All computer programs, operating systems or not, run on a processor. If you are struggling to understand how to program the computer system you are using when such information is readily available from the manufacturer, I'd suggest putting off your operating system development for a while.
computertrick
Member
Member
Posts: 71
Joined: Wed May 29, 2013 1:07 pm

Re: 8086 Opcodes

Post by computertrick »

Gigasoft wrote:
computertrick wrote:
iansjack wrote:And, when reading it, bear in mind that the jump is relative not absolute.

This is not a question about Operating System Development.
It is related to operating system development because its on about the processor.
All computer programs, operating systems or not, run on a processor. If you are struggling to understand how to program the computer system you are using when such information is readily available from the manufacturer, I'd suggest putting off your operating system development for a while.
No point putting it off for a while that's giving up... Where would people get if they just gave up on things.
1100110100010011
User avatar
Griwes
Member
Member
Posts: 374
Joined: Sat Jul 30, 2011 10:07 am
Libera.chat IRC: Griwes
Location: Wrocław/Racibórz, Poland
Contact:

Re: 8086 Opcodes

Post by Griwes »

No point carrying on when you lack the basic knowledge and ability to read manuals.
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
AbstractYouShudNow
Member
Member
Posts: 92
Joined: Tue Aug 14, 2012 8:51 am

Re: 8086 Opcodes

Post by AbstractYouShudNow »

Why the hell do you need this for OSDev ?
computertrick
Member
Member
Posts: 71
Joined: Wed May 29, 2013 1:07 pm

Re: 8086 Opcodes

Post by computertrick »

Griwes wrote:No point carrying on when you lack the basic knowledge and ability to read manuals.
Well that's uncalled for... Didn't realise when you ask a question on these forum's big heads respond this way.
1100110100010011
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: 8086 Opcodes

Post by AJ »

Hi,

I've locked the thread.

@op: The reason for the responses you got is that the getting started and rules post in the forum ask you to do some basic research and a very full explanation of what you were asking is contained in the Intel Software Developers Manuals. Having said all that, I do think that the replies you got were a bit harsh and I do agree that opcodes are very relevant to OS development. As for a full reference, try http://ref.x86asm.net/

Cheers,
Adam
Locked