Design Document


This document outlines the design and implementation of the Mach 5 Proccessor Architecture. The Mach 5 architecture is a 16-bit architecture. Each instruction is fixed width at 16 bits. There are 16 addressable instructions and 16 addressable general purpose registers. There are also 128 special purpose registers, some of these registers are availible for use while others have a predefined purpose.

Assembly Language Specification:

OperationParameter 1Parameter 2Parameter 3DescriptionOperator NumberSample Instruction
Mathematical Operations
adddestination registersource registersource registerAdds the values in the source registers and stores it in the destination register.10add $t0, $t1, $t2
subdestination registerminuend registersubtrahend registerSubtracts the value in the subtrahend value from the minuend register and stores the result in the result registerPseudosub $t0, $t1, $t2
ordestination registersource registersource registerOrs the values in the source registers and stores the result in the destination register14or $t0, $t1, $t2
oridestination registersource register16 bit immediate valueOrs the value in the source register with the 16 bit immediate valuePseudoori $t1, $t2, 0x16
negdestination registersource registerN/ATakes number stored in the source register and stores its 2's-compliment negation in the destination register.2neg $t0, $1
multdesination registersource registersource registerMultiplies the values in the source registers and stores the result in the destination register6mult $t0, $t1, $t2
divdestination registernumerator registerdenominator registerDivides the value in the numerator register by the value in the denominator register and stores the result in the destination register (NOTE: this is integer division).7div $t0, $t1, $t2
Shift Operations
slldestination registersource register8 bit immediateShifts the source register to the left by the immediate value then stores it in the destination register5sll $t0, $t1, 0x4
srldestination registersource register8 bit immediateShifts the source register to the right by the immediate value then store the value in the destination register.Pseudosrl $t0, $t1, 0x4
Register Manipulation/Memory Instructions
luidestination register8 bit immediate valueN/ALoads the specified value into the upper 8 bits of a register without altering any other bits.3lui $t0, 0x12
llidestination register8 bit immediate valueN/ALoads the specified value into the lower 8 bits of a register without altering any other bits.4lli $t0, 0x34
lidestination register16 bit immediate valueN/ALoads the immediate value into the destination register.Pseudoli $t0, 0x1234
lwdestination registeraddress register4 bit immediate valueLoads the value at the specified address plus offset from memory into the specified register.12lw $t0, 0x2($t1)
ladestination registerLabelN/ALoad the address of the specified Label into the destination register.Pseudola label
swsource registeraddress register4 bit immediate valueStore the value in the specified register to the specifed address in memory plus offset.13sw $t0, -0x2($t1)
aspgeneral registerWrite Flagspecial registerReads the value from the special purpose register into the general register if the write flag is set to zero or writes the value in the general purpose register into the special purpose register if the write flag is set to one.15asp $t0, 1 , $disp0
wraspgeneral registerspecial registerN/AWrites the value in the general purpose register into the specified special purpose register.Pseudowrasp $t0, $disp0
reaspgeneral registerspecial registerN/AReads the value in the special purpose register into the specified general purpose register.Pseduoreasp $t0, $disp0
Branch Instructions
jLabelN/AN/AUnconditionally jumps to the specified Label.Pseudoj label
jspLabelN/AN/AIncrements the stack pointer, stores the next execution address at the top of the stack, and jumps to the specified label.Pseudojsp label
rspN/AN/AN/AReturns to the value at the top of the stack and decrements the stack pointerPseudorsp
bnesource registersource registerjump registerIf the source registers are not equal, then execution moves to the address specified in the jump register1bne $t0, $t1, $t2
bnelsource registersource registerLabelIf the source registers are not equal, jump to the specified label.Pseudoben $t0, $t1, label
beqsource registersource registerjump registerIf the source registers are equal, then continue execution at the address stored in the jump register0beq $t0, $t1, $t2
beqlsource registersource registerLabelIf the source registers are equal, jump to the specified label.Pseudobeq $t0, $t1, label
Logical Instructions
sltdestination registerleft source registerright source registerSets the destination register to 1 if the left source register is less than than the right register or to 0 otherwise.8slt $t0, $t1, $t2
sgtdestination registerleff source registerright source registerSets the destination register to 1 if the left source register is greater than then right source register or to 0 otherwise.Pseudosgt $t0, $t1, $t2
Notes: All opcodes are represented in machine code as 4-bit numbers. All general registers are represented as 4-bit numbers. Special registers are 7-bits in length. The write flag specified in asp is 1 bit. Unless otherwise specifed, all 'source' and 'destination' registers are general registers.

Pseudo Instruction Implementations

sub $t0, $t1, $t2
 neg $as0, $t2
 add $t0, $t1, $as0
 
ori $t0, $t1, 0x00
 lui $as0, 0x0  # Lower half of immediate value
 lli $as0, 0x0  # Upper half of immediate value
 or  $t0, $t1, $as0
 
