DOC PREVIEW
Berkeley COMPSCI 61C - Machine Structures Midterm I

This preview shows page 1-2-3-4-5 out of 14 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

University of California at BerkeleyCollege of EngineeringDepartment of Electrical Engineering and Computer SciencesComputer Science DivisionCS 61c J. WawrzynekSpring 2006Machine StructuresMidterm IYour Name: Fect, PerID Number: 999-99-999Left Neighbor ID: Right Neighbor ID:This is a op en- book exam. You are allowed to use any books and notes that you wish.No calculators or electronic devices of any kind, please. You have 2 hours. Each questionis marked with its number of points.This exam booklet should have 11 printed pages, plus 4 blank pages at the end. Checkto make sure that you have all the pages. Put your student ID neatly on each page.Show your answers in the space provided for them. Write neatly and be well organized.If you need extra space to work out your answers, you may use the back of previousquestions or the blank sheets attached to the back of your exam booklet. However, onlythe answers appearing in the proper answer space will be graded.Good luck!problem maximum score1 7pts2 5pts3 5pts4 10pts5 10pts6 10pts7 13ptstotal 60pts1CS61c S06 Midterm I ID: 21. [8 points]Which of these unsigned numbers is largest: FadedAbehex, DeadBeefhexorFeedFacehex[1 point]?0xFeedFaceWhat is B0Dhexin decimal [1 point]?2829What is 337tenin hexadecimal [1 point]?0x151What is the decimal equivalent of the 6-bit two’s complement number 101010two[1point]?-22Put a T (true) or F (false) in each table cell [14point each, total is rounded up ⇒ 4points]:sign & 1’s 2’sunsigned magnitude complement complementCan representpositive numbers T T T TCan representnegative numbers F T T THas more than onerepresentation for 0 F T T FUses the same additionprocess as unsigned T F F TCS61c S06 Midterm I ID: 32. [5 points] The following program is compiled and run on a MIPS computer.1 int main() {2 int i;3 int four_ints[4];4 char* c;56 for(i=0; i<4; i++) four_ints[i] = 2;78 c = (char*)four_ints;9 for(i=0; i<4; i++) c[i] = 1;1011 printf("%x\n", four_ints[2]);12 }What does it print out? (The “%x” in printf is used print out a word in hexadecimalformat.) [3 points]2If we change the 2 on line 11 to a 0, then recompi le and run, what would be printed [2points]?1010101CS61c S06 Midterm I ID: 43. [5 points] The program below is written using the MIPS instruction set. It is loaded intomemory at address 0xF000000C (all ins truction memory addresses are shown below).F000000C loop: addi $1, $1, -1 # [ 8 | 1 | 1 | -1 ]F0000010 beq $1, $0, done # [ 4 | 0 | 1 | 1 ]F0000014 j loop # [ 2 | 3 ]F0000018 done:For each instruction in the program, write down the values (in decimal) of each field inthe machine language version of that instruction using the following notation:[ value | value | ... ](With this notation, the MIPS instruction add $3,$2,$1 instruction would be describedas[ 0 | 2 | 1 | 3 | 0 | 32 ].Put your answers to the right of the “#”s.CS61c S06 Midterm I ID: 54. [10 points] a) The following function should allocate space for a new string, copy thestring from the passed argument into the new string, and convert every lower-casecharacter in the new string into an upper-case character. Fill in the blanks and the bodyof the for() loop [7 points]:char* upcase(char* str) {char* p;char* result;result = (char*) malloc(1+strlen(str));strcpy(result, str);for( p=result; *p!=’\0’; p++ ) {if (*p >= ’a’ && *p <= ’z’)*p += ’A’ - ’a’;}return result;}Below is table for the ASCII character codes, that you might need for part b). Thenumbers along the left and top indicate the first and second hex digits of the codes,respectively.0 1 2 3 4 5 6 7 8 9 A B C D E F0 NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI1 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US2 SP ! ‘‘ # $ % & ’ ( ) * + , - . /3 0 1 2 3 4 5 6 7 8 9 : ; < = > ?4 @ A B C D E F G H I J K L M N O5 P Q R S T U V W X Y Z [ \ ] ^ _6 ‘ a b c d e f g h i j k l m n o7 p q r s t u v w x y z { | } ~ DELCS61c S06 Midterm I ID: 6b) Conside r the code bel ow. The upcase name() function should convert the ithnameto upper case by calling upcase by ref, which should in turn call upcase().Complete the implementation of upcase by ref. You may not change any part ofupcase name [3 points].void upcase_by_ref( char** n ) {*n = upcase (*n);}void upcase_name(char* names[], int i) {upcase_by_ref( &(names[i]) );}CS61c S06 Midterm I ID: 75. [10 points] The original MIPS processor did not support multiplication; compilers wereexpected to break down multiplication and division into simpler operations. Even onnewer MIPS processors (that have the MUL instruction), compilers sometimes still dothis to i mprove performance.Consider the following C function:int foo(int x) {return x*257;}Write the corresponding MIPS assembly code below. You may not use any form of MUL.Your answer should use as few a number of instructions as possible [4 points].foo: sll $v0, $a0, 8 # $a0 contains xadd $v0, $v0, $a0# return value should be in $v0jr $raMultiplication is more difficult when neither argument is known at compile time. Thegeneral procedure for achieving multipl ication of two unsigned numbers is to use a seriesof shift and add operations (think about how long-hand multiplication works). Thefollowing assembly code multiplies two unsigned numbers, $a0 and $a1, le aving theresult in $v0. Assume that the result is sufficiently small that it fits in a single register.Fill in the missing lines [6 points].addi $v0, $zero, $zero # clear $v0loop: beq $a1, $zero, done # if $a1==0, we are doneandi $t0, $a1, 1 # check bottom bit of $a1...beq $t0, $zero, skip # ...if it is 0, skip over# the next instructionadd $v0, $v0, $a0 # fill me in!skip: srl $a1, $a1, 1 # shift $a1 to the rightsll $a0, $a0, 1 # fill me in!j loop # repeatdone: jr $raCS61c S06 Midterm I ID: 86. [10 points] Consider the design of a new type of 16-bit processor, with the followingcharacteristics:• One machine word equals 16 bits.• 16 16-bit registers.• Byte-addressed memory of 216memory locations.• 16 different instruction opcodes (some defined below).• Single word instruction format..The table below lists a subset of instructions for this machine. Your job is to devisethe machine language (instruction encodings). Each instruction will begin with a 4-bi topcode field on the far left of the instruction word, followed by whatever other fields areneeded to encode the instruction.To the extent possible you should model your instruction encodings after the MIPS.Obviously, there will be


View Full Document

Berkeley COMPSCI 61C - Machine Structures Midterm I

Documents in this Course
SIMD II

SIMD II

8 pages

Midterm

Midterm

7 pages

Lecture 7

Lecture 7

31 pages

Caches

Caches

7 pages

Lecture 9

Lecture 9

24 pages

Lecture 1

Lecture 1

28 pages

Lecture 2

Lecture 2

25 pages

VM II

VM II

4 pages

Midterm

Midterm

10 pages

Load more
Download Machine Structures Midterm I
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Machine Structures Midterm I and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Machine Structures Midterm I 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?