Question
- Uses MIPs and must look like the output displayed below - I attempted #1 - 4 but i'm not sure if it's the correct
- Uses MIPs and must look like the output displayed below
- I attempted #1 - 4 but i'm not sure if it's the correct way to do it
------------
The steps for the code:
-
Print the string at label num to the screen as a string (use syscall) on its own line
-
Prompt the user (print to the screen) to enter a single lowercase letter using the label prompt (use a syscall). Error checking isnt necessary (assume that the user follows directions)
-
Read in the 1 character from the user (use syscall 12) and store the character (sb) into memory at label num. Save this character value in a saved temporary register for later use
-
Print a newline (label endl) to the screen. Print the label num to the screen as a string (use syscall) on its own line. Load the byte at address num + 2 into a temporary register (referred to as Reg A). Add 32 to Reg A and store it back into Reg and store the value back into memory at address num + 2. Print the string at label num to the screen as a string (use syscall) on its own line.
-
Load the word at the label num into a temporary register (referred to as Reg B). Shift Reg B right logical by 8 bits and store the value back into Reg B
-
Shift Reg A left by 3 bytes (24 bits) placing the result back into Reg A. Add the value of Reg A to Reg B and store the result of the operation as a word (sw) into memory at the label num
-
Print the label num to the screen as a string (use syscall) on its own line
-
Store byte the value of Register 0 (aka $0) into the address of (num + 4)
-
Print the label num to the screen as a string (use syscall) on its own line
-
Load the word of data stored at label num into a temporary register, Reg A
-
Rotate the value right 4 bits and store the result back into Reg A. Print the label num to the screen as a string (use syscall) on its own line
-
Store the modified value, Reg A, as a word into memory at the label num. Print the label num to the screen as a string (use syscall) on its own line
-
Rotate the value right 4 more bits. Store the modified value into memory at the label num. Print the label num to the screen as a string (use syscall) on its own line
-
Use the print string syscall to print the string starting at the label myspace on its own line
-
Load the word of data stored at label myspace into a temporary register, Reg A. Add the saved register, from instruction 3 to the value, replacing the value in Reg A. Store word the result back into memory at label myspace. Use the print string syscall with the label myspace on its own line again
-
Add 1 to Reg A and store the byte into memory at myspace + 1. Use the print syscall with the label myspace again
-
Print a newline and then quit the program
Code:
.globl main .text main:
# Your code goes here
#step 1 li $v0, 4 la $a0, num syscall #step 2 addi $v0, $0, 4 la $a0, prompt syscall li $v0, 8 syscall #step 3 li $v0, 12 sb $v0, 12($0) #idk if this is correct #step 4 li $v0, 4 la $a0, endl syscall li $v0, 4 la $a0, num syscall
.data prompt: .asciiz "Enter a lowercase letter: " endl: .asciiz " " .align 2 num: .word 0x44434241 myspace: .byte '#', 0x00, '@', '%' stop: .byte 0x00
Output:
Example expected MARS output [1/5/21 @ 10am - Labels added to help see which step produces which output] ABCD# Enter a lowercase letter: t tBCD# tBcD# BcDc# BcDc Step 1 Step 2 Step 4 First print Step 4 Second print Step 7 Step 9 Step 11 Step 12 Step 13 Step 14 Step 15 Step 16-17 BcDc 4F4& cDcB t tu@% program is finished running ABCD# Enter a lowercase letter: z ZBCD# zBcD# BcDc# BcDc BcDc 4F4& cDcB z z{@% program is finished runningStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started