News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

ModR/M byte (maybe?)

Started by vandelay, December 15, 2005, 08:10:32 PM

Previous topic - Next topic

vandelay

I'll often see opcodes specified as some stuff /some number e.g. FNSAVE is DD /6. Is that referring to the ModR/M byte?

If that's what it is, say, I'm in a 16 bit mode and I want to FNSAVE to immediate memory location. Do I go to the ModR/M table, read off the displacement addressing mode, and put that after the opcode? i.e. would the opcode be DD 35 [some displacement]?

If that's not the ModR/M byte, what the heck is it, and what is the ModR/M byte?

Also, what's a good introduction to assembly book? Right now I'm looking stuff up in the Intel manual whenever there's something I don't get, but that's probably not the best way to learn assembly.

MazeGen

The slash indicates what contains reg/opcode field (bits 3-5) in ModR/M byte. I can be either register code (it is /r then) or an opcode extension (it is /6, for instance). In most cases, the opcode extension is used if the instruction uses one operand only.

As for FNSAVE in 16-bit mode with immediate memory location, the mod field (bits 6-7) would contain 00 bin and the r/m field (bits 0-2) 110 bin (that's the pure displacement addressing mode). The reg/opcode field would contain the value of 6. Here comes the result: DD hex 00110110 bin, followed by the displacement value.

vandelay

Thanks; that makes sense.

What about when only one operand is used, and no opcode extension is specified? e.g. SETcc is specified as 0F 9E r/m8.

My assembler uses 0F 9E DA for SETLE DL and 09 DE 98 for SETLE AL, so the opcode extension it uses seems to be 011. Can I replace that with an arbitrary opcode extension, or does it have to be 011? If it has to be 011, how can I tell from looking at the manual?

MazeGen

You got it, SETcc is one of (or the only?) exception.

According to my Intel manual (253667-017 September 2005), the only valid encoding is 000 bin:

QuoteSETcc, Eb - Byte Set on condition (000) 1K

1K Valid encoding for the reg/opcode field of the ModR/M byte is shown in parenthesis.

You can find it in APPENDIX A, Table A-4. Two-Byte Opcode Map for Non-64-Bit Mode (First Byte is 0FH). It could be different table number if you use different revision of the manual.

I expect that any encoding should be valid. You can try it with different disassemblers, or the best on different processors.