汇编代写 | Computer Science 230 Fall 2020 Assignment 2
Computer Science 230
Computer Architecture and Assembly Language
Part (a): Write procedures save_our_souls
return value: none
The MARS application has several additional tools, one of which is the “Digital Lab
Sim”. This simulates a lab board with two seven-segment digital displays plus a hex
keypad. The procedures seven_segment_on and seven_segment_off contain the
code necessary to turn on and off all seven segments of the right-most digital
display. These procedures do not have parameters. You can use these procedures to
make the display flash on and off. Feel free to play with this display (i.e., in a
separate assembly file) but please do not modify those two procedures.
Also provided are two other procedures named delay_long and delay_short.
These cause the simulator to “sleep” for a certain period of time, 600 milliseconds
and 200 milliseconds respectively. The procedures do not have parameters. As
everything is simulated, the delays might not have these exact durations on your
computer; regardless, the long delay is significantly different from the short delay.
Your task is to write a procedure named save_our_souls which will flash the
famous “SOS” morse code sequence (dot dot dot dash dash dash dot dot dot). Below
is a timing diagram that attempts to relate the delays to the display being on or off;
this shows a dot dot dash dot pattern. the length of flashes and delays. In real morse
code the delay between dots is a bit shorter than the delay between dashes.
However, in order to simplify programming, you can keep delays the same between
the end of one dot/dash and the start of the next dot/dash.
Part (b): Write the procedure morse_flash
parameters: one byte contained in the $a0 register
return value: none
Later in part (d) of this assignment, you will write code to convert dots and dashes
for a letter (e.g., “. . .” for ‘S’, and “- – -” for ‘O’) into a one-byte equivalent. For now,
however, you are to write a procedure that takes a one-byte equivalent (passed into
the procedure as the least-significant byte in a 32-bit register) and flashes the
Digital Lab Sim display in a manner appropriate to the contents of that byte. The
procedure does not need to know the letter to be flashed; all it needs is the byte
Below are examples of dot-dash sequences beside their one-byte equivalents
(shown binary and hexadecimal notation):
Each byte consists of a high nybble and a low nybble:
● The high nybble (left-most four bits) encodes the length of the sequence.
● The low nybble (right-most four bits) encodes the dot-dash sequence itself
(where 0 is a “dot” and 1 is a “dash”).
In the first example above (the Morse for ‘F’), the high nybble encodes the number 4
(i.e., the length of the sequence), and the low nybble contains that sequence (0, 0, 1,
0). In the last example (the Morse for ‘T’), the high nybble encodes the number 1
(i.e., the length of the sequence), and the low nybble contains that sequence (first
three 0s are ignored, while last 1 is the dash). Notice that the low-nybble bits for
sequences of length three, two and one will contain leading zeros; these leading
zeros must be ignored (i.e., they are not dots).
The one-byte equivalent is to be turned into a series of calls to leds_on and
leds_off, with a delay between calls visually distinguishing dots from dashes. This
is to be done in a manner shown in the diagram provided in the save_our_souls
section of this description.
There is a special one-byte value: 0xff. It represents a space between words. For
this, morse_flash must keep the display off for three calls to delay_long
Part (c): Write the procedure flash_message
parameters: data-memory address in $a0
return value: none
Encoded messages are stored in data memory and consists of a sequence of
one-byte equivalents. A sequence is terminated by the 0 value (i.e., null, just as in
ending a string). For example, the one-byte equivalent sequence for “SOS” consists
of the following four bytes:
0x30 0x37 0x30 0x00
The code provided for you in a2_morse.asm stores this sequence at the
test_buffer memory location.
This procedure must use the address passed in $a0 as the starting location of the
sequence, and then loop through that sequence, calling morse_flash for each byte,
until encountering the end of the sequence. Once the sequence ends, the procedure