CDA3101Exam1Soln

# CDA3101Exam1Soln - CDA 3101 Exam1 (Fall 2006) Time: 1 hr....

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

CDA 3101 Exam1 (Fall 2006) Time: 1 hr. 30 mins. Honor Code Statement On my honor, I have neither given nor received unauthorized aid on this exam. _______________________ ________________________ Signature UFID 1. (a). (10 points) Write (in binary) the IEEE 754 single-precision representation of the number 20.75 10 . Show all work. 0 1000 0011 0100 1100 0000 0000 0000 000 (b). (5 points) Say f 1 , f 2 , f 3 , …., f n are the consecutive decimal numbers that can be represented in the interval 4 10 to 8 10 . Find the values f i+1 – f i , i=1. .(n-1), assuming IEEE 754 double-precision floating point representation is used. You can leave your answer in powers of 2. Show all work. (8-4)/2 52 =2 -50

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

View Full Document
2. (40 points) Implement the recursive function foo() given below in the MIPS assembly language. Be sure to follow the procedure call conventions (pass arguments in \$a0- \$a3, pass return values in \$v0-\$v1, saving appropriate registers) appropriately. (Assume that the value of x entered is always small enough so that the output of foo will fit 32-bit 2’s complement representation) int foo(int x) { int ret; if (x <= 0) return 1; else { ret = x * foo(x-2); return ret; } } Also, write a short main function that i. prompts the user to enter the integer x ii. calls the foo( ) function iii. and prints the value returned by the foo( ) function. .data Prompt: .asciiz "\n Please Input a value for x = " .globl main .text main: li \$v0, 4 la \$a0, Prompt syscall li \$v0, 5 syscall add \$a0, \$v0,\$zero jal foo addi \$a0, \$v0,0 li \$v0, 1 syscall li \$v0, 10 syscall foo: blez \$a0, base addi \$sp,\$sp, -8 sw \$a0,0(\$sp) sw \$ra,4(\$sp) addi \$a0,\$a0,-2 jal foo lw \$a0,0(\$sp)
\$ra,4(\$sp) addi \$sp,\$sp, 8 mul \$v0,\$v0,\$a0 jr \$ra base: addi \$v0,\$zero,1 jr \$ra

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## CDA3101Exam1Soln - CDA 3101 Exam1 (Fall 2006) Time: 1 hr....

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

View Full Document
Ask a homework question - tutors are online