CSE230 Assignment 1 Solved

30.00 $

Category:

Description

5/5 - (5 votes)

You are required to turn in the following source file: assignment1c.s

Objectives:

This assignment is for you to become familiar with the QTSpim simulator that we will be using in this course. You can use a machine in BYENG 214 (a computer lab) or install the QTSpim into your own computer, by downloading from:

https://canvas.asu.edu/courses/56799/pages/assignment1-due-wednesday-august-26th-5pm?module_item_id=3410168 1/8

8/20/2020 Assignment1 – Due: Wednesday, August 26th, 5pm: CSE 230: Computer Org/Assemb Lang Prog (2020 Fall)

http://sourceforge.net/projects/spimsimulator/files/ (http://sourceforge.net/projects/spimsimulator/files/)

You will edit an assembly language program, load it in the QTSpim, execute it, and step through the program.

Important Note: Your submitted assignment will be tested using SPIM, therefore you should test your program using SPIM before its submission.

—————————————

Assignment Description:

1. Load the QTSpim program. You can also use other SPIM and you will have a similar, but slightly different interface. You will see the windows looking as follows:

https://canvas.asu.edu/courses/56799/pages/assignment1-due-wednesday-august-26th-5pm?module_item_id=3410168 2/8

8/20/2020 Assignment1 – Due: Wednesday, August 26th, 5pm: CSE 230: Computer Org/Assemb Lang Prog (2020 Fall)

https://canvas.asu.edu/courses/56799/pages/assignment1-due-wednesday-august-26th-5pm?module_item_id=3410168 3/8

8/20/2020 Assignment1 – Due: Wednesday, August 26th, 5pm: CSE 230: Computer Org/Assemb Lang Prog (2020 Fall)

If the console window is not visible, then select Window -> Console from the menu in the QTSpim. The console window should be empty.

The QTSpim window is divided into some sections. The left section under Int Regs is the registers section. Registers are storage areas internal to the CPU. They are identified by notations such as $r0-$r31. In QTSpim, registers are 32-bits wide, meaning that they can store a 32-bit value. (Note that there are Int Regs to store integers, and FP Regs to store floating point numbers. We will discuss floating point numbers later in the semester.)

