Brock Cameo

  COSC 2P12
Assignment 4
Last Modified: Sunday, 19-Nov-2017 16:45:49 EST


Due: Monday, December 4, 2017, 4:30 pm
Accepted late until:Wednesday, December 6, 2017, 4:30 pm

1. LC-3 Process Data Program - A

You are to write an LC-3 program that processes a number of integers in memory. The program will go through the integers and produce the following results: the sum of the negative integers, the sum of the positive integers, the number of negative integers, and the number of positive integers. These results will be stored in appropriately labelled memory locations at which time the program will halt.

The values in memory to process will start at a location in memory labelled data. This will be defined by a .fill directive. This will be followed by a number of subsequent .fill directives with various values and a final .fill directive with a value of 0.

Thus this part of your code might look like:

data .fill   123
     .fill   -23
     .fill   17


     .fill   0

You should have at least 15 or so values to process. Your program will process each value in memory until it encounters a 0 at which time the computed results will be stored in memory (at appropriately labelled locations) and the program will halt.

2. LC-3 Process Data Program - B

You are to write an LC-3 program that processes a number of integers entered at the keyboard. You will need to use the newtraps as mentioned in the class email and also to be discussed in class. The program will prompt for and read integers until a value of 0 is entered. The program will produce the following results: the sum of the even integers, the sum of the odd integers, the number of even integers, and the number of odd integers. These results will be printed out (one per line) with each value preceded by an appropriate message after which the program will halt. Typical output will look like:

There are 8 even integers
The total of even integers is 272
There are 9 odd integers
The total of odd integers is 369

You will need to use the extended traps as described in the LC-3 Simulators mini-guide found at: You will need to use the extended trap for reading an integer and the extended trap for printing an integer. The source code for the extended traps is newtrapsV2.asm found in the LC-3 Examples programs on the course web site. You will need to assemble the newtraps code to produce newtrapsV2.obj or download the newtrapsV2.obj. Then load the newtrapsV2.obj file before loading your program object file for execution.

3. String Subroutine

Write an LC-3 function that accepts one parameter, the address of a null-delimited string in R1, and returns the length of the string in R0. The length does NOT include the null terminating the string. Make certain that the function does not destroy any registers!

Write a main program that utilizes the function. The program will continuously prompt the user to enter strings (a sequence of characters). You detect the end of the string by recognizing the new line character when the return or enter key is pressed. This terminating character does NOT form part of the string. Your program will print the length of the string followed by separator characters ": " and then the string itself, ALL on a single line. The end of the string input will be determined by a zero length string which will not be processed by the function. You may assume the maximum string entered is 100 characters in length.

You will also need to use the extended trap for printing an integer for this question.

Sample program execution:

Enter a string: There once was a boy from Kentucky.
35: There once was a boy from Kentucky.
Enter a string: Abcdefghijkl  
12: Abcdefghijkl
Enter a string:   
Normal Termination  

NOTE: The character for the return key may be either x0A or x0D depending on the system you are using. You can determine the character used by creating a one line program that issues getc (TRAP x20) to accept a single character and look at the character placed in R0 after getc is executed and you use the return key.

Remember to include appropriate program and code comments in your solution.

Print out your source listings for inclusion in your assignment submission. Also, in order to facilitate marker evaluation, compress all of your source programs (.asm files) and machine language file (.obj files) into a zip file and email it to as described below.

Note that you must make a digital submission via e-mail, in addition to your printed submission. The details are discussed in the submission section below. Make certain that you make this submission from your Brock e-mail address. Failed message delivery as a result of problems with an external mail server will not qualify as a reason to provide an extension or other consideration.

• For the electronic submission you must compress your source and object files together into a zip file named and e-mail as a single attachment to
• The subject must consist of student number - name - COSC 2P12 Assign 4

• Failure to follow these instructions will result in at least a 40% deduction!!
• Staple your printed source code together and a standard computer science cover sheet and deposit into the hand-in box.