Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MIPS Programming Exercise You may turn off branch and load delays for this program. It will make it considerably simpler. Be sure to turn on

MIPS Programming Exercise

You may turn off branch and load delays for this program. It will make it considerably simpler. Be sure to turn on memory-mapped I/O. You should base this on the example program memmapIO.asm. Make sure you fully understand what it is doing before you start programming. You may not use syscall for input, because the program would then block on the input. Instead, use a polling input routine catch input. You must do ALL input and output through the memory-mapped input/output ports, NOT through syscall. Write a program that starts with two arrays of characters (.asciiz strings), of equal length (at least 40 characters), labeled 'source' and 'display'. Initially, the source array contains a character string with a ' ' before the terminating NUL. Start your program by copying the source array into the display array. Use a little subroutine to do this, passing in the bases of the two blocks of memory. Then loop forever, polling the input and output ports to see if the devices are ready to accept a character (output) or give you a character (input). If the output device is ready, display the next character in the display string. If you reach the terminating NUL (or, you just printed the ' '), start over at the beginning. If the input device has a character ready, get it and process it according to these rules: 's': sort the display array using any easy sort routine (bubble or ripple is fine). Do not sort the ' ' in with the rest of the characters. 't': toggle the case of every alphabetic character (for example, 'T' becomes 't', 't' becomes 'T' and all non-alphabetic characters stay unchanged). 'a': replace the display array elements with the source elements once again. 'r': reverse the elements in the display array. Do not reverse the ' ' to the front! 'q': terminate program execution gracefully, using syscall 10. Ignore any other input characters. Note: the line being displayed could change mid-line, since input can come in at any point. You will want to code delay loops in the program to keep the output lines from flying down the screen.

Here is the code for memmapIO.asm:

# # memmapIO.asm # # MIPS example program # Illustrate polling and memory-mapped IO # turn on memory-mapped IO, load/branch delays, pseudoinstructions. # Turn off load exception handler. # .text .globl main main: la $a0, pMsg # prompt for a string jal printIt # without syscall nop la $a0, str # address of input buffer jal readIt nop la $a0, rMsg # print the string jal printIt # again, without syscall nop la $a0, str jal printIt nop li $v0, 10 syscall # read routine using simplest calling convention, w/buffer address in $a0 readIt: li $a3, 0xffff0000 # base of memory-mapped IO area rloop: lw $t1,($a3) nop andi $t1, $t1, 0x0001 # mask off ready bit beqz $t1, rloop nop lw $t0, 4($a3) # extract character (as a word) nop sb $t0, ($a0) # put into buffer nop li $t2, 0x0a beq $t0, $t2, rexit # if we just read the ' ' byte, exit nop addiu $a0, $a0, 1 # advance to next byte j rloop # otherwise try again nop rexit: li $t2, 0 addiu $a0, $a0, 1 sb $t2, ($a0) # add terminating NUL to C-string jr $ra nop # print routine using simplest calling convention, string address in $a0 printIt: li $a3, 0xffff0000 # base of memory-mapped IO area ploop: lw $t1, 8($a3) # extract transmitter control nop andi $t1, $t1, 0x0001 # mask off ready bit beqz $t1, ploop nop lb $t0, ($a0) # extract next character nop beqz $t0, pexit # find the 0 byte? Yes == exit nop sw $t0, 12($a3) # write character to display addiu $a0, $a0, 1 # advance to next character j ploop # and try again nop pexit: jr $ra nop .data pMsg: .asciiz "Enter a string (nothing will appear on screen) " rMsg: .asciiz "You entered " str: .space 200 # room for user's enrty

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_2

Step: 3

blur-text-image_step3

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

More Books

Students also viewed these Databases questions