Caption: THE #1 PROGRAMMER EXCUSE FOR LEGITIMATELY SLACKING OFF: 'MY CODE IS COMPILING.' Two stick figures standing on desk chairs fight eachother with lightsabers. From outside the open door, somebody yells 'HEY! GET BACK TO WORK!' One of the programers reponds: 'COMPILING!' The person from outside replies back 'OH. CARRY ON.'

CMPT 295 - Unit - Instruction Set Architecture

Lecture 25

Last Lecture

Format of assembly instruction not necessarily == format of machine instruction

From last lecture!

Example of an ISA: MIPS

Register name Number Usage
$zero 0 constant 0
$at 1 reserved for assembler
$v0 2 expression evaluation and results of a function
$v1 3 expression evaluation and results of a function
$a0 4 argument 1
$a1 5 argument 2
$a2 6 argument 3
$a3 7 argument 4
$t0 8 temporary (not preserved across call)
$t1 9 temporary (not preserved across call)
$t2 10 temporary (not preserved across call)
$t3 11 temporary (not preserved across call)
$t5 12 temporary (not preserved across call)
$t6 13 temporary (not preserved across call)
$t7 14 temporary (not preserved across call)
$s0 15 saved temporary (preserved across call)
$s1 16 saved temporary (preserved across call)
$s2 17 saved temporary (preserved across call)
$s3 18 saved temporary (preserved across call)
$s4 19 saved temporary (preserved across call)
$s5 20 saved temporary (preserved across call)
$s6 21 saved temporary (preserved across call)
$s7 22 saved temporary (preserved across call)
$t8 24 temporary (not preserved across call)
$t9 25 temporary (not preserved across call)
$k0 26 reserved for OS kernel
$k1 27 reserved for OS kernel
$gp 28 pointer to global area
$sp 29 stack pointer
$fp 30 frame pointer
$ra 31 return address (used by function call)

From last lecture! – MIPS - Design guidelines

From last lecture! – MIPS ISA designers compromise

Today’s Menu

Let’s design our own ISA - x295M (1 of 2)

Let’s design our own ISA - x295M (2 of 2)

x295M assembly language instructions Semantic (i.e., Meaning) Corresponding x295M machine instructions
ADD a, b, c M[c] = M[a] + M[b] 01 <30 bits> 00 <30 bits> 00 <30 bits>
SUB a, b, c M[c] = M[a] - M[b] 10 <30 bits> 00 <30 bits> 00 <30 bits>
MUL a, b, c M[c] = M[a] * M[b] 11 <30 bits> 00 <30 bits> 00 <30 bits>

Note about the machine code format

Format 1 (within a word):

opcode memory address

Format 2 (within a word):

X memory address

About Design guideline:

3) In terms of machine instruction format:

  1. Create as few of them as possible -> 2 formats
  2. Have them all of the same length -> 32 bits
  3. Since we have two different machine instruction formats, fields with same purpose are positioned in the same location in the 2 formats ->
    • operand field (purpose -> memory address) positioned in the same location in the 2 formats

Evaluation of our ISA x295M versus MIPS

Sample C code: z=(x+y)×(xy)z = (x + y) \times (x - y)

Evaluation of our ISA x295M versus MIPS

Sample C code: z=(x+y)×(xy)z = (x + y) \times (x - y)

Stack segment:

Memory Stack Segment
   
   
   
   
   
   
0x7fffff00<- $sp ->  
   
   
   

Text Segment:

Memory Text Segment
   
   
   
   
   
   
   
   
   
0x00400000 ->  
Opcode Encoding
ADD 01
SUB 10
MUL 11
No op 00
Assembly code Memory address/machine code pt. 1 Memory address/machine code pt. 2 Memory Address/machine code pt. 3
ADD 0($sp),4($sp),12($sp) 0x00400000 / 01 0x7fffff0c 0x00400004 / 00 0x7fffff00 0x00400008 / 00 0x7fffff04
SUB 0($sp),4($sp),16($sp) 0x0040000c / 10 0x7fffff10 0x00400010 / 00 0x7fffff00 0x00400014 / 00 0x7fffff04
MUL 12($sp),16($sp),8($sp) 0x00400018 / 11 0x7fffff08 0x0040001c / 00 0x7fffff0c 0x00400020 / 00 0x7fffff10

Evaluation of our ISA x295M versus MIPS

Sample C code: z=(x+y)×(xy)z = (x + y) \times (x - y)

C code -> Assembly code Meaning
lw $s1,0($sp) $s1 = M[$sp + 0]
lw $s2,4($sp) $s2 = M[$sp + 4]
add $a3,$s1,$s2 $s3 = $s1 + $s2
sub $s4,$s1,$s2 $s4 = $s1 - $s2
mul $s5,$s3,$s4 $s5 = $s3 * $s4
sw $s5,8($sp) M[$sp + 8] = $s5

Evaluation of our ISA x295M versus MIPS

Opcode table:

Opcode + func Encoding
lw 3510\text{35}_{10}
sw 4310\text{43}_{10}
add 0+32100 + \text{32}_{10}
sub 0+34100 + \text{34}_{10}
mul 0+36100 + \text{36}_{10}

Register table:

Register Number
$s1 1710\text{17}_{10}
$s2 1810\text{18}_{10}
$s3 1910\text{19}_{10}
$s4 2010\text{20}_{10}
$s5 2110\text{21}_{10}
$sp 2910\text{29}_{10}

Sample C code: z=(x+y)×(xy)z = (x + y) \times (x - y)

I-format src dest  
opcode 6 bits rs 5 bits rt 5 bits Address/immediate 16 bits
Assembly code Machine code
lw $s1,0($sp) 100011 11101 10001 0x0000
lw $s2,4($sp) 100011 11101 10010 0x0004
sw $s5,8($sp) 101011 10101 11101 0x0008
R-format src1 src2 dest    
opcode 6 bits rs 5 bits rt 5 bits rd 5 bits shamt 5 bits func 6 bits
Assembly code Machine code
add $s3,$s1,$s2 000000 10001 10010 10011 00000 100000
sub $s4,$s1,$s2 000000 10001 10010 10100 00000 100010
mul $s5,$s3,$s4 000000 10011 10100 10101 00000 100100

Evaluation of our ISA x295M versus MIPS

Sample C code: z=(x+y)×(xy)z = (x + y) \times (x - y)

x295M in machine code:

Memory address of each instruction at address +1 +2 +3 +4 +5 +6 +7
0x00400000 01 11 1111 1111 1111 1111 1111 0000 1100
0x00400004 00 11 1111 1111 1111 1111 1111 0000 0000
0x00400008 00 11 1111 1111 1111 1111 1111 0000 0100
0x0040000c 10 11 1111 1111 1111 1111 1111 0001 0000
0x00400010 00 11 1111 1111 1111 1111 1111 0000 0000
0x00400014 00 11 1111 1111 1111 1111 1111 0000 0100
0x00400018 11 11 1111 1111 1111 1111 1111 0000 1000
0x0040001c 00 11 1111 1111 1111 1111 1111 0000 1100
0x00400020 00 11 1111 1111 1111 1111 1111 0001 0000

MIPS in machine code:

Memory address of each instruction Machine code
0x00400000 100011 11101 10001 0000 0000 0000 0000
0x00400004 100011 11101 10010 0000 0000 0000 0100
0x00400008 000000 10001 10010 10011 00000 100000
0x0040000c 000000 10001 10010 10100 00000 100010
0x00400010 000000 10011 10100 10101 00000 100100
0x00400014 101011 10101 11101 0000 0000 0000 0008

Which criteria shall we use when comparing/evaluating ISAs?

Which criteria shall we use when comparing/evaluating ISAs?

Why is memory access slow!

Diagram:

A box labled CPU contains Registers, Condition Codes, PC. It is on the left. A box labled Memory is on the right. There is an arrow from CPU to Memory labled “Address Bus”. There is a double-sided arrow from CPU and Memory, labled “Data Bus”. Finally, there is an arrow from Memory to the CPU labled “Instruction Bus”.

How is the von Neumann Bottleneck created?

Evaluation of our ISA x295M versus MIPS

x295M fetch decode/execute MIPS fetch decode/execute
ADD 0($sp), 4($sp), 12($sp)   lw $s1,0($sp)      
SUB 0($sp), 4($sp), 16($sp)   lw $s2,4($sp)      
MUL 12($sp), 16($sp), 8($sp)   add $s3,$s1,$s2      
    sub $s4,$s1,$s2      
    mul $s5,$s3,$s4      
    sw $s5,8($sp)      

Total: _____

Summary

Next Lecture