The right section under the tab Text is the text segment. This is where the assembly/machine language code you are executing is displayed. On the left hand side you see values such as [00400000]. These are memory addresses. The simulator begins executing code at 00400000 by default. The next column is the 32-bit machine language instruction stored at that address. It is displayed in hex. The next column is the assembly language statement that corresponds to that 32-bit machine language instruction. The next column (with the 😉 is an alternative representation of the statement in column three.

The right section under the tab Data is the data segment. Any data used by your program is stored here. The first column displays a memory address (or range) and the columns display the data stored there.

https://canvas.asu.edu/courses/56799/pages/assignment1-due-wednesday-august-26th-5pm?module_item_id=3410168 4/8

8/20/2020 Assignment1 – Due: Wednesday, August 26th, 5pm: CSE 230: Computer Org/Assemb Lang Prog (2020 Fall)

2. Minimize the QTSpim window. Then using your favorite text editor (such as NotePad, TextPad, note that TextEdit for Mac is not a good choice since it deals with non-ascii characters, you will need a simple text editor where you can write code), type the following program and save it within the file name assignment1.s (i.e., with a .s extension).

Anything written right side of ‘#’ will be a comment just like “//” in Java or C++.
It is case-sensitive (upper case and lower case make differences.)

Put your name and other information at the top of the file:

###########################################################
#
#
#
#
#
#
###########################################################

Assignment #: 1
Name: Your name
ASU email: Your ASU email
Course: CSE/EEE230, your lecture time such as MWF 1:30pm Description: This is my first assembly language program.

la
li syscall jr

$a0, message1 # $a0 = address of message1

It prints “Hello world”.

#data declarations: declare variable names used in program, storage allocated in RAM

.data
message1: .asciiz “Hello world.\n” #create a string containing “Hello world.\n”

#program code is contained below under .text

.text
.globl main #define a global function main

# the program begins execution at main()

main:

$v0, 4 $ra

# $v0 = 4 — this is to call print_string() # call print_string()

# return

Note:

https://canvas.asu.edu/courses/56799/pages/assignment1-due-wednesday-august-26th-5pm?module_item_id=3410168 5/8

8/20/2020 Assignment1 – Due: Wednesday, August 26th, 5pm: CSE 230: Computer Org/Assemb Lang Prog (2020 Fall)

li — “load immediate” la — “load address”:

la $t0, var1 # copy RAM address of var1 into register $t0 jr — “jump register”:

jr $ra # jump to the address contained in $ra

3. Once you have typed in the program and saved it, switch back to the QTSpim window and load the program by clicking File -> Load File on the menu bar, and navigating to the location where you saved the file. If your program contains syntax errors, the QTSpim will display the line with the error. If that is the case, you need to go back to the editor window and correct the error and re-save the program. Continue doing this until QTSpim load the program without errors

To execute the program, select Simulator -> Run/Continue (or press the F5 key). You should see “Hello world.” displayed in the console window if it is running successfully. You just wrote and executed your first assembly language program!!

4. You can also execute the program by selecting Simulator -> Single Step. This executes one line in the loaded assembly program at a time, and this can be used to debug if it is not producing a correct result.
The program that you have just written has a line using syscall The syscall instruction stands for system call, i.e., it allows the assembly language program to invoke a call to the QTSpim simulator operating system (in a real computer this would be a call the underlying operating system such as Windows or Linux). Various system calls can be used to request the QTSpim simulator to perform various functions. Here are some of them:

System Call Number

System Call Operation

System Call Description

$v0 = 1; $a0 = int to be printed
$v0 = 4; $a0 = address of beginning of ASCIIZ string

$v0 = 5; user types int at keyboard; value is stored $v0 = 8; user types string at keybd; addr of

1
4
5
in $v0
8
beginning of string is stored in $a0; len in $a1

print_int print_string read_int

read_string

https://canvas.asu.edu/courses/56799/pages/assignment1-due-wednesday-august-26th-5pm?module_item_id=3410168 6/8

8/20/2020 Assignment1 – Due: Wednesday, August 26th, 5pm: CSE 230: Computer Org/Assemb Lang Prog (2020 Fall)

  1. 10  exit
  2. 11  print_char
  3. 12  read_char

stored in $v0

$v0 = 10; terminates the program $v0 = 11; $a0 = char to be printed

$v0 = 12; user types char at keyboard; value is

We are invoking system call number 4 (print_string). Note that the second instruction of the program, li $v0, 4 puts the value 4 in the $v0 register (i.e., the $r2 register). The second instruction, la, $a0, message1, loads the address of the beginning of our message1 string (“Hello world”) into the $a0 register (i.e., the $r4 register). This is what is expected by the print_string system call. (Incidentally, you can think of the system call as a function call with the input parameters being stored in registers; if the function returns values, those values will be store in registers as well.)

5. Modify the program to display the string “Goodbye World.\n” Instead of “Hello world.\n”. Save this program as assignment1b.s. Be sure to update the program header block. Re-run the program in QTSpim and verify the correct string is displayed.

NOTE: Once you have uploaded a program successfully before, then when you upload a program again, you will need to choose File -> Reinitialize and Load File (instead of Load File) to ignore any main function definition that you have uploaded before. (You can also use Simulator -> Reinitialize Simulator first before loading).

6. If we want to display multiple strings, we can invoke the print_string system call multiple times, once with the address of the beginning of the first string in $a0, and another time with the address of the beginning of another string in $a0 again.
Modify your program to display the following three texts in the console window on separate lines. Update the program header block, save this program as assignment1c.s, and run it.

Hello World.
Goodbye World.
This is my first MIPS program.

  • assn1-cirsvz.zip