




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





Name: NetID: Discussion Section (Friday Lab Section): (circle one) AD1 AD2 AD3 AD4 AD5 AD6 AD7 AD8 AD9 ADA
Problem 1: C to LC-3 Conversion ( 20 points) Convert the C function below to an LC-3 assembly language subroutine. While converting from C to LC-3, use the run-time stack and activation record implementation described in the textbook (R5 is the frame pointer, R6 is the stack pointer, etc). You may assume that the input values for parameters alpha and beta are positive integers (greater than zero). You may also assume that the passed parameters are already saved in the activation record on the run-time stack (this was done by the calling program). int greek(int alpha, int beta) { int gamma, delta; gamma = 3; delta = alpha * beta + gamma; return delta; } Files in your problem1 directory:
Problem 3: Image Processing (20 points) Given two image files (Image1.ppm and Image2.ppm), write the C code to generate a new image file (alternate.ppm) such that the new image has alternating horizontal bands from Image1 and Image2. For example, if Image1 is entirely red and Image2 is entirely blue, then the final image will have horizontal strips of red and blue, with each strip is one pixel wide. Input1 Input2 Output The maximum size of an image will not exceed 200 by 200 pixels. The two images will be the same size. Files in your problem 3 directory:
Problem 4: Sting Manipulation (20 points) Implement a C function to perform basic string compression using the counts of repeated characters. For example, the string “aabccccaaa” would become “a2b1c5a3”. If the “compressed string” would not become smaller than the original string, your method should return the original string. File in your problem 4 directory:
Problem 5, continued Example You do not need to implement the queue in this manner; however, this example is provided for your contemplation. The queue is initially empty. isEmpty() returns 1; isFull() returns 0 Head Tail After calling enqueue(10): 10 Head Tail After calling enqueue(20): 10 20 Head Tail After calling enqueue(30): 10 20 30 Head Tail dequeue(&x) sets x to 10 and returns 1 20 30 Head Tail dequeue(&x) sets x to 2 0 and returns 1 30 Head Tail dequeue(&x) sets x to 30 and returns 1 Head Tail dequeue(&x) returns 0 Head Tail Free Hints Consider what happens when you enqueue 2 elements and dequeue 1 and repeat 50 times. At some point, if you don't copy, your tail pointer will leave the end of the array. There are three ways to deal with this: (1) make a circular array (harder), or (2) make the array bigger than it needs to be, and occasionally copy the array on dequeue (faster but takes some thought), or (3) always copy the array on dequeue (slower but easier and still worth full credit).
Reference information LC-3 assembly language problems: