delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/26/12:00:58

Date: Sat, 26 Jul 1997 09:00:36 -0700 (PDT)
Message-Id: <199707261600.JAA29591@adit.ap.net>
Mime-Version: 1.0
To: pweeks AT execulink DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: Intel opcodes: ModR/M and SIB bytes
Cc: djgpp AT delorie DOT com

Lugging out Intel's _80386_Programmer's_Reference_Manual_ ...
>I think I've got the SIB byte down:  The first two bits are the scale
>(00 = 1, 01 = 2, 10 = 4, 11 = 8... is that correct?), the next three
>bits are the index register, and the next three bits are the base
>register.  Is that all correct?
Yep, that's all correct.
>
>Okay, now what about the ModR/M byte?  That one really confuses me.  I
>really don't know much about it at all.  I don't understand the function
>of the first two bits.  The next three bits, to my understanding hold
>either a register (the first operand?), or another three bits of the
>opcode, is that right?  And the last three bits, to my understanding,
>hold either another register (the second operand?) or something else
>(what?)?
Quoting from manual...

The ModR/M byte contains three fields of information:

- The mod field, which occupies the two most significant bits of the byte,
combines with the r/m field to form 32 possible values: eight registers and
24 indexing modes
- The reg field, which occupies the next three bits following the mod field,
specifies either a register number or three more bits of opcode information.
The meaning of the reg field is determined by the first (opcode) byte of the
instruction.
- The r/m field, which occupies the three least significant bits of the
byte, can specify a register as the location of an operand, or can form part
of the addressing-mode encoding in combination with the mod field as
described above

The book also contains several charts showing the encoding of each possible
ModR/M byte and SIB byte. I might be able to scan and send them to you if
necessary. Or you might be able to get a copy of its current equivalent
(maybe Pentium) from Intel. It *would* be helpful for writing an assembler.

>Lastly, how do you know, for example, wether certain bits form a
>register, or their other purpose?  Is that designated by each certain
>opcode?
Yes.

HTH

Nate Eldredge
eldredge AT ap DOT net



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019