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

I\'m trying to learn the Assembly language MIPS using the MARS simulator. The pr

ID: 3666261 • Letter: I

Question

I'm trying to learn the Assembly language MIPS using the MARS simulator. The problem I'm currently working through is: Allocate space for an array A[0..15] in the data section of your assembly code. Each array element is a 32-bit word. Write a program that will do the following two things: (1) It will first fill the nth element of the array with the value of 2^n (calculate A[n] using the formula A[n]:=A[n-l]+A[n-l]). (2) It will then ask you to enter any integer value of n between 0 and 15, and out put the value of A[n].

Explanation / Answer

MARS: An Education-Oriented MIPS Assembly Language Simulator

INTRODUCTION The MIPS RISC architecture and corresponding assembly language use a limited number of instruction formats. Typical student programs may use register-to-register, load/store, branch, jump, system call, and floating-point instructions. Thirty-two general-purpose registers are available for integer operations (some have dedicated uses), as are thirty-two single-precision floating point registers. MIPS is a clean design with simple instructions, and is very popular in industry as well as academia.

Instructions not yet implemented in MARS include some pseudoinstructions and other instructions expected to be more of professional than educational interest. The MARS simulator operates under either GUI or command-line modes of operation. Students use primarily the GUI mode in either “go” or “single step” execution for assembly code creation and debugging. Instructors have the option of running the simulator from an OS shell or a batch command file, to facilitate execution of several test cases of all student’s programs in sequence for grading. Command-line arguments are used to request the output of particular registers or memory locations to verify program results. The MARS simulator is written in Java 1.4.2, using standard techniques of human-computer interaction via its Swing and AWT packages. Standard icons have been obtained from the Java look adn feel graphics repository.

2. MARS OPERATION Students will typically use MARS to compose an assembly language program using the editor, assemble it, then execute the assembled program all at once or step-by-step using the facilities of the execute pane. These operations are illustrated and described below. The MARS editor is an ASCII-oriented text editor that operates much like Window's Notepad. Figure 1 shows the active editing pane. The first two groups of toolbar icons are used with the editor. The first group corresponds to the File menu and includes file options such as New, Open, and Save. The second group corresponds to the Edit menu and includes operations such as Cut, Copy and Paste. Menu items and their corresponding toolbar buttons are enabled and disabled as appropriate. To assemble the program, the user selects Assemble from the Run menu or clicks the wrench toolbar icon. A successful assembly causes the Execute pane to come forward as shown in Figure 2. An unsuccessful assembly displays appropriate messages and line numbers in the console window at the bottom of the screen. The Execute pane contains several windows. The Text Segment window is front and center. It displays both the source and binary code of the assembly program, including the expansion of pseudoinstructions (the la and li instructions in Figure 2). A breakpoint can be set at any instruction using the check box in the leftmost column. When stepping through program execution manually or at reduced run speeds, the next instruction to be executed is highlighted. The Data Segment display illustrated at the bottom of Figure 2 shows the program's data storage area in a scrollable window. Its lower border contains icons to control display of memory contents at special locations such as the stack or heap, and check boxes to display memory addresses and values in either decimal or hexadecimal format. The contents of a memory word can be directly edited at any time by double-clicking on its cell and entering the desired value in either decimal or hexadecimal format. Symbol table information is displayed in the Labels window. This is relatively less important and the window may be closed to allow more space for the Text Segment display. Registers are permanently displayed to the right of the Execute pane in a vertically oriented window. This can be seen in the right side of Figure 1. As with memory, values are editable and display format is selectable. There are separate tabs for the general purpose registers, the floating point registers of Coprocessor 1 and the exception registers of Coprocessor 0.

Another permanent display is the console window on the lower portion of the screen. It includes two tabs, one for MARS messages such as assembly errors and another for runtime input and output generated by MIPS system calls. Each tab is activated when text is written to it.