Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
.
  • Loading branch information
cag-uconn committed Aug 29, 2023
1 parent b124ca3 commit 7c8beca
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 43 deletions.
4 changes: 2 additions & 2 deletions pa0/README.md
@@ -1,7 +1,7 @@
MIPS Simulator
RISC-V Simulator
==============

A simulator for the MIPS like Instruction Set, that translates machine code created from the assembler, and then executes the machine instructions. Each instruction goes through a Fetch, Decode, Execute, Memory and Writeback stage of processing.
A simulator for the RISC-V like instruction set, that translates machine code created from the assembler, and then executes the machine instructions. Each instruction goes through a Fetch, Decode, Execute, Memory and Writeback stage of processing.

# Build
$ make
Expand Down
10 changes: 5 additions & 5 deletions pa0/nop.asm
@@ -1,7 +1,7 @@
.text
sll $zero $zero, 0 # execute NOOP ... done
.text
addi x0, x0, 0 # Do nothing

.data
2048: .word 10
2049: .word 32

2048: .word 4302 # Welcome
2049: .word 5402 # to
2050: .word 2023 # CompArch
71 changes: 35 additions & 36 deletions pa0/simulator.c
Expand Up @@ -6,7 +6,7 @@
#include <stdio.h>
#include <string.h>
#include "simulator.h"
#include "mipsInstructionMap.h"
#include "instruction_map.h"

int debug = 0;

Expand Down Expand Up @@ -55,7 +55,7 @@ void process_instructions() {
while(terminate != 1)
{
// set terminate flag when SLL $0, $0, 0 (aka NOOP) is executed
if (memory[pc/4] == 0)
if (memory[pc/4] == nop)
terminate = 1;

//Fetch Instruction
Expand Down Expand Up @@ -121,40 +121,39 @@ void write_back_stage(struct Registers mem_out)
// Output reigsters
void rdump()
{
printf("$0 $zero 0x%08x\n", registers[0]);
printf("$1 $at 0x%08x\n", registers[1]);
printf("$2 $v0 0x%08x\n", registers[2]);
printf("$3 $v1 0x%08x\n", registers[3]);
printf("$4 $a0 0x%08x\n", registers[4]);
printf("$5 $a1 0x%08x\n", registers[5]);
printf("$6 $a2 0x%08x\n", registers[6]);
printf("$7 $a3 0x%08x\n", registers[7]);
printf("$8 $t0 0x%08x\n", registers[8]);
printf("$9 $t1 0x%08x\n", registers[9]);
printf("$10 $t2 0x%08x\n", registers[10]);
printf("$11 $t3 0x%08x\n", registers[11]);
printf("$12 $t4 0x%08x\n", registers[12]);
printf("$13 $t5 0x%08x\n", registers[13]);
printf("$14 $t6 0x%08x\n", registers[14]);
printf("$15 $t7 0x%08x\n", registers[15]);
printf("$16 $s0 0x%08x\n", registers[16]);
printf("$17 $s1 0x%08x\n", registers[17]);
printf("$18 $s2 0x%08x\n", registers[18]);
printf("$19 $s3 0x%08x\n", registers[19]);
printf("$20 $s4 0x%08x\n", registers[20]);
printf("$21 $s5 0x%08x\n", registers[21]);
printf("$22 $s6 0x%08x\n", registers[22]);
printf("$23 $s7 0x%08x\n", registers[23]);
printf("$24 $t8 0x%08x\n", registers[24]);
printf("$25 $t9 0x%08x\n", registers[25]);
printf("$26 $k0 0x%08x\n", registers[26]);
printf("$27 $k1 0x%08x\n", registers[27]);
printf("$28 $gp 0x%08x\n", registers[28]);
printf("$29 $sp 0x%08x\n", registers[29]);
printf("$30 $fp 0x%08x\n", registers[30]);
printf("$31 $ra 0x%08x\n", registers[31]);

printf(" --> pc 0x%08x\n", pc);
printf("x0 zero 0x%08x\n", registers[0]);
printf("x1 ra 0x%08x\n", registers[1]);
printf("x2 sp 0x%08x\n", registers[2]);
printf("x3 gp 0x%08x\n", registers[3]);
printf("x4 tp 0x%08x\n", registers[4]);
printf("x5 t0 0x%08x\n", registers[5]);
printf("x6 t1 0x%08x\n", registers[6]);
printf("x7 t2 0x%08x\n", registers[7]);
printf("x8 s0 0x%08x\n", registers[8]);
printf("x9 s1 0x%08x\n", registers[9]);
printf("x10 a0 0x%08x\n", registers[10]);
printf("x11 a1 0x%08x\n", registers[11]);
printf("x12 a2 0x%08x\n", registers[12]);
printf("x13 a3 0x%08x\n", registers[13]);
printf("x14 a4 0x%08x\n", registers[14]);
printf("x15 a5 0x%08x\n", registers[15]);
printf("x16 a6 0x%08x\n", registers[16]);
printf("x17 a7 0x%08x\n", registers[17]);
printf("x18 s2 0x%08x\n", registers[18]);
printf("x19 s3 0x%08x\n", registers[19]);
printf("x20 s4 0x%08x\n", registers[20]);
printf("x21 s5 0x%08x\n", registers[21]);
printf("x22 s6 0x%08x\n", registers[22]);
printf("x23 s7 0x%08x\n", registers[23]);
printf("x24 s8 0x%08x\n", registers[24]);
printf("x25 s9 0x%08x\n", registers[25]);
printf("x26 s10 0x%08x\n", registers[26]);
printf("x27 s11 0x%08x\n", registers[27]);
printf("x28 t3 0x%08x\n", registers[28]);
printf("x29 t4 0x%08x\n", registers[29]);
printf("x30 t5 0x%08x\n", registers[30]);
printf("x31 t6 0x%08x\n", registers[31]);
printf(" --> pc 0x%08x\n", pc);
}

// Output Memory
Expand Down
2 changes: 2 additions & 0 deletions pa0/simulator.h
Expand Up @@ -8,6 +8,8 @@
* 25/07/19
*/

#define nop 0x00000013

#ifndef SIMULATOR_H_
#define SIMULATOR_H_

Expand Down

0 comments on commit 7c8beca

Please sign in to comment.