CS2630: Computer Organization Midterm practice, Study notes of Electronics

The questions are the type you should expect. The best way to use this practice is to take it like you are taking a real exam. One caveat is that the ...

Typology: Study notes

2021/2022

Uploaded on 08/01/2022

fioh_ji
fioh_ji 🇰🇼

4.5

(70)

814 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
!
CS2630:(Computer(Organization(
Midterm(practice(
!
Since!there!are!no!past!midterms!to!look!at,!this!document!provides!some!practice!questions.!
The!questions!are!the!type!you!should!expect.!!
!
The!best!way!to!use!this!practice!is!to!take!it!like!you!are!taking!a!real!exam.!One!caveat!is!that!
the!length!of!the!practice!exam!is!not!representative!of!the!length!of!the!midterm,!so!you!will!
probably!take!more!than!75!minutes!on!the!practice.!Grade!yourself!with!the!solutions!after!
you’ve!taken!this!practice.!
!
The!exam!will!be!open!book/open!note.!No!electronics.!Show!your!work!when!appropriate.!
Binary(/(number(representation(
1. How!many!things!can!you!name!uniquely!with!N!bits?!2N!
!
2. What!is!the!result!of!the!following!expression?!Assume!the!integers!are!32-bit.!Give!your!
answer!in!decimal.!
!
(6!<<!2)!|!1!!
25!
!
3. What!is!the!least!number!of!bits!needed!to!store!the!number!0x4023!when!using!two’s!
complement?!
!
0100!0000!0010!0011!
valid!answer!might!be!15!or!16!
!
4. X!is!a!variable!holding!an!integer.!Give!an!expression!using!only!X!and!bitwise!operations!
that!evaluates!to!0!if!X!has!a!0!in!the!least!significant!bit!and!1!if!X!has!a!1!in!the!least!
significant!bit.!
X!&!1!!
!
5. Give!the!standard!name!for!235!bytes.!For!example,!210!is!1!kibi-byte.!
!
32!gibi-bytes!
! !
!
6. Give!the!decimal!number!-3!in!binary!using!two’s!complement!(you!may!show!your!
answer!using!any!number!of!bits!that!is!sufficient!to!store!the!number):!
101!with!3!bits,!1101!with!4!bits,!11101!with!5!bits!…!
pf3
pf4
pf5

Partial preview of the text

Download CS2630: Computer Organization Midterm practice and more Study notes Electronics in PDF only on Docsity!

CS2630: Computer Organization

Midterm practice

Since there are no past midterms to look at, this document provides some practice questions. The questions are the type you should expect. The best way to use this practice is to take it like you are taking a real exam. One caveat is that the length of the practice exam is not representative of the length of the midterm, so you will probably take more than 75 minutes on the practice. Grade yourself with the solutions after you’ve taken this practice. The exam will be open book/open note. No electronics. Show your work when appropriate.

Binary / number representation

  1. How many things can you name uniquely with N bits? 2 N
  2. What is the result of the following expression? Assume the integers are 32-bit. Give your answer in decimal. (6 << 2) | 1 25
  3. What is the least number of bits needed to store the number 0x4023 when using two’s complement? 0100 0000 0010 0011 valid answer might be 15 or 16
  4. X is a variable holding an integer. Give an expression using only X and bitwise operations that evaluates to 0 if X has a 0 in the least significant bit and 1 if X has a 1 in the least significant bit. X & 1
  5. Give the standard name for 2 35 bytes. For example, 2 10 is 1 kibi-byte. 32 gibi-bytes
  6. Give the decimal number - 3 in binary using two’s complement (you may show your answer using any number of bits that is sufficient to store the number): 101 with 3 bits, 1101 with 4 bits, 11101 with 5 bits …

Memory organization

  1. Suppose I have an architecture where addresses are 64 bits and integers are 32 bits. Consider the following Java code. int[] x = new int[ 3 ]; x[0] = 4; x[1] = 5; x[2] = 6; Suppose the array starts at address 0x80. a) Draw a diagram of memory after this code runs. You should label each byte with an address, and show the value of each byte (in hexadecimal). Address Contents … 0x80 0x 04 0x81 0x0 0 0x82 0x0 0 0x83 0x0 0 0x84 0x 05 0x85 0x 0x86 0x 0x87 0x 0x88 0x 0x89 0x 0x8A 0x 0x8B 0x … b) What is the address of the last word of the array? 0x
  2. Match the region of a running program’s memory with what to store there. Some regions may have zero, one, or multiple answers. what to store: a) an array of characters representing a message that might be printed b) a constant c) return address of a procedure call

loop: lw $t2,0($t0) # t2 gets 1st element of array A lw $t3,0($t1) # t3 gets last element of array A sw $t2, 0($t1) (^) # store ___ into end of A sw $t3, 0($t0) (^) # store ___ into start of A addi $t1, $t1, _- 4 __ (^) # Update $t addi $t0, $t0, _ 4 __ (^) # Update $t bgt $t1, $t0, loop (^) # Continue until $t0>=$t

  1. In a MIPS program, assume that the program counter PC currently contains address 0x000000F0 and program needs to jump to the label LL, which is labeling address 0x3FFFFFF0. If you use an instruction like j LL, then you can easily do it, and this is fine when you are writing a program. However, in this case, it cannot be a TAL instruction in the J-type instruction format J. Here is the question: (a) Why can’t j LL be a basic machine instruction in the J-type format? [Hint: See how far the program counter has to jump] jump address = (PC+4)[31:28], value_for_address_field, 00 So if the j LL instruction is at 0x000000F0, then it can only jump to addresses that look like 0x0XXXXXXX. (b) What sequence of TAL instructions should the assembler translate j LL to? lui $at, 0x3FFF ori $at, 0xFFF jr $at
  1. In class, we discussed how each card in a 52-card deck (4 suits and 13 values A,2,3,…,K) can be represented by a 6-bit binary number. Below is how a card is stored in a 32-bit integer 26 unused bits| _ _ _ _ | _ _ fvalue suit a) Suppose we want to write a function check_fvalue. The signature of the function as it would appear in Java is: int check_fvalue(int cardA, int cardB) CardA and CardB are integers such that the 6-bit representation of the card is in the least significant bits and the rest of the bits are unknown. The function returns 0 if the cards had different fvalues and 1 if the cards had the same fvalue. Write check_fvalue as a function in MIPS. Use the conventions for functions written in MIPS. check_fvalue: srl $t0, $a0, 2 srl $t1, $a1, 2 beq $t0,$t1,same addiu $v0, $zero, 0 jr $ra same: addiu $v0, $zero, 1 jr $ra b) Write MIPS code that calls the check_value on a card with the fvalue of 7 and a card with the fvalue of 2. The suit of the cards can be anything. addiu $a0, $zero, 7 sll $a0, $a0, 2 addiu $a1, $zero, 2 sll $a1, $a1, 2 jal check_fvalue