Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USING MIPS Simulator Write a assembly program that repeatedly asks the user for a string and then calculates and prints out the string length. Stop

USING MIPS Simulator

Write a assembly program that repeatedly asks the user for a string and then calculates and prints out the string length. Stop the program when the string is empty (when the user hits "enter" without anything else on the line.)

Be sure to reserve enough memory in the .data for the string. Use indexed addressing to scan through the string. Strings read in with the trap handler service include a ' ' character at the end, followed by the null termination. Don't count the ' ' or the null as part of the string length.

Use the below given code and complete the assembly program:

.text

.globl main

main:

top: li $t0,0

# get string

li $v0,4 # print prompt

la $a0,prompt

syscall

li $v0,8 # code 8 == read string

la $a0,string # $a0 == address of buffer

li $a1,24 # $a1 == buffer length

syscall # Invoke the operating system.

li $t1,0 # read first character from string

lb $v0,string($t1) # $v0 = string[$t1]

beq $v0,10,exit # if character is ' ' jump to exit

# test code

# print the string

li $v0,4 # print prompt2

la $a0,prompt2 #

syscall

li $v0,4 # print body

la $a0,string #

syscall

j top

exit: li $v0,4 # print prompt2

la $a0,EndMessage #

syscall

li $v0,10 # exit

syscall

.data

prompt: .asciiz "please enter a string: "

string: .space 128

prompt2: .asciiz "the string you entered was: "

EndMessage: .asciiz "empty string entered"

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Entity Alignment Concepts Recent Advances And Novel Approaches

Authors: Xiang Zhao ,Weixin Zeng ,Jiuyang Tang

1st Edition

9819942527, 978-9819942527

More Books

Students also viewed these Databases questions

Question

Answered: 1 week ago

Answered: 1 week ago