CS 2733/2731, Org II, Spring 2004, First Exam, Answers ======================================================================== 1. (a) 46 (base 10) = 101110 (base 2) -46 (base 10 = ~101110 + 1 = 1111 1111 1101 0001 + 1 = 1111 1111 1101 0010 (b) 1011 1111 1101 1100 (48 more 0's) (binary) = 0 01111111101 1100 (48 more 0's) (broken into fields) = (-1)^Sign x (1 + Significand) x 2^(Exponent - Bias) = (-1)^1 x (1 + 0.750000000) x 2^(1021 - 1023) = (-1) x 1.75 x 2^(-2) = -(7/4)x(1/4) = -7/16 = -0.4375 ======================================================================== 2. # CS 2733/2731, Computer Organization II, Spring 2004 # MIPS program giving answer to Exam1, question 2 .globl main main: addu $s7, $zero, $ra ########## Start of answer to Question 2 ###################### .data # A: .word 2, 3, 5, 7, 11, 13, 17, 19, 23, 0 # .text # la $s0, A # address of A # addi $t0, $0, 0 # loop counter, start at 0 # addi $t1, $0, 10 # to terminate loop # add $t2, $0, $s0 # address of item in A # addi $s1, $0, 0 # running sum # Loop: lw $t3, 0($t2) # store current $t0 into A # addi $t0, $t0, 1 # increment loop counter # addi $t2, $t2, 4 # increment pointer into A # add $s1, $s1, $t3 # add A[i] into running sum # bne $t0, $t1, Loop # branch back to form loop # ########## End of answer to Question 2 ######################## ## Print the sum just calculated (100) li $v0, 1 add $a0, $s1, $0 syscall jal Newl ########## Finish main################### addu $ra, $zero, $s7 jr $ra ########## write newline ################################# Newl: li $v0, 4 la $a0, Newline syscall jr $ra .data Newline: .asciiz "\n" ############### output ############################# # % spim -file exam1.s # 100 #################################################### ========================================================================== 3. # Answer to Exam1, Problem 3, Spring 2004 #################### .globl main main: add $s7, $0, $ra # save return address ########## First part of answer, call to Addup ########## addi $a0, $0, 7 addi $a1, $0, 19 jal Addup ########## End of call to Addup ######################### add $t0, $0, $v0 # save result in $t0 addi $v0, $0, 1 # print the returned value add $a0, $0, $t0 syscall addi $v0, $0, 4 # print a newline la $a0, Newln syscall add $ra, $zero, $s7 # restore return address jr $ra ########## Second part of answer, Code for Addup ####### Addup: addi $sp, $sp, -4 sw $ra, 0($sp) add $v0, $a0, $a1 lw $ra 0($sp) addi $sp, $sp, 4 jr $ra ########## End of code for Addup ######################## .data Newln: .asciiz "\n" ################# Output ####################################### four06% spim -file exam1_3.s 26 =========================================================================== 4. # CS 2734, Computer Organization II, Spring 2004 .globl main main: addu $s7, $zero, $ra ### First way uses addi and requires 0 for sign bit lui $s3, 0x0344 addi $s3, $s3, 0x07ff ## output answer: 0x034407ff or 54790143 li $v0, 1 move $a0, $s3 syscall jal Newl ### Second way uses ori and and always works lui $s3, 0x0344 ori $s3, $s3, 0x07ff ## output answer: 0x034407ff or 54790143 li $v0, 1 move $a0, $s3 syscall jal Newl ### Third method without lui: li $s3, 0x0344 sll $s3, $s3, 16 ori $s3, $s3, 0x07ff ## output answer: 0x034407ff or 54790143 li $v0, 1 move $a0, $s3 syscall jal Newl ## final part of main addu $ra, $0, $s7 jr $ra ## Newl function, print a newline Newl: li $v0, 4 la $a0, Newline syscall jr $ra .data Newline: .asciiz "\n" ############################################# # Output: # 54790143 # 54790143 # 54790143 ========================================================================== 6. With the given inputs, the upper two transistors are open (don't conduct current), while the bottom two are closed. Thus C is connected to the ground at the bottom and not to any power, so C's output is 0. If either input is 0, C is 1, while both inputs 1 makes C a 0. Thus C is a NAND gate.