代写 MIPS Programming Questions

Programming Questions
5. In this question, you will write a MIPS program for encoding and decoding morse code using memory-mapped I/O. You will use a simple written version of morse code where dots are represented by a period (ASCII 4610), dashes by a hyphen (ASCII 4510), letter breaks by a space (ASCII 3210), and word breaks by a slash (ASCII 4710). For example, the string “hello world” would be represented in morse code as “…. . .-.. .-.. — / .– — .-. .-.. – ..”. This version of morse code will only support encoding lower case letters and spaces. Beginning with the provided code for this question, implement main, decode, and encode as described below.
The main procedure of your program should consist of a loop that asks the user to enter a single character, ‘d’ for decode or ‘e’ for encode. The character should be echoed to the console, followed by a newline character. Next, if the uses pressed ‘d’, invoke your decode procedure, described below. If the user pressed ‘e’, invoke your encode procedure, described below. If the user presses any other character, terminate. Once decode or encode returns, loop again.
The decode procedure should accept as input a series of morse code characters. Each time a period, hyphen, or slash is input, it should be placed into a buffer (use the space declared in the .data section with the label decodeBuffer). When the space key is pressed, add null terminator to the buffer (do not store the space). The address of the buffer should then be passed to the provided decodeChar function, which will return the actual character to print. Finally, the decoded character should be output to the console. If the decodeChar procedure returns 0, the input was invalid, and nothing should be output. The procedure should continue accepting morse code input and echoing the decoded

characters to the console until the enter key is pressed, then echo a newline character to the console and return.
The encode procedure should accept as input a series of lower case letters and spaces. Each time a character is input, its value should be passed to the provided encodeChar procedure, which will return the address of a string containing the morse code encoding of that character, which should be output. If encodeChar returns 0, the input was invalid, and nothing should be output. The procedure should continue accepting characters as input and echoing their morse code encoding to the console until the enter key is pressed, then echo a newline character to the console and return.
In addition to implementing main, encode, and decode, you may add other procedure if needed. However, do not modify or add to the .data section, and do not modify the provided procedures encodeChar and decodeChar. All procedures you implement must use the “standard” conventions discussed in class for passing parameters and returning results. Do not use any syscall instructions, except to terminate at the end of your program.
Notes
• When working on this question, ensure memory mapped IO is turned on in QtSpim (Windows/Linux: Simulator menu > Settings > MIPS tab > check Enable Mapped IO; Mac: QtSpim menu > Settings > MIPS tab > check Enable Mapped IO).
• When using memory mapped IO, all read and write operations work one character at a time. Also, input is not automatically echoed, so typing in the console will have no visible result unless your code reads the character and then prints it.
• In the decode procedure, the morse code characters (periods, hyphens, spaces, and slashes) should not be output to the console, only the decoded character is output each time the space key is pressed. Similarly, in the encode procedure, the letters and spaces the user types should not the output to the console, only the morse code encoding.
• You may find it helpful to write procedures for input and/or output rather than duplicating the memory- mapped IO code in multiple places.
Sample run:
Would you like to encode (‘e’) or decode (‘d’)? e …. . .-.. .-.. — / .– — .-. .-.. -.. Would you like to encode (‘e’) or decode (‘d’)? d hello world
Would you like to encode (‘e’) or decode (‘d’)? q
Note that the input for this sample run was “ehello world\nd…. . .-.. .-.. — / .– — .-. .-.. -..\n”