StudentCodingHUB

Use programming to create innovative things.
  • new post

    Thursday, 19 March 2015

    Computer Instruction Codes

    Computer instructions are the basic components of a machine language program. They are also known as macro operations, since each one is comprised of a sequences of micro operations.

    Each instruction initiates a sequence of micro operations that fetch operands from registers or memory, possibly perform arithmetic, logic, or shift operations, and store results in registers or memory.

    Instructions are encoded as binary instruction codes. Each instruction code contains of a operation code, or opcode , which designates the overall purpose of the instruction (e.g. add, subtract, move, input, etc.).

    The number of bits allocated for the opcode determined how many different instructions the architecture supports.

    In addition to the opcode, many instructions also contain one or more operands, which indicate where in registers or memory the data required for the operation is located.

    For example, and add instruction requires two operands, and a not instruction requires one.
                 15    12 11          6 5          0
                +-----------------------------------+
                | Opcode |  Operand    |  Operand   |
                +-----------------------------------+
               
    The opcode and operands are most often encoded as unsigned binary numbers in order to minimize the number of bits used to store them.
    For example, a 4-bit opcode encoded as a binary number could represent up to 16 different operations.


    The control unit is responsible for decoding the opcode and operand bits in the instruction register, and then generating the control signals necessary to drive all other hardware in the CPU to perform the sequence of micro operations that comprise the instruction.

    Designing an Instruction Code
    Machine instruction codes may all be the same length (e.g. MIPS processor), or codes for different instructions may be different lengths (e.g. x86, VAX processors).
    Suppose all instruction codes of a hypothetical accumulator-based CPU are exactly 16 bits. A simple instruction code format could consist of a 4-bit operation code (opcode) and a 12-bit memory address.
                     15    12 11           0
                    +-----------------------+
                    | Opcode | Address      |
                    +-----------------------+
                    
    5.1.2.4. Some Common Addressing Modes
    • Direct: Instruction code contains address of operand
                          0 005   AC = AC + contents of address 5
                         
      * 1 memory-reference beyond fetching instruction
    • Immediate: Instruction code contains operand
                          1 005   AC = AC + 5
                         
      * No memory-reference after fetching instruction
    • Indirect: Instruction code contains address of address of operand
                          2 005   AC = AC + contents of address stored at address 5
                         
      * 2 memory-references after fetching instruction
    Effective address = actual address of the data in memory.


    No comments:

    Post a Comment