CSC 376
Exercise Assignment Midterm (ESMidTerm)
The midterm has problems consisting of true/false, multiple choice, fill in the blank and short response. This exercise consists of similar questions you may encounter on the exam. ESMidTerm will not be graded in the strict sense. If submitted with all the exercises attempted, a completion grade of 10 points will be awarded as extra credit. There is also Discussion ESMidTerm Extra Credit if you have questions or can assist others with questions. As before, if you are giving assistance, provide help without directly giving out the answers.
Exercise 1
Convert each of the following numbers to 8-bit signed magnitude, 8-bit one’s complement and 8-bit two’s complement. Report your answers in binary.
a. (−97)10
8-bit signed magnitude
8-bit one’s complement 8-bit two’s complement
b. (−47)10
8-bit signed magnitude 8-bit one’s complement 8-bit two’s complement
c. (−127)10
8-bit signed magnitude 8-bit one’s complement 8-bit two’s complement
d. 12610
8-bit signed magnitude 8-bit one’s complement 8-bit two’s complement
Exercise 2
___________________
___________________
___________________
___________________
___________________
___________________
___________________
___________________
___________________
___________________
___________________
___________________
Convert the following 16-bit two’s complement numbers in hexadecimal representation to decimal.
a. AC2416 b. 64A216 c. 5D1716 d. FFFF16
_____________
_____________
_____________
_____________
Exercise 3
Find the decimal equivalents for the following 8-bit two’s complement numbers. a. 0010 0100 Decimal Equivalent ___________
b. 1010 1001 Decimal Equivalent ___________
c. 1100 0011 Decimal Equivalent ___________
d. 0101 0101 Decimal Equivalent ___________
Exercise 4
Perform two’s complement addition on the following pairs of numbers. In each case, indicate the value of the status bits after the addition. Assume NZVC=0000 prior to the addition.
a. 1000 0010 + 1000 0010 = __________________ NZVC=_________ b. 1010 1001 + 0110 1100= __________________ NZVC=_________ c. 1001 1111 + 1111 1110= __________________ NZVC=_________ d. 0111 1010 + 0110 0110= __________________ NZVC=_________ Exercise 5
Using the PEP/8 instruction, 72004A, answer the following questions. What is the instruction in binary?
________ ________ ________ ________ ________ ________
Starting from the left, what do bits 6 – 8 represent? ___________________ (be specific) For this instruction, what register will be used? __________________________ Explain what is stored in mem[004A]? _________________________________
Exercise 6
The following is in single-precision IEEE 754 format, 1 01111111 10110011001100110011010.
What is the sign bit?
Does the sign bit represent a positive or negative number?
What is the bias used in IEEE 754 single-precision format?
As shown above, what is the exponent in binary?
What is the exponent after the bias is removed? (In decimal)
As shown above, what is the significand in binary?
Explain why it is possible for error to be introduced when converting a decimal number to IEEE 754 format.
Exercise 7
Using the PEP/8 instruction, D11AA3, and the following table, answer the following questions.
Content before instruction.
What is the instruction? ______________________________
What is the register? _________________________________
What is the addressing mode? _________________________
What is the content of the accumulator after the instruction is executed, (hex)? __________________ What is the content of the index register after the instruction is executed, (binary)? _________________ What is the content of mem[1AA3] after the instruction is executed, (hex)? ______________________ What is the content of mem[1AA5], (binary)? ________________________ What is the content of mem[1AA7], (hex)? ________________________ What is the RTL specification for this instruction?___________________________________________ What is the value of the NZVC bit after execution? _____________________
____________
____________
____________
____________
____________
____________
Accumulator
Index Register
Mem[1AA3]
Mem[1AA5]
Mem[1AA7]
NZVC
Content
2A34
FF32
3AF0
2AFF
1AFF
0000
Exercise 8
The following is in Pep/8 assembly language.
LDX 8, i
ORX 0x0030, i STBYTEX num, d CHARO num, d STOP
num: .BYTE 0 .END
What is the output of this program? ________
What is ORX doing? __________
Why is the ORX instruction required?
What is the hexadecimal object code that is suitable for PEP/8. (Include all code necessary for the object code to run on the PEP/8. Use PEP/8 to check your work)_______________________________________________
Exercise 9
The following is in Pep/8 assembly language.
DECO ‘X’, i CHARO ‘\n’,i DECO 0xFFE3, i CHARO ‘\n’,i CHARO 0x003D, i STOP
.END
What is the output of DECO ‘X’, i?
What is the output of DECO 0xFFE3, i? _______________________ What is the output of CHARO 003D, i? _______________________
What is the hexadecimal object code that is suitable for PEP/8. (Include all code necessary for the object code to run on the PEP/8. Use PEP/8 to check your work)_______________________________________________
______________________
Exercise 10
Draw the runtime stack for the following C++ program. (Show any global variables and include main in the runtime stack)
Use
retAddr for the return address
retVal for the return value NA not used
#include
using namespace std;
int ounces;
void size(int& ou, int lbs) {
ou = lbs*16; }
int main() { int lbs;
cout << "Enter number of pounds";
cin >> lbs;
size(ounces, lbs);
cout <<"You have " << ounces << "ounces"; return 0;
}
Exercise 11
Draw the call tree, as in Figure 2.30, for the function binCoeff of Figure 2.28 for the call statement from the main program: (e) binCoeff (4, 2)
● Part 1) Draw the call tree for the call statement from the main program. (See Fig 2.30 for an example)
● Part 2) How many times is the function called? __________________
● Part 3) What is the maximum number of stack frames on the run-time stack during the execution, including main). __________________
● Part 4) The sequence of calls and returns for the program. (See page 66 below Fig 2.30)
Exercise 12
The Fibonacci sequence is
0 1 1 2 3 5 8 13 21...
Each Fibonacci number is the sum of the preceding two Fibonacci numbers. The sequence starts with the first two Fibonacci numbers, and is defined recursively as:
fib(0) = 0
fib(1) = 1
fib(n) = fib(n-1) + fib(n-2) for n > 1
The C++ program that computes the Fibonacci number is as follows:
#include
if (n == 0) { return 0;
}
else if (n == 1) {
return 1; }
else {
return fib (n – 1) + fib (n – 2);
} }
int main () {
int num;
cout << "Which Fibonacci number? ";
cin >> num;
cout << "The number is " << fib (num) << endl; return 0;
}
● Part 1) Draw the call tree for the Fibonacci number fib(5)
● Part 2) How many time is fib called? ______________
● Part 3) What is the maximum number of stack frames allocated on the run-time stack? (Do not include the main stack.) ___________
Exercise 13
The object code for Figure 6.14 has a CPA at 000C to test the value of j. Because the program branches to that instruction from the bottom of the loop, why doesn’t the compiler generate a LDA j,d at that point before CPA.
Exercise 14
Explain the difference in the memory model between global and local variables.
How are each allocated and accessed in PEP/8?
Exercise 15
Draw the values just before and just after the CALL at 0022. See Figure 6.18
PC
SP
0000
0000
Before the CALL
FBCD FBCF
FBCD FBCF
PC
SP
After execution of the second CALL at 0022
Exercise 16
For the PEP/8 program shown in Figure 6.26, draw the run-time stack just before the second return. (See Figure 6.26 for an example)