CS33 -- Laboratory 5

Due 11:59pm Thursday, Sep 30.

email to me at: cfk@cs.swarthmore.edu a message in text form (no word, html or any other format than plain text) that contains labeled solutions to the exercises below. Make the subject of the email: cs33lab5. Make sure it is posted to me before 11:59 pm on Thursday, 30 Sep. The solutions will just be annotated programs in LC3 Assembly Language.

Don't forget that you are encouraged to work with a partner on these labs.

In this lab, you will write well-commented assembly language programs for the LC-3, assemble them to object code for the LC-3 (lc3as), and then run them in the LC-3 simulator (lc3sim-tk).

Each .asm file should assemble without errors using the lc3as program.

For this lab assignment, you will write two LC-3 assembly language programs. Your programs should begin at x3000 and you should not make any assumptions about the initial state of registers or memory locations. Of course loading your program will put what you want in memory locations.

  1. A Caesar cipher with key x is a way to encipher text where each letter of the plaintext is replaced by a letter x places past it in the alphabet. So, if the key is 2, a is replaced by c, b by d, e by f, etc. At the end of the alphabet, we 'wrap' around to beginning. So a is considered 1 place past z. If the plaintext is: "bombpearlharborzany" and the key is 2; the enciphered text will be: "dqodrgctnjctdqtbcpa"
    Your task is to write an LC3 assembly language program (with excellent comments explaining how it works) that will allow the user to enter a single digit key and then enter text (terminated by pressing the 'enter' key i.e. cr) Your program should output the enciphered text enciphered by a Caesar cipher with the entered key. Your program should also save the enciphered text is some consecutive memory locations of your choice Understanding the character counting example in P&P should help. It is initially presented in section 5.5, treated again in section 6.1.4, and solved using assembly language in section 7.2.

  2. Write a program which converts numbers typed in ASCII into their binary equivalent. Your program should read a decimal value (made up of multiple digits) from the keyboard and then output the binary value to the screen. Keyboard input is terminated when the user presses enter.

    For example, here the user enters the decimal value "4304" which yields the binary result "0001000011010000". (The IN trap is used here but you can use GETC if you prefer.

    Input a character> 4
    
    Input a character> 3
    
    Input a character> 0
    
    Input a character> 4
    
    Input a character> 
    
    0001000011010000
    

    To avoid complicating issues, you should assume that the user always enters input from keyboard that consists only of the digits 0 through 9 and Enter -- there's no need to do any error checking. Also, you should assume -- again, don't error check -- that all values are positive, and that the user will not type a value larger than (215 - 1) = 32767.

    Though this might sound quite complicated, if you break the problem into two halves, it's quite manageable. In the first half, you need to read digits from the keyboard and store the binary equivalent in a register. You don't have to actually convert it to binary -- simply by storing the "appropriate value" in the register, you're storing it in binary! In the second half, you need to print the contents of that register to the screen. That is send the ASCII code for a 0 or a 1 to the screen in the correct order for each bit in the register.