DO NOT USE LI , LA OR PSEUDO INSTRUCTIONS PLEASE.. This assignment is designed t
ID: 3881214 • Letter: D
Question
DO NOT USE LI , LA OR PSEUDO INSTRUCTIONS PLEASE..
This assignment is designed to introduce you to the MIPS assembly language, using registers and memory, input/output syscalls and the MIPS simulator.
VERY IMPORTANT: You are restricted to the core instructions for this assignment. DO NOT use any pseudo or extended instructions. This means you must use the standard formats and no use of li or la instructions.
a. Open the text editor and type in the following. Then save your work as assign1.asm
.data
val1: .word 0
val2: .word 0
val3: .word 0
.text
.globl main
main:
b. Add the following zero terminated ascii strings to the data segment after the three words.
1. Your name
2. “Enter a number “ 3. A new line (“ ”)
c. Add the MIPS assembly language instructions after the main for the following steps. You must show each step in the order given. Each step may require multiple instructions. Note that the variables val1, val2, and val3 represent addresses or locations in memory in the data segment. Use other registers as needed.
DO NOT USE LI, LA OR PSEUDO INSTRUCTIONS
Steps:
1. Initialize the register $s0 to 19
2. Prompt the user to enter an integer and then read the integer into register $s1 3. Prompt the user to enter an integer and read the number into register $s2
4. Store the value in $s1 into the memory labeled “val1”
5. Store the value in $s2 into the memory labeled “val2”
6. Calculate the value of $s0 - $s1 + $s2 and store the result in the memory labeled “val3” 7. Print the following output each on its own line
a. Your name
b. The value in val1 c. The value in val2 d. The value in val3
8. Exchange or swap the values in $s1 and $s2 9. Set the value in $s0 to –$s0
10. Print the values finally in $s0, $s1 and $s2
- DONT USE LI, LA OR PSEUDO INSTRUCTIONS
Specifics:
Use only the instructions covered to date.
Stop the program by using a syscall with the command 10.
Test
Documentation:
Comment the beginning of your programs with your name, class ID, and assignment number.
Comment every instruction.
Explanation / Answer
Code:
.data
val1: .word 0
val2: .word 0
val3: .word 0
string: .asciiz "Enter a number "
newline: .asciiz " "
name: .asciiz "Your name"
.text
.globl main
main:
addiu $s0, $0, 19 #initialise $s0 to 19
addiu $v0, $0, 4 # set v0 to 4, for string output
lui $at, 0x1001 #load upper 16 bits to base address of data segment
ori $a0, $at, 12 #or it with offset 12 of data segment or string and store in a0
#set a0 to address of string
syscall #perform system call
#read integer from user
addiu $v0, $0, 5 # set v0 to 5, for reading integer
syscall #perform system call
addu $s1, $0, $v0 #store integer read in $s1
#prompt user for integer
addiu $v0, $0, 4 # set v0 to 4, for string output
lui $at, 0x1001 #load upper 16 bits to base address of data segment
ori $a0, $at, 12 #or it with offset 12 of data segment or string and store in a0
#set a0 to address of string
syscall #perform system call
#read from user
addiu $v0, $0, 5 # set v0 to 5, for reading integer
syscall #perform system call
addu $s2, $0, $v0 #store integer read in $s2
lui $at, 0x1001 #load upper 16 bits to base address of data segment
sw $s1, 0($at) #store s1 to offset 0 of data segment or val1
lui $at, 0x1001 #load upper 16 bits to base address of data segment
sw $s2, 4($at) #store s2 to offset 4 of data segment or val2
#calculate s0-s1+s2
sub $t0,$s0,$s1 #calculate s0 - s1 and store it in t0
add $t0,$t0,$s2 ##calculate t0 + s2 and store it in t0
lui $at, 0x1001 #load upper 16 bits to base address of data segment
sw $t0, 8($at) #store t0 to offset 8 of data segment or val3
#print name and newline
addiu $v0, $0, 4 # set v0 to 4, for string output
lui $at, 0x1001 #load upper 16 bits to base address of data segment
ori $a0, $at, 30 #or it with offset 30 of data segment or name and store in a0
syscall #perform system call
addiu $v0, $0, 4 # set v0 to 4, for string output
lui $at, 0x1001 #load upper 16 bits to base address of data segment
ori $a0, $at, 28 #or it with offset 28 of data segment or newline and store in a0
syscall #perform system call
#print val1 and newline
addiu $v0, $0, 1 # set v0 to 1, for integer output
lui $at, 0x1001 #load upper 16 bits to base address of data segment
lw $a0, 0($at) #load offset 0 of data segment or val1 into a0
syscall #perform system call
addiu $v0, $0, 4 # set v0 to 4, for string output
lui $at, 0x1001 #load upper 16 bits to base address of data segment
ori $a0, $at, 28 #or it with offset 28 of data segment or newline and store in a0
syscall #perform system call
#print val2 and newline
addiu $v0, $0, 1 # set v0 to 1, for integer output
lui $at, 0x1001 #load upper 16 bits to base address of data segment
lw $a0, 4($at) #load offset 4 of data segment or val2 into a0
syscall #perform system call
addiu $v0, $0, 4 # set v0 to 4, for string output
lui $at, 0x1001 #load upper 16 bits to base address of data segment
ori $a0, $at, 28 #or it with offset 28 of data segment or newline and store in a0
syscall #perform system call
#print val3 and newline
addiu $v0, $0, 1 # set v0 to 1, for integer output
lui $at, 0x1001 #load upper 16 bits to base address of data segment
lw $a0, 8($at) #load offset 8 of data segment or val3 into a0
syscall #perform system call
addiu $v0, $0, 4 # set v0 to 4, for string output
lui $at, 0x1001 #load upper 16 bits to base address of data segment
ori $a0, $at, 28 #or it with offset 28 of data segment or newline and store in a0
syscall #perform system call
#swap s1 and s2
addu $t0, $0, $s1 #move $t0, $s1
addu $s1, $0, $s2 #move $s1, $s2
addu $s2, $0, $t0 #move $s2, $t0
#negate s0
sub $s0,$0,$s0
#print s0 and newline
addiu $v0, $0, 1 # set v0 to 1, for integer output
addu $a0, $0, $s0 #move $s0 into $a0
syscall #perform system call
addiu $v0, $0, 4 # set v0 to 4, for string output
lui $at, 0x1001 #load upper 16 bits to base address of data segment
ori $a0, $at, 28 #or it with offset 28 of data segment or newline and store in a0
syscall #perform system call
#print s1 and newline
addiu $v0, $0, 1 # set v0 to 1, for integer output
addu $a0, $0, $s1 #move $s1 into $a0
syscall #perform system call
addiu $v0, $0, 4 # set v0 to 4, for string output
lui $at, 0x1001 #load upper 16 bits to base address of data segment
ori $a0, $at, 28 #or it with offset 28 of data segment or newline and store in a0
syscall #perform system call
#print s2 and newline
addiu $v0, $0, 1 # set v0 to 1, for integer output
addu $a0, $0, $s2 #move $s2 into $a0
syscall #perform system call
addiu $v0, $0, 4 # set v0 to 4, for string output
lui $at, 0x1001 #load upper 16 bits to base address of data segment
ori $a0, $at, 28 #or it with offset 28 of data segment or newline and store in a0
syscall #perform system call
#exit with syscall
addiu $v0, $0, 10 # set v0 to 4, for exiting the program
syscall #perform system call
Output:
Enter a number 5
Enter a number 10
Your name
5
10
24
-19
10
5
-- program is finished running --
Hope this helps. Do Upvote! :)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.