tags:

views:

104

answers:

5

I am reading the book The Art of Assembly Language. I came across these two lines.

the three byte encoding for mov ax, [1000] would be 0C6h, 00h,
10h and the three byte encoding for mov ax, [2000] would be 0C6h, 00h, 20h.

Can anybody show me how mov ax, [1000] converted to oc6h, ooh, 10h and mov ax, [2000] converted to 0C6h, 00h, 20h. Can anybody show me the calculations? Thanks in advance.

EDIT: I am a starter in assembly programming, kindly explain with description.

+4  A: 

Just guessing, but looks to me like:

0C6h - This is the opcode for "mov ax,"
00h 10h - This is the address 1000h, Little Endian
00h 20h - This is the address 2000h, Little Endian
Chris Shaffer
Thanks Marc - Can't believe I actually typed that :)
Chris Shaffer
@Chris: tsk, that should have been Little Native American.
ninjalj
+2  A: 

00h is the LoByte of the Memory Address

20h is the HiByte of the Memory Address

OC6h is the OpCode instruction for mov, ax

kyndigs
+1  A: 

I'm guessing the mov ax command is 0C6h the 1000/2000 is just an byte ordering issue, you're getting the more significant bytes first (welcome to Endianness)

Rudu
+4  A: 

I'm assuming your confusion lies in the fact that 1000 was encoded as 10h.

ax is an alias for the bottom 16 bits of the 32 bit eax register. So mov ax, 1000 knows that this is a 16-bit operation. 1000 is encoded as 00 10 in memory because it was encoded using little-endianness which basically means that the most significant byte is last in physical order.

Mario
Thanks buddy. This is what I wanted. Thanks a lot again.
+1  A: 

The opcodes for all x86 instructions can be found at http://download.intel.com/design/intarch/manuals/24319101.pdf (mov is at page 442). Chapter 2 describes how opcodes are encoded with register arguments.

Other answers already explain the encoding :-)

cytrinox