CIS-77 Home http://www.c-jump.com/CIS77/CIS77syllabus.htm

Instruction Format Design


  1. Instruction Format Design
  2. Encoding The Opcodes
  3. Encoding The Opcodes, Cont.
  4. The Goal to Keep Opcodes Small
  5. Variable-length Opcodes
  6. Variable-length Opcodes, Cont.
  7. Example: One-byte Opcodes
  8. Example: Two-byte Opcodes
  9. Example: Three-byte Opcodes
  10. Opcode Length Trade-offs
  11. Planning for the future
  12. Selecting Instruction Set
  13. Instruction Groups
  14. Encoding Instructions
  15. Opcode Design Trade-offs
  16. Reducing x86 ISA to a Simplified Version
  17. The MOV Instruction
  18. Arithmetic and Logical Instructions
  19. Simplified Instruction Encoding (not x86!)
  20. Simplified Instruction Encoding, Cont. (not x86!)
  21. Simplified Instruction Encoding Example (not x86!)
  22. Simplified Multibyte Instructions (not x86!)
  23. Simplified Multibyte Instructions Cont. (not x86!)
  24. Simplified Special Opcode Instructions (not x86!)
  25. Simplified Jump Instructions (not x86!)
  26. Simplified Conditional Jump Instructions (not x86!)
  27. Simplified Instructions Reserved Opcode (not x86!)
  28. Simplified Zero-Operand Instructions (not x86!)
  29. Extending the Simplified Instruction Set (not x86!)
  30. Problem with Extending the Simplified Instruction Set (not x86!)
  31. Prefix-Extending the Simplified Instruction Set (not x86!)
  32. Prefix-Extending the Simplified Instruction Set Example (not x86!)

1. Instruction Format Design


  • Most important feature of instruction set design -

    • make opcodes easy to decode.

  • The easiest way to do this -

    • break up the opcode into several different bit fields.

  • Opcode fields:

      opcode byte

2. Encoding The Opcodes


3. Encoding The Opcodes, Cont.


4. The Goal to Keep Opcodes Small


5. Variable-length Opcodes


6. Variable-length Opcodes, Cont.


7. Example: One-byte Opcodes


8. Example: Two-byte Opcodes


9. Example: Three-byte Opcodes


10. Opcode Length Trade-offs


11. Planning for the future


12. Selecting Instruction Set


13. Instruction Groups


14. Encoding Instructions


  • Some bits are needed to identify:

    • instruction group

    • instruction code

    • operand types: registers, memory locations, constants.

  • All of the above has a direct impact on the instruction size.

  • For example, 8-bit opcode could be split into

    • one 3-bit iii field to describe instruction and its group, and

    • two fields, rr and mmm, (5 bits together) to specify where the instruction operands could be found.

     

     

  • An opcode byte:

      opcode byte

15. Opcode Design Trade-offs


16. Reducing x86 ISA to a Simplified Version


17. The MOV Instruction


18. Arithmetic and Logical Instructions


  • The arithmetic and logical instructions could take the following forms:

        add reg, reg/memory/constant
    
        sub reg, reg/memory/constant
    
        cmp reg, reg/memory/constant
    
        and reg, reg/memory/constant
    
        or  reg, reg/memory/constant
    
        not reg/memory
    

     

  • 1-operand instructions modify its operand.

  • 2-operand instructions store the result in the destination operand:

      Instruction formats

