Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

CE

Lab Report 4

Encoding and Decoding Morse Code

Brandon Gomez

Lab Section: 2

11.14.14





















PROCEDURE:
The purpose of this lab is to get familiar of using JSR and Stacks in LC-3 assembly. We
should also get familiar of converting Morse hex to a string and string to Morse binary. Our
program will be starting at x3000 and will be storing the input at x3201 through x3220 and
the output at x3221 through x3240. Moreover, if the user encodes SOS into Morse, the
program will produce the output: FOSOFO. If the user wants to decode a Morse message of
B810B8, the output will be LOL.



MATERIALS:
Orgin / .ORIG xXXXX / 0110 xXXXX
Tells the program where to start
AND DR, SR1, SR2 / 0101 DR SR1 0 00 SR2
This AND ands SR1 and SR2 and stores the result into DR
AND DR, SR1, imm5 / 0101 DR SR1 1 imm5
This AND ands SR1 and the digit and stores the result into DR
ADD DR, SR1, SR2 / 0001 DR SR1 0 00 SR2
This ADD adds SR1 and SR2 and stores the result into DR
ADD DR, SR1, imm5 / 0001 DR SR1 1 imm5
This ADD adds SR1 and the digit and stores the result into DR
Store Direct / ST SR, LABEL / 0011 SR offset9
Gets whatever data is in SR and stores it into LABEL
Load Direct / LD DR, LABEL / 0010 DR PCoffset9

Loads the data inside of LABEL and puts it in DR


Load Base + Index / LDR DR, BaseR, offset / 0110 DR BaseR offset6
Loads whatever is in BaseR and puts it into DR
Load Effective Address / LEA DrR LABEL / 1110 DR offset9
Loads the address of LABEL and puts it into DR
Conditional Branch / BRx LABEL / 0000 nzp PCoffset9
If the condition is true then it will go to the address LABEL, else it will go to the next
line
System Routine / TRAP x25 / 1111 0000 trapvect8
Halts the program
GETC / Gets user input and stores it in R0
PUTC / Gets R0 and prints it on to the monitor
STACKS / Stores data and you are able to push or pop it
JSR / Takes you to a subroutine where R7 contains the address of where you called the JSR so
you can return.

PARTA: Choosing



My program right away asks for the input of the user and then outputs it (not in picture), it
then checks to see if it is the letter E of D for Encode and Decode. If the user selects to E, it is
expected that the user inputs items like SOS. If the user selects D, it is expected that the
user inputs items like B810B8.

PARTB: Decoding

I first store my values inside a stack that is located inside x3201 and only 30 values can be
stored inside the stack so I keep a counter to make sure it never gets to that value. Once the
user presses ENTER, the program continues.



After getting instructions and going into a JSR subroutine, my program stores variable
inside some registers in order to check for some tests. The first string that the user inputs is
stored inside R5, and we have to check to see if that value lies inside 0-9 or A-F so we can
determine the offset. If it is inside 0-9 we only subtract x30 from the first hex value, else we
subtract x41 from the hex value. This is done by first subtracting x3A from the hex and if it
is positive it lies in A-F if it is negative, it lies inside 0-9. We used a temp in order to retain
our real value.

My program then takes the a pair of hexes and then decrements them and adds 16 if it is
the first hex and adds 1 if it is the second hex to a single byte.



Then, the program stores the new values into another stack inside x3221. Last, the
program looks though a table to see which of the new single byte matches with the
corresponding letter in order to print out the letter.

PARTC: Encoding



The first part of the encoder is very similar to the decoder were the program stores the
users input inside a stack in x3201. If the user inputs ENTER, the program will stop asking
for more inputs. The user can only enter 30 items. Once the user is done, the program
checks the results and compares the item to a table. Once one matches, the program stores
the HEX values into another stack in x3221 and prints the hex values.

DECODER RESULT:
If the user inputs B810B8[ENTER], then the program will take the first value and see it is a
letter so it will deduct x41 from B to give the value 12. (12-1) * 16 give a value of 176. Then
the program takes the second value of 8 and it sees that it is a digit so it will only deduct
x30 from the hex to give a value of 8. 176 + 8 = 184, which corresponds to L on the table.

Since there are still hex values to check, the program will go back up and get the next to
values until there is no more in the stack.

ENCODER RESULTS:
If the user inputs SOS[ENTER], then the program will get the first value and go through a
table in order to check to see which Hex value it corresponds to. Once it finds it, it will print
out the Hex value of F0. Since there are still values inside of the stack, the program goes
back up and gets the next value until the stack is empty.

CONCLUSION:
In conclusion, I found that the algorithms were much easier to solve, but took quite a while
to implement them. If I were to type in HELLO WORLD into the program, it will output
F8C0B8B8109010B0B870. If I were to type in 40101020A06048F0C058B0C040F0, the
program will output TOOMANYSECRETS. Error checking that may be good to have is
checking that the Morse code is in multiples of two. If it was not then it will report an error.
The subroutine should save and restore the registers so that they can use the registers for
arithmetic reasons. My conversion table is 72 bytes long. To convert a two ASCII hex to a
binary byte, will take a certain amount of cycles. For example if the input was A8. It will
take 18 cycles since 10 + 8 = 18. To convert a binary byte to a two ASCII hex character will
take the a certain amount of cycles too. If it was 17, it will take two cycles. One cycle to
determine how many 16s there are and one cycle to determine how many 1s there are.

You might also like