Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

One of the best ways to understand how computers works at a basic level is to wr

ID: 3808180 • Letter: O

Question

One of the best ways to understand how computers works at a basic level is to write a simulator. This will force you to look at the fetch-execute cycle at a deeper level than just using a simulator or talking about how processors work. In this assignment, you will write a simulator that can load and run full MIPS programs (similar to, but more basic than SPIM or MARS). The simulator should run on the command line and take as input a text file. You may use whatever language you wish to program the simulator.

----------------------

Write an original program of your own in C. Translate it to MIPS assembly by hand, and convert it to an input file that will run in the simulator. You may use SPIM to help you do this, or do it by hand. Your program must print your name out when it starts. The program should not be trivial, but should be rather simple. An example of the scope I am looking for is something like this: “The program prints your name, and then asks the user to input a string. The program takes the input, reverses it, and prints it out.” Of course, your program must do something different.

Running Modes

Your simulator must be able run in two different modes, Debug and Normal, that can be changed when you run the program (on the command line, for example). You are not required to change modes while the program is running.

In Normal mode, the program should run without printing any debug information, and should not pause between instructions. However, the program should print a message stating that it is a MIPS simulator written by you when it starts. The only other output should come from system calls. Also, you should not print anything during a system call unless it is one of the printing system calls.

In Debug mode, your program should once again print your name when it starts. It must print the PC and instruction in Hex as it executes, and require the user to hit a key, such as “Enter” to advance one instruction. You also need to provide commands to print out the contents of the registers in Hex or Decimal, or the value stored at a location in memory without advancing.

Explanation / Answer

C Program: write a program to add two numbers

#include<stdio.h>

int main()

{

   int a, b, c;

   printf("Enter two numbers to add ");

   scanf("%d%d",&a,&b);

   c = a + b;

   printf("the sum of entered numbers = %d ",c);

   return 0;

}

Output

Enter two number to add

4

5

Sum of entered numbers = 9

MIPS assembly: assembler

Text segment (all programs start with the next 3 lines)

        .text          
        .globl main

main:

# ------------- print prompt on "console" --------------------
        la      $a0, prompt     # address of prompt goes in
        li      $v0, 4          # service code for print string
        syscall

# ------------- read in the integer --------------------------
        li      $v0, 5          # service code
        syscall
        sw      $v0, Num1       # store what was entered
# -------------- read another
        li      $v0, 5          # service code
        syscall
        sw      $v0, Num2       # store what was entered

# ------ Perfrom the addition, $a0 := Num1 + Num2
        lw      $t0, Num1
        add     $a0, $t0, $v0

# ------ print the sum, it is in $a0
        li      $v0, 1          # print integer service call
        syscall

# ------ print a final string identifying the result, and ending with a new line
        la      $a0, final
        li      $v0, 4
        syscall

        li      $v0, 10         # exit program service
        syscall

#------------------------------------------------------------------
#       Data segment
#------------------------------------------------------------------
        .data
Num1:   .word   0
Num2:   .word   0
prompt: .ascii "Please type 2 integers, end each with the "
        .asciiz "Enter key: "
final: .asciiz " is the sum. "

#------ end of file ADDNUMS.ASM

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote