Computer Sciences Dept.

CS/ECE 252 Introduction to Computer Engineering

Fall 2012 Section 3
Instructor Guri Sohi
TAs Pradip Vallathol and Junaid Khalid

URL: http://www.cs.wisc.edu/~sohi/cs252/Fall2012/

Homework 7 // Due at lecture Wed, Nov 21

Primary contact for this homework: Junaid Khalid [junaid at cs dot wisc dot edu]

You must do this homework in groups of two. Please write the full name and the student id of each member on every pages and staple multiple pages together.

Important notes:

  1. All code should be commented; answers without comments will be penalized.
  2. Use the "homework7" DropBox in Learn@UW to hand in the code for problems 4 and 5. You have to submit the .asm files and the files should be named q#.asm, i.e, the file for problem 4 should be named q4.asm. Since your code is tested automatically, it is important to stick to this naming convention, otherwise you will lose credit, even if your code is working correctly.
  3. Submit one archive file (*.zip or *.tar.gz) per group to the folder homework7. Add a README.txt file in the archive which contains the names and student IDs of all members of your group.
  4. The archive file should be named exactly like: <lastname1><lastname2>[.zip|.tar.gz]
  5. You can submit your code for problem 4 and 5 as many times as you want, until 11:00 AM on Wednesday, Nov 21, 2012. After that time we will consider your latest submissions for grading.

Problem 1 (3 points)

Consider the following LC-3 assembly language program. After execution, the output of the program is available in register R0.

 

          .ORIG x3000
          LD R2, INPUT
          AND  R0, R0, #0
 	  ADD  R1, R0, #1
	  ADD  R3, R0, #15

    LOOP  AND R4, R2, R1   
	  BRz  SKIP 
          ADD R0, R0, #1
    SKIP  ADD R1, R1, R1
    
          ADD R3, R3, #-1
   	  BRzp  LOOP
    INPUT .FILL x1997
          .END

  1. Run the program on PennSim and give a brief explanation of what it does.
    Counts the number of 1's in INPUT and store them in R0
  2. How many times does the LOOP execute?
    16 times
  3. What value will be contained in R3 after the execution of the program?
    R3 = 0xFFFF = -1

Problem 2 (4 points)

The following LC-3 program compares two characters strings of the same length; the source strings are in the .STRINGZ form. The first string starts at memory location x4000, and the second string starts at memory location x4100. If the strings are the same, the program terminates with a value 1 in R5, otherwise R5 is 0. Insert instructions at (a), (b) and (c) that will complete the program

 
	
            .ORIG x3000
            LD R1, FIRST
            LD R2, SECOND
            AND R0, R0, #0
LOOP        LDR R3, R1, #0
            LDR R4, R2, #0
            BRz NEXT
            ADD R1, R1, #1
            ADD R2, R2, #1
            NOT R4, R4
            ADD R4, R4, #1
            
             or 
            
            NOT R3, R3
            ADD R3, R3, #1
            ADD R3, R3, R4
            BRz LOOP
            AND R5,R5, #0
            BRnzp DONE
NEXT 	    AND R5, R5, #0
            ADD R5, R5, #1
DONE 	    TRAP x25
FIRST 	    .FILL x4000
SECOND 	    .FILL X4100
            .END

Problem 3 (5 points)

Consider the following LC-3 assembly language program:

 

        .ORIG x3000
        LD R0,INPUT
        AND  R1, R1, #0 
        ADD  R4, R1, #1
        ADD  R3, R0, #0 
	  

L00P    ADD R1, R1, R0
        ADD R3, R3, #-1
        BRp  L00P
	
        ADD R3, R3, R0
        ADD R0, R1, #0
        ADD R3, R3, #-1
        ADD R4, R4, #-1
        BRz  L00P
        BR DONE
INPUT   .FILL x0003
RESULT  .FILL x0000
DONE    ST R0,RESULT
        HALT
  1. Show the symbol table created by the assembler for the above program.
     Symbol Name    |   Address 
    INPUT | x300D
    L00P | x3004
    DONE | x300F
    RESULT | x300E
  2. Once the symbol table is created, the assembler then creates a binary version (.obj) of the program. Show the LC-3 machine code for the above program.
    x3000 0010000000001100
    x3001 0101001001100000
    x3002 0001100001100001
    x3003 0001011000100000
    x3004 0001001001000000
    x3005 0001011011111111
    x3006 0000001111111101
    x3007 0001011011000000
    x3008 0001000001100000
    x3009 0001011011111111
    x300A 0001100100111111
    x300B 0000010111111000
    x300C 0000111000000010
    x300D 0000000000000011
    x300E 0000000000000000
    x300F 0011000111111110
    x3010 1111000000100101

Problem 4 (9 points)

In this problem you are to write an assembly program that converts lower case alphabet characters to upper case alphabet characters. The input to the program is from the keyboard and the output is sent to the (display) screen. Make use of the template code provided in q4.zip along with the test scripts.

You have to implement the following functionalities in the program:

  1. Code to check for the termination character. If the user enters the termination character (“!”), the program will display the message “Finished successfully!” on the screen and will terminate.
  2. Code to check whether the input is a valid character. Only uppercase and lower case alphabets are considered valid characters; other characters (other than the termination character) are considered invalid. On getting an invalid input, the program should display an error message and then ask for a new input.
  3. Code to check whether an input is a lower case or upper case character. If the entered input is a lower case character, convert it to the corresponding upper case character.
  4. Code to display the uppercase alphabet characters on the screen.
  5. Keep doing the above until the user enters the termination character “!”

Your program should use subroutines for all the major functions.

To run the test for q4, type the following line into the Pennsim command line:

 
script test1.sc 

Your test is considered a failure if you see some messages having the FALSE keyword on the output command window when you run the test script. If your program is called something other than q4.asm you should either change its name or edit the script file, but make sure to rename it to q4.asm when you submit it to the Learn@UW DropBox.

The grading scheme for this problem will be as follows:

  1. Code assembles and has comments (1 point)
  2. Terminates on “!” (1 point)
  3. CheckInput; checks whether the input is valid (3 points)
  4. IsUppercase; checks whether the input is already in uppercase (2 points)
  5. ConvertToUppercase (1 point)
  6. DisplayChar; display the upper case alphabet (1 points)
q4_sol.zip

Problem 5 (9 points)

For problem 5, you have to further modify the GetInput and DisplayChar functionality of problem 4. Now, instead of getting input from the user, you will read a section of the memory from x7000 to x7013 (both inclusive). Instead of displaying the output at the console you will have to only write the uppercase alphabets to memory location starting from x7100. Thus in this part there is no need to check the termination character. In addition, you will need to implement some counters:

  1. Count the total number of invalid (i.e., non-alphabet) characters and write the result into memory location x70FF
  2. Count the total number of characters which are already in upper case and write the result into memory location x70FE
  3. Count the total number of character which have been converted to upper case by your program and write the result into memory location x70FD
To test your code you can use the test script provided in (q5.zip). You can do this by typing the following line into the Pennsim command line:
 
script test2.sc 

Your test is considered a failure if you see some messages having the FALSE keyword on the output command window when you run the test script. If your program is called something other than q5.asm you should either change its name or edit the script file, but make sure to rename it to q5.asm when you submit it to the Learn@UW DropBox.

The grading scheme for this problem will be as follows:

  1. Code assembles and has comments (1 point)
  2. Modifying the input mechanism to read from memory (2 points)
  3. Modifying the display/output sub routine to write data to memory (2 points)
  4. Count the total number of invalid characters (1 point)
  5. Count the total number of characters which are already in upper case (2 points)
  6. Count the total number of character which has been converted to upper case (1 point)
q5_sol.zip

 
Computer Sciences | UW Home