CMPT 295 - Unit - Instruction Set Architecture

Lecture 23

Last Lecture - 1

Last Lecture - 2

Brief look at:

Today’s Menu

Reference

The Big Picture – Above the hood

C code:

short abs(short aNumber){
  short result=0;
  if(aNumber>0) result=aNumber;
  else result=-aNumber;
  return result;
}

Assembly code:

  .global abs
abs:
  movl %edi,%eax
  testw %di,%di
  jle .L3
.L2:
  ret
.L3:
  negl %eax
  jmp .L2

Machine code:

1111100010001001
111111111000010101100110
0000001001111110
1100001111110011
1101100011110111
1111101011101011

The Big Picture - Under the hood!

Wikipedia says: A datapath is a collection of functional units such as:

Along with the control unit, the datapath composes the central processing unit (CPU/microprocessor).

Microprocessor datapath

Machine code below is stored in Instruction Memory:

1111100010001001
111111111000010101100110
0000001001111110
1100001111110011
1101100011110111
1111101011101011

Instruction Set Architecture (ISA)

Instruction Set Architecture (ISA)

An ISA is a formal specification of …

Instruction Set Architecture (ISA) cont’d

An ISA is a formal specification of … (cont’d)

Memory Models:

Address resolution is the smallest addressable memory “chunk”.

Model 1 – word-addressable computer

Memory layout with 232×162^{32} \times 16 bits; 16 is the “address resolution”:

Address Value (width = address resolution)
23212^{32}-1  
 
2  
1  
0  

Example of word-addressable ISAs:

In this model, n = wordsize; wordsize is 16 bits.

Model 2 – byte-addressable computer

Memory layout with 232×82^{32} \times 8 bits. 8 is the address resolution.

Address Value (8 bits in width)
23212^{32}-1 a.k.a 4294967232  
 
2  
1  
0  

Compressed View of Memory:

Address +1 +2 +3 +4 +5 +6 +7
23212^{32-1} a.k.a. 4294967295              
             
16              
8              
0              

In this model nwordsizen \neq \text{wordsize}; wordsize = 64 bits.

Examples of byte-addressable ISA:

Model 3

Target machine:

Example of an ISA: x86

Instruction set (IS) design guidelines

  1. Each instruction of IS must have an unambiguous binary encoding, so CPU can unambiguously decode and execute it -> let’s assign a unique opcode to each instruction
  2. IS is functionally complete -> i.e., it is “Turing complete”; it will have 3 classes of instructions:
    1. Data transfer instructions – Memory reference
    2. Data manipulation instructions – Arithmetic and logical
    3. Program control instructions – Branch and jump
  3. In terms of machine instruction format:
    1. Create as few of them as possible
    2. Have them all of the same length and same format!
    3. If we have different machine instruction formats, then position the fields that have the same purpose in the same location in the format

1. “Each instruction of IS must have an unambiguous binary encoding …”

Assembly instruction:

An assembly instruction will compile (more specifically, “assemble”) into a:

Machine Instrucction:

What is an opcode? What is an operand?

Example using x86-64:

Mixed assembly and hex machine instructions:

00000000004004b7 <someFcn>:
  4004b7:   4c 03 00  add (%rax),%r8
  4004ba:   7e fb     jle 4004b7 <someFcn>
  4004bc:   c3        retq

Binary machine instructions:

000000000000001101001100
1111101101111110
11000011
 diff. length\therefore \text{ diff. length}

Types of instruction sets

CISC:

RISC:

Summary

Next lecture