This project involves designing and implementing a custom assembler and simulator for a 16-bit Instruction Set Architecture (ISA), undertaken by groups of three students. The ISA features a comprehensive set of instructions, encompassing arithmetic operations, data movement, and control flow, to facilitate a wide range of computational tasks.
The assembler translates assembly language instructions into machine code, with rigorous error checking against syntax and logical errors. It handles labels, variables, and ensures adherence to the ISA's specifications, including the proper use of registers, immediate values, and memory addresses.
The simulator executes the binary code generated by the assembler, simulating the specified behaviors of the ISA. It provides insights into the program's execution by simulating the effects on memory, registers, and the FLAGS register.
The project extends to support simple floating-point arithmetic and includes bonus challenges for memory access trace visualization and enhanced memory organization, offering a deeper dive into computer organization principles.
The ISA for this project is a 16-bit architecture supporting various instructions across six encoding types. It features arithmetic operations, data movement, control flow changes, and special operations.
- Registers: Seven general-purpose registers (R0-R6) and a FLAGS register.
- Memory: 8-bit address space, totaling 512 bytes.
- 7 General Purpose Registers: R0 to R6
- 1 FLAGS Register
- 8-bit addressable, leading to a total space of 512 bytes.
add, sub, mul, div
: Perform arithmetic operations on register contents.
mov
: Transfer data between registers or from an immediate value to a register.
jmp, jlt, jgt, je
: Conditional and unconditional jumps based on flag conditions.
hlt
: Halts execution.
- Syntax:
add reg1 reg2 reg3
- Semantics: Performs
reg3 = reg1 + reg2
. Sets overflow flag if necessary.
- Syntax:
sub reg1 reg2 reg3
- Semantics: Performs
reg3 = reg1 - reg2
. Zeroesreg3
and sets overflow ifreg2 > reg1
.
- Syntax:
mov reg1 $Imm
- Semantics: Loads immediate value
$Imm
intoreg1
.
- Syntax:
mov reg1 reg2
- Semantics: Transfers the contents of
reg1
toreg2
.
- Syntax:
ld reg1 mem_addr
,st reg1 mem_addr
- Semantics: Load or store data between a register and a memory address.
- Syntax:
mul reg1 reg2 reg3
- Semantics:
reg3 = reg1 * reg2
. Sets overflow flag if necessary.
- Syntax:
div reg1 reg2
- Semantics: Divides
reg1
byreg2
, storing the quotient and remainder in specified registers.
- Includes
xor
,or
,and
, each performing bitwise operations on registers.
rs
,ls
: Shifts register contents right or left by an immediate value.
- Syntax:
cmp reg1 reg2
- Semantics: Compares
reg1
andreg2
, updating FLAGS accordingly.
- Conditional jumps (
jlt
,jgt
,je
) based on FLAGS.
- Syntax:
hlt
- Semantics: Halts execution.
Instructions include:
- Arithmetic Operations:
add
,sub
,mul
,div
- Data Movement:
mov
- Control Flow:
jmp
,jlt
,jgt
,je
- Special Operations:
hlt
- Type A: 3 register operations (e.g.,
add reg1 reg2 reg3
) - Type B: register and immediate operations (e.g.,
mov reg1 $Imm
) - Type C: 2 register operations (e.g.,
mov reg1 reg2
) - Type D & E: memory operations (e.g.,
ld reg1 mem_addr
,st reg1 mem_addr
) - Type F: halt (e.g.,
hlt
)
Support for floating-point operations in an 8-bit format is included, enhancing the assembler and simulator's capabilities.