19. Simplified Instruction Encoding (not x86!)


  • Three high-order bit field, iii, defines the instruction and allows 8 unique bit combinations.

  • (Since we decided to encode 20 different instructions, we cannot encode them with three bits, so we'll have to pull some tricks to handle all of the instructions.)

  • Consider one-byte opcode with an optional two-byte constant value:

      simplified instruction encoding

20. Simplified Instruction Encoding, Cont. (not x86!)


  • There are three iii encoding groups:

    1. Special instruction class iii=000 is reserved for instruction set expansion in the future.

    2. Two forms of the MOV instruction include:

      • iii=110 specifies rr field is the destination,

      • iii=111 specifies mmm field is the destination.

    3. Remaining codes belong to ADD, SUB, CMP, AND, and OR instructions: simplified instruction encoding

  • Another opcode field, rr, contains the destination register,

  • ...except for MOV whose iii = 111, in which case rr specifies the source register.

  • Third bit field, mmm, encodes the source operand (again, except MOV whose iii = 111.)

21. Simplified Instruction Encoding Example (not x86!)


  • For example, encoding of instruction

            mov ax, bx
    

    consists bit fields

    1. iii=110 is the encoding for MOV REG, REG.

    2. rr=00 specifies that AX is the destination operand.

    3. mmm=001 specifies that BX is the source operand.

  • Simplified opcode structure:

      simplified instruction encoding

22. Simplified Multibyte Instructions (not x86!)


23. Simplified Multibyte Instructions Cont. (not x86!)


  • To encode immediate constant values and address modes such as

      0xxxxh          ; immediate mode
      [ 0xxxxh ]      ; direct mode
      [ 0xxxxh + bx ] ; fixed base + reg
    

    we add two bytes of 16-bit address or constant value to the opcode:

    • low-order byte immediately follows the opcode byte in memory, and

    • high-order byte comes after that.

  • Simplified multibyte instruction encoding: Simplified multibyte instruction encoding

  • Three-byte encoding for MOV AX, [1000h] instruction becomes

        C6 00 10
    

    and the three-byte encoding for MOV AX, [2000h] is

        C6 00 20
    

24. Simplified Special Opcode Instructions (not x86!)


  • The special opcode [7:5]=000 allows our imaginary CPU to expand the set of available instructions.

  • This opcode handles several zero- and one-operand instructions.

  • Imaginary Single-Operand Instruction Encoding:

      Single Operand Instruction Encoding

25. Simplified Jump Instructions (not x86!)


  • There are seven jump instructions in the simplified x86 instruction set. They all take the following form:

            jxx address
    
  • The JMP instruction copies the 16-bit value (address) following the opcode into the IP register.

  • Imaginary jump instruction encodings:

      Jump Instruction Encodings

26. Simplified Conditional Jump Instructions (not x86!)


  • There are six conditional jump instructions:

        JA  - jump if greater than (above)
        JAE - jump if greater than or equal
        JB  - jump if less than (below)
        JBE - jump if less than or equal
        JE  - jump if equality
        JNE - jump if inequality
    
  • You would normally execute JE or similar instruction immediately after a CMP instruction, since it sets the less than and equality flags in the CPU for conditional jump instructions to look at.

27. Simplified Instructions Reserved Opcode (not x86!)


  • Note that there are eight possible jump opcodes, but so far we needed only seven of them.

  • The eighth opcode, mmm=111 should then be another illegal opcode.

     

  • Imaginary jump instruction encodings:

      Jump Instruction Encodings

28. Simplified Zero-Operand Instructions (not x86!)


  • The last group of instructions is the zero operand instructions.

  • Three of these instructions are illegal instruction opcodes.

  • The BRK (break) instruction pauses the CPU until the user manually restarts it.

    • This is useful for pausing a program during execution to observe results.

  • The IRET (interrupt return) instruction returns control from an interrupt service routine.

    • (We will discuss interrupt service routines later.)

  • Zero Operand Instruction Encodings:

      Zero Operand Instruction Encodings

29. Extending the Simplified Instruction Set (not x86!)


  • The simplified CPU architecture design does provide the capability for expansion.

  • The ability to accomplish this exists in the instruction set through undefined/reserved/illegal opcodes.

  • Imaginary single-operand instruction encoding:

      single operand instruction encoding

30. Problem with Extending the Simplified Instruction Set (not x86!)


  • Unfortunately, the simplified CPU doesn't have that many illegal opcodes available.

  • For example, to add new single-operand instructions

        SHL - shift left
        SHR - shift right
        ROL - rotate left
        ROR - rotate right
    
  • Imaginary single-operand instruction encoding:

      single operand instruction encoding

31. Prefix-Extending the Simplified Instruction Set (not x86!)


32. Prefix-Extending the Simplified Instruction Set Example (not x86!)