Unformatted text preview:

ECE 3035 Computing Mechanisms Study Guide Version 1.0 1 Computing Mechanisms Study Guide This study guide provides example problems on material from the class outline. It is valuable in helping you test your understanding of concepts from lecture. Many of these problems are from old exams; so they also provide good exam preparation. Solutions are provided to verify your answers. If any errors are detected, please send mail to [email protected] or [email protected] so future versions can be corrected. Good Luck! Scott and Linda Wills Version 1.0 18 August 2008 Copyright © 2008ECE 3035 Computing Mechanisms Study Guide Version 1.0 2 1: Introduction to Computing Mechanisms Problem IN-1 (3 parts) MIPS Assembly Language p1p5: addi $1, $0, Array # IA addi $6, $0, Bright # IB … Loop: loop body # IC … Next: addi $1, $1, 4 # ID bne $1, $6, Loop # IE Part A: What are the values of $1 at the following times in the execution of the loop above? Assume Array: begins at 6000 and Bright: begins at 7024. $1 when IC is first executed: $1 when IC is last executed: $1 when IE is last executed: Part B: Write a code fragment that packs four unsigned eight bit values A, B, C, and D (stored in $1, $2, $3, and $4) in order into a single 32 bit word stored in $1. When complete, value A should be stored in the least significant byte, while value D is stored in the most significant byte. Use only $1, $2, $3, $4, all of which can be modified. label instruction comment Part C: In a recursive subroutine, two registers $1 and $2 and the unmoved return address of the subroutine's caller must be preserved on the stack prior to the recursive call. Write a MIPS code fragment that preserves these three words on the stack. label instruction commentECE 3035 Computing Mechanisms Study Guide Version 1.0 3 Problem IN-2 (5 parts) MIPS Assembly Language Part A: Write a MIPS program fragment that computes “ )(17 CB−⋅−”and puts the result in register $6. Assume B and C are in registers $1 and $2, respectively. Use a minimum number of instructions and registers. You may reuse registers $1 and $2. Part B: Suppose A is stored in memory location 1020 and B is stored in memory location 1024. Write a MIPS program fragment that computes “ )16/(256 BA+⋅” and stores the result at memory location 1028. Use a minimum number of instructions and registers. Part C: Write a MIPS program fragment to jump to address 0xABCD1234. Part D: Suppose an image processing system stores a 512x256 pixel image in memory. Each pixel is represented by 8 bits and they are store contiguously in memory. How much memory (in kilobytes) does this require? How many bits are needed to address 1 pixel? Part E: Write a MIPS fragment that exchanges two registers ($1 and $2) without using any other registers or memory. (hint: think xor).ECE 3035 Computing Mechanisms Study Guide Version 1.0 4 Problem IN-3 (1 part) MIPS and C Part A: Consider the following MIPS code, which is the packed-data.asm example from the first module http://www.ece.gatech.edu/academic/courses/ece3035/examples/intro/asm/packed-data.asm. Write a C program corresponding to this MIPS code by filling in body of the C program fragment provided below. Assume that the registers $2, $3, and $6 hold variables “Pixels,” “P,” and “Result,” respectively. # Computes the OR of four 8-bit pixels packed in a 32-bit data word. # $2: Pixels: packed data word # $3: P: a single pixel # $6: Result: bit-wise OR of all pixels .data Pixels: .word -12869361 # decimal equivalent of 0xFF3BA10F .text Dilate: lw $2, Pixels($0) andi $6, $2, 255 # mask: extract P0 (0xFF) srl $2, $2, 8 # logical shift right by 8 bits andi $3, $2, 255 # mask; extract P1 srl $2, $2, 8 # shift off P1 or $6, $3, $6 # $6: P1 or P0 andi $3, $2, 255 # mask; extract P2 srl $2, $2, 8 # shift off P2, $2 is right with just P3 or $6, $3, $6 # $6: P2 or P1 or P0 or $6, $2, $6 # $6: P3 or P2 or P1 or P0 jr $31 int Pixels = -12869361; int main() { int P; int Result; return Result; }ECE 3035 Computing Mechanisms Study Guide Version 1.0 5 Problem IN-4 (2 parts) MIPS Assembly Language Part A: Create an assembly language implementation of dot product on two 10 element integer arrays. Here the values are placed in an array in static memory using the .word assembler directive. An assembly language shell program, shown below, is provided. # This program computes the dot product of two ten element integer arrays. .data A: .word 243, 459, 896, 535, 264, 698, 268, 281, 921, 886 B: .word 864, 215, 781, 151, 435, 128, 276, 336, 790, 825 .text P1p1: addi $1, $0, A # set memory base of array A # put your program here (return result in $3) jr $31 # return to operating system When your program completes, the result should be returned in register $3. The solution is best written and tested using MISASIM. Part B: Create an assembly language function that computes the averages of even and odd numbers in a variable sized array. Here the values are placed in an array in static memory using the .word assembler directive. The number of values is implied by the address of the next value in static memory at label Next:. An assembly language shell program, shown below, is provided. Assume at least one even and one odd value occurs in the list. # This program finds the average of even and odd numbers in an array .data Array: .word 243, 459, 896, 535, 264, 698, 268, 281, 921, 886 .word 864, 215, 781, 151, 435, 128, 276, 336, 790, 825 .word 501, 725, 835, 160, 300, 095, 481, 282, 515, 282 .word 662, 770, 776, 998, 758, 447, 758, 272, 015, 398 .word 042, 645, 565, 265, 105, 778, 739, 148, 309, 960 .word 903, 067, 469, 126, 673, 864, 658, 333, 170, 987 .word 565, 228, 235, 477, 568, 254, 628, 421, 788, 012 .word 246, 170, 746, 892, 586, 875, 055, 850, 885, 828 .word 717, 797, 971, 862, 269, 082, 824, 728, 650, 470 .word 740, 522, 232, 648, 323 Next: .word 00 .text P1p2: addi $1, $0, Array # set memory base # put your program here jr $31 # return to operating system When your program completes, the average of all even numbers is returned in $4 and the average of all odd numbers is


View Full Document

GT ECE 3035 - Study Guide

Download Study Guide
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Study Guide and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Study Guide 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?