EE319KMid-Term1F11-sol

# EE319KMid-Term1F11-sol - 1/8 EE 319K Fall 2011 First...

This preview shows pages 1–5. Sign up to view the full content.

1/8 EE 319K Fall 2011 First Mid-Term Dr. Ramesh Yerraballi Full Name : Solution Duration : 75 minutes EID :__________________________ Instructions : This is a closed book exam No calculators are allowed Write answers within the box/space provided after each of the questions. There are SIX questions on the test, read all of them first so you may properly allocate your time to answer them. Score Sheet Question Max Your Score 1 15 2 15 3 15 4 15 5 25 6 15

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2/8 1) [15 pts] Answer the following a) [4 pts] Give the signed 8-bit binary 2’s complement representation of the number -122 b) [5 pts ] What is the largest decimal number that can be added with %10000000 without setting the condition code flags C,V to 1 ? Assume 8-bit arithmetic. c) [6 pts] There is a bsr sub instruction at memory address \$4078. If the subroutine sub is at memory address \$40F9, what is the offset as seen in the machine code of the instruction? 2) [ 15 pts ] For the following instructions, give how many (read, write) bus cycles each takes. Instruction Read Bus Cycles Write Bus Cycles ldd #1000 3 0 stab \$44 2 1 jsr sub 3 2 puld 3 0 rts 3 0 01111111 -122 = -128 + 4 + 2 => 10000110 Offset = Dest_Addr – Location_of_Instr – Size of branch = \$40F9 - \$4078 – 2 = \$7F
3/8 3) [ 15 pts ] Recall the Primes example in C that I worked out in class. Given below is the subroutine IsPrime that I presented. Write a subroutine called LargestFactor that takes as input an unsigned 8-bit number and finds its largest factor (not itself). The above code should give you a good starting point to write this subroutine. The code skeleton is given below, you have to complete it. Note that if the number is a prime then the largest factor (not itself) is 1. Notes : LargestFactor(5) returns 1; LargestFactor(6) returns 3; LargestFactor(9 ) returns 3; LargestFactor(24 ) returns 12 // Checks whether the passed number is a prime or not // Input: Number whose primality is to be checked // Output: TRUE if prime, FALSE if not unsigned char IsPrime( unsigned char number) { unsigned char factor = 2; unsigned char result = TRUE; while ((factor <= number/2) && (result == TRUE)) { if (number%factor == 0) { result = FALSE; } factor = factor+1; } return result; } // Returns the largest factor of a given input number // Input: number (>2) whose largest factor is to be found // Output: The largest factor of number; unsigned char LargestFactor( unsigned char number) { unsigned char factor = 2; unsigned char largest = 1; while (factor <= number/2) { if (number%factor == 0) { largest = factor; } factor = factor+1; } return largest; }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4/8 4) [ 15 pts ] Your friend Joe and you are working together on a software project. You divide the job so Joe is responsible for a subroutine called Power that takes two inputs (lets call them p and q ) and returns a result ( p q ) in Register D. The inputs are 16-bit numbers. Joe requires that the two inputs you pass have to be passed using the stack. You are responsible for the main program where you will call Joe’s
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 8

EE319KMid-Term1F11-sol - 1/8 EE 319K Fall 2011 First...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online