srl $t0, $t1, 0x1
 ssl $t0, $t1, 0x-1
 
li $t0, 0x12
 lui $as0, 0x1
 lli $as0, 0x2
 or $t0, $as0, $0
 
la $t0, label
 lui $as0, 0x0	# (First half of address computed by compiler)
 lli $as0, 0x0  # (Second half of address computed by compiler)
 or $t0, $as0, $0
 
wrasp $t0, $disp0
 asp $t0, 0, $disp0
 
reasp $t0, $disp0
 asp $t0, 1, $disp0
 
jsp label
 lui $as0, 0x0 # (First half of address computed by assembler)
 lli $as0, 0x0 # (Second half of address computer by assembler)
 add $sp, $sp, $1
 add $sp, $sp, $1
 or $as1, $0, $0
 lli $as1, 0x6
 add $as1, $pc, $as1
 sw $as1, 0($sp)
 bne $0, $1, $as0
 
rsp
 neg $as0, $1
 add $as0, $as0, $as0
 add $sp, $sp, $as0
 lw $as0, 2($sp)
 bne $0, $1, $as0
 
j label
 lui $as0, 0x0 # (First half of address computed by assembler)
 lli $as0, 0x0 # (Second half of address computer by assembler)
 bne $0, $1, $as0
 
bne $t0, $t1, label
 lui $as0, 0x0 # (First half of address computed by assembler)
 lli $as0, 0x0 # (Second half of address computer by assembler)
 bne $t0, $t1, $as0
 
beq $t0, $t1, label
 
 lui $as0, 0x0 # (First half of address computed by assembler)  
 lli $as0, 0x0 # (Second half of address computer by assembler)   
 beq $t0, $t1, $as0    
 
sgt $t0, $t1, $t2
 slt $t0, $t2, $t1
 


Machine Language Specification:


When designing an assembler for the Mach 5 architecture, the translation of assembly language instructions into machine code is straightforward. Each non-pseudo instruction is 16 bits wide. The first 4 bits of this number are the "Operation number" which is specified in the table above. The remaining 14 bits are the parameters, listed in the same order as above.

Example

 Assembly Instruction:	add	$t0, $t1, $t2
 Machine  Instruction:  1010 0011 0100 0101 
 

 Assembly Instruction:	lui	$t0, 0x23
 Machine  Instruction:  0011 0011 0010 0011
 

 Assembly Instruction:  neg     $t0, $t1
 Machine  Instruction:  0010 0011 0100 0000 
 


Register Specification:

General Purpose

Register NameRegister NumberPerferred Use
$zero0Always contains the value 0. Cannot be changed.
$one1Always contains the value 1. Cannot be changed.
$as02Reserved for assembler use
$as13Reserved for assembler use
$as24Reserved for assembler use
$as35Reserved for assembler use
$t06Volitile Storage
$t17Volitile Storage
$t28Volitile Storage
$t39Volitile Storage
$t410Volitile Storage
$t511Volitile Storage
$f012Storage space for arguments and return values from 'function' calls.
$f113Storage space for arguments and return values from 'function' calls.
$pc14Holds the address of the next instrcution to be executed
$sp15The pointer to the next operation

Special Purpose

Register NameRegister NumberUsage
$disp00Holds the value displayed onto the first LED Display
$disp11Holds the value displayed onto the second LED Display
$disp22Holds the value displayed onto the third LED Display
$disp33Holds the value displayed onto the fourth LED Display
 4RESERVED
$sw05Holds the values of the switch input
 6RESERVED
 7RESERVED
$s0050Storage which is consistent across function calls
$s0151Storage which is consistent across function calls
$s0252Storage which is consistent across function calls
$s0353Storage which is consistent across function calls
$s0454Storage which is consistent across function calls
$s0555Storage which is consistent across function calls
$s0656Storage which is consistent across function calls
$s0757Storage which is consistent across function calls
$s0858Storage which is consistent across function calls
$s0959Storage which is consistent across function calls
$s1060Storage which is consistent across function calls
$s1161Storage which is consistent across function calls
$s1262Storage which is consistent across function calls
$s1363Storage which is consistent across function calls
$s1464Storage which is consistent across function calls
$s1565Storage which is consistent across function calls
$s1666Storage which is consistent across function calls
$s1767Storage which is consistent across function calls
$s1868Storage which is consistent across function calls
$s1969Storage which is consistent across function calls
$s2070Storage which is consistent across function calls
$s2171Storage which is consistent across function calls
$s2272Storage which is consistent across function calls
$s2373Storage which is consistent across function calls
$s2474Storage which is consistent across function calls
$s2575Storage which is consistent across function calls
$s2676Storage which is consistent across function calls
$s2777Storage which is consistent across function calls
$s2878Storage which is consistent across function calls
$s2979Storage which is consistent across function calls
$s3080Storage which is consistent across function calls


Sample Programs:

Euclid's Algorithm binary
Volume of a Rectangular Prism binary