Hi, I'm trying to manually translate 16-bit assembly intruction into the format Instruction Prefix-Opcode-ModR/M-SIB-Address Displacenebt-Immediate Data for an Intel8086. I'm having problems trying to figurit out when to use the respective values for the Mod, the R/M. If anyone could point a good book or site for this type of exercise or if anyone could explain when each value is used, I would appreciate it.


Recommended Answers

All 4 Replies

Here's what some of the values mean in the modR/M byte:
Operands Mod Reg R/M Displacement
Reg,Reg 11 XXX XXX Here R/M is treated as Reg
Mem (Direct Addressing Mode) 00 XXX 110 [Lo-Byte][Hi-Byte]
[BX+SI] 00 XXX 000
[BX+SI+Displacement] 01 XXX 000 [Byte]
[BX+SI+Displacement] 10 XXX 000 [Lo-Byte][Hi-Byte]
[BX+DI] 00 XXX 001
[BX+DI+Displacement] 01 XXX 001 [Byte]
[BX+DI+Displacement] 10 XXX 001 [Lo-Byte][Hi-Byte]
[BP+SI] 00 XXX 010
[BP+SI+Displacement] 01 XXX 010 [Byte]
[BP+SI+Displacement] 10 XXX 010 [Lo-Byte][Hi-Byte]
[BP+DI] 00 XXX 011
[BP+DI+Displacement] 01 XXX 011 [Byte]
[BP+DI+Displacement] 10 XXX 011 [Lo-Byte][Hi-Byte]
[SI] 00 XXX 100
[SI+Displacement] 01 XXX 100 [Byte]
[SI+Displacement] 10 XXX 100 [Lo-Byte][Hi-Byte]
[DI] 00 XXX 101
[DI+Displacement] 01 XXX 101 [Byte]
[DI+Displacement] 10 XXX 101 [Lo-Byte][Hi-Byte]
[BX] 00 XXX 111
[BX+Displacement] 01 XXX 111 [Byte]
[BX+Displacement] 10 XXX 111 [Lo-Byte][Hi-Byte]

The SIB (Scale Index Base) byte is used in 32-bit code,
I would suggest getting ahold of the 80186 architecture manual,
80386 programmer's reference, and I believe Art Of Assembly
also explains instruction format.

So the value for the mod r/m depends on what the source operand is, whether it is ax, [ax], inmidate value or combination, and whether it has more than one byte. I'll look for that book at school or the local bookstore. Thanks.

Whether the operands are 8-bit or 16-bit is specified in the
opcode of the instruction by the word bit (bit 0), also
whether REG field in the modR/M specifies the destination
operand is determined by the destination bit (bit 1) of the opcode.
You should be able to find documentation online,
beats pumping out pennies for documentation.
The books I mentioned previously can be found on the web.

Thanks for the points and the book, they were of help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.