Sample Exam I PAC II ANSWERS

Similar documents
Computer Systems Organization V Fall 2009

administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions?

Practical Malware Analysis

CSCI 2121 Computer Organization and Assembly Language PRACTICE QUESTION BANK

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 4 Solution

Second Part of the Course

CMSC 313 Lecture 12. Project 3 Questions. How C functions pass parameters. UMBC, CMSC313, Richard Chang

CSC 8400: Computer Systems. Machine-Level Representation of Programs

CSC 2400: Computer Systems. Towards the Hardware: Machine-Level Representation of Programs

CSE P 501 Exam 8/5/04 Sample Solution. 1. (10 points) Write a regular expression or regular expressions that generate the following sets of strings.

CS , Fall 2001 Exam 1

Low-Level Essentials for Understanding Security Problems Aurélien Francillon

X86 Addressing Modes Chapter 3" Review: Instructions to Recognize"

Stack -- Memory which holds register contents. Will keep the EIP of the next address after the call

CMSC 313 Lecture 12 [draft] How C functions pass parameters

Program Exploitation Intro

CNIT 127: Exploit Development. Ch 1: Before you begin. Updated

Instruction Set Architecture

Instruction Set Architecture

Instruction Set Architecture

CISC 360 Instruction Set Architecture

Binghamton University. CS-220 Spring x86 Assembler. Computer Systems: Sections

Machine Programming 1: Introduction

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 21: Generating Pentium Code 10 March 08

Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p

CS , Fall 2002 Exam 1

Winter Compiler Construction T11 Activation records + Introduction to x86 assembly. Today. Tips for PA4. Today:

CSE P 501 Compilers. x86 Lite for Compiler Writers Hal Perkins Autumn /25/ Hal Perkins & UW CSE J-1

Y86 Processor State. Instruction Example. Encoding Registers. Lecture 7A. Computer Architecture I Instruction Set Architecture Assembly Language View

CSE351 Autumn 2014 Midterm Exam (29 October 2014)

COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 4. The Processor

COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 4. The Processor

Chapter 4. The Processor

Chapter 4. Instruction Execution. Introduction. CPU Overview. Multiplexers. Chapter 4 The Processor 1. The Processor.

Chapter 4. The Processor

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

CSE351 Spring 2018, Midterm Exam April 27, 2018

UW CSE 351, Winter 2013 Midterm Exam

Assembly I: Basic Operations. Computer Systems Laboratory Sungkyunkwan University

ECE 2030B 1:00pm Computer Engineering Spring problems, 5 pages Exam Two 10 March 2010

CS 31: Intro to Systems ISAs and Assembly. Martin Gagné Swarthmore College February 7, 2017

AS08-C++ and Assembly Calling and Returning. CS220 Logic Design AS08-C++ and Assembly. AS08-C++ and Assembly Calling Conventions

15-213/18-243, Spring 2011 Exam 1

Assembly I: Basic Operations. Jo, Heeseung

Towards the Hardware"

CS241 Computer Organization Spring Addresses & Pointers

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING PREVIEW SLIDES 16, SPRING 2013

ASSEMBLY I: BASIC OPERATIONS. Jo, Heeseung

Computer Organization Chapter 4. Prof. Qi Tian Fall 2013

CSE351 Autumn 2014 Midterm Exam (29 October 2014)

x86 assembly CS449 Fall 2017

Name: CMSC 313 Fall 2001 Computer Organization & Assembly Language Programming Exam 1. Question Points I. /34 II. /30 III.

You may work with a partner on this quiz; both of you must submit your answers.

CAS CS Computer Systems Spring 2015 Solutions to Problem Set #2 (Intel Instructions) Due: Friday, March 20, 1:00 pm

Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction

CS , Spring 2004 Exam 1

Computer Science 104:! Y86 & Single Cycle Processor Design!

CPS104 Recitation: Assembly Programming

W4118: PC Hardware and x86. Junfeng Yang

Intel assembly language using gcc

ECE 313 Computer Organization EXAM 2 November 11, 2000

2.7 Supporting Procedures in hardware. Why procedures or functions? Procedure calls

CS241 Computer Organization Spring 2015 IA

16.317: Microprocessor Systems Design I Fall 2014

6.1 Combinational Circuits. George Boole ( ) Claude Shannon ( )

Sungkyunkwan University

An Introduction to x86 ASM

IA Digital Electronics - Supervision I

Machine-Level Programming I: Introduction Jan. 30, 2001

CSE 582 Autumn 2002 Exam Sample Solution

Digital Forensics Lecture 3 - Reverse Engineering

CISC 360. Machine-Level Programming I: Introduction Sept. 18, 2008

The Processor: Datapath and Control. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College February 9, 2016

Midterm Exam CSC February 2009

1 /* file cpuid2.s */ 4.asciz "The processor Vendor ID is %s \n" 5.section.bss. 6.lcomm buffer, section.text. 8.globl _start.

Machine-level Representation of Programs. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

The Hardware/Software Interface CSE351 Spring 2013

EECS 213 Introduction to Computer Systems Dinda, Spring Homework 3. Memory and Cache

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College September 25, 2018

238P: Operating Systems. Lecture 3: Calling conventions. Anton Burtsev October, 2018

Chapter 4. The Processor Designing the datapath

Assembly Language: Function Calls

Systems I. Machine-Level Programming I: Introduction

EE 3170 Microcontroller Applications

Assembly Language: Function Calls" Goals of this Lecture"

ECE 341 Midterm Exam

ASSEMBLY II: CONTROL FLOW. Jo, Heeseung

6.1 Combinational Circuits. George Boole ( ) Claude Shannon ( )

Assembly Language: Function Calls" Goals of this Lecture"

complement) Multiply Unsigned: MUL (all operands are nonnegative) AX = BH * AL IMUL BH IMUL CX (DX,AX) = CX * AX Arithmetic MUL DWORD PTR [0x10]

Representation of Information

Assembly Language: Function Calls. Goals of this Lecture. Function Call Problems

Process Layout and Function Calls

CSE140: Components and Design Techniques for Digital Systems

CS61 Section Solutions 3

Using MMX Instructions to Perform Simple Vector Operations

SOEN228, Winter Revision 1.2 Date: October 25,

Assembly II: Control Flow. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

16.317: Microprocessor Systems Design I Fall 2015

Transcription:

Sample Exam I PAC II ANSWERS Please answer questions 1 and 2 on this paper and put all other answers in the blue book. 1. True/False. Please circle the correct response. a. T In the C and assembly calling convention that we used for this class, arguments to a function call are pushed in reverse (i.e. right-to-left) order. b. F In C, for the expression (x THE_MASK), where THE_MASK has at least one bit that is not zero, the result will be zero if all the bits of x are zero. c. T In x86 assembly, the instruction mov eax,[ebp+12] (or movl 12(%ebp),%eax in AT&T syntax) will add 12 to the value contained in the ebp register in order to compute a memory address. d. T In x86 assembly on a 32-bit machine, the instruction pop eax adds 4 to the value of the esp register. e. T In assembly, performing a right arithmetic shift operation, SAR, on a negative number results in a negative number. f. T Any circuit constructed using only AND, OR, or NOT gates can also be constructed using only NAND gates (which perform an AND and then a NOT). g. T Branch prediction is used to predict which way a conditional branch (jump) instruction will go in order to avoid pipeline stalls. h. F A multiplexer uses 2 N select lines to select from N input lines. i. T A 32-bit adder can be used for subtraction if each bit of the second operand is first sent through a (32-bit) NOT gate and the carry-in to the adder is set to 1. j. T In an unclocked latch, setting both the S and the R inputs to 0 will cause the output Q to retain its current value. 2. a. Write the number AB31 hex in binary: 1010 1011 0011 0001. b. Write the number 73 decimal in hex: 49 and in binary: 0100 1001. c. log 16G = 34. d. In order to access all bytes in a 64MB memory, an address must have at least 26 bits. 3. Write a C procedure, int foo(int x), that returns the index of the most significant bit of x whose value is 1. For example, if bit 15 of x is the most significant bit of x whose value is 1, then foo should return 15. If no bits are 1, then foo should return -1. int foo(int x) { int i; for(i=31;i>=0;i--) { if (x & (1<<i)) return i;

} } return -1; 4. Write an x86 assembly procedure bar that takes two parameters, an integer n and a pointer p to an integer array (i.e. p is the address of the start of the array), and adds up the first n integers of the array and returns the result. Intel Syntax _bar: push mov ebp ebp,esp mov eax,0 #result is initially 0 mov ecx,[ebp+8] #ecx holds n mov edx,[ebp+12] #edx holds p TOP: DONE: cmp ecx,0 #if n=0 je DONE #jump out of loop add eax,[edx] #result = result + *p dec ecx #n-- add edx,4 #p++ jmp TOP #jump to top of loop pop ret ebp AT&T Syntax _bar: push mov %ebp %esp,%ebp mov $0,%eax #result is initially 0 mov 8(%ebp),%ecx #ecx holds n mov 12(%ebp),%edx #edx holds p TOP: DONE: cmp $0,%ecx #if n=0 je DONE #jump out of loop add (%edx),%eax #result = result + *p dec %ecx #n-- add $4,%edx #p++ jmp TOP #jump to top of loop pop ret %ebp

5. a. Write in C a recursive version of the bubble sort procedure (hint: it should take as parameters an array a[] and an integer size that gives the size of the portion of the array that is currently unsorted). void bubble(int a[], int size) { if (size <= 1) return; int i; for(i=0;i<size-1;i++) //bubble the largest element to the end if(a[i] > a[i+1]) { int temp = a[i]; a[i] = a[i+1]; a[i+1] = temp; } bubble(a, size-1); //now sort the rest of array } b. Write the recurrence relation that gives the running time, T(n), of the bubble sort algorithm. T(1) = 1 T(n) = T(n-1) + (n-1) c. Solve the recurrence relation in order to determine the asymptotic complexity, expressed in big-oh notation, for bubble sort. T(n) = T(n-1) + (n-1) = T(n-2) + n-2 + n-1 = T(n-3) + n-3 + n-2 + n-1 = 1 + 2 +... + n-1 = n(n-1)/2 = O(n 2 ) 6. a. Build, from AND, OR, and NOT gates, a circuit that represents the two-bit less-than function. That is, it has two two-bit inputs, A and B, and a single one-bit output, R, such that R is true when A< B. [Hint: enumerate the possible inputs for which the output is true.] One way to do this is to write out the truth table, where the four inputs are A1 A0 B1 and B0, then generate the Boolean formula for those rows where the result is 1, simplify if possible, and then build the circuit according to the Boolean formula. Another way is to notice: If A = 00, then A < B if either bit of B is 1 If A = 01, then A < B if B1 is 1 If A = 10, then A < B if B=11 Encoding the above observations as a Boolean formula gives: R = ((NOT A1) AND (NOT A0) AND (B1 OR B0)) OR ((NOT A1) AND A0 AND B1) OR (A1 AND (NOT A0) AND B1 AND B0) Although this could be simplified a bit further, it is easy enough to build as is:

b. As you saw in class, a clocked latch is built from an unclocked latch as shown below. Why are flip-flops used for storing bits in a CPU rather than clocked latches? With a clocked latch, the value being stored (and output at Q) can change as long as the clock is up. In a system, such as the one illustrated below, where the data stored in a sequential circuit is being used as input to a combinational circuit (such as an ALU) and the output of the combinational circuit is being sent back to the combinational circuit for storage, if the sequential circuit consisted of clocked latches then, as long as the clock was up, the data coming in to the sequential circuit could overwrite the data that was stored while the combinational circuit is still performing its computation. What is needed instead, and provided by flip-flops, is for the data coming in to the sequential circuit to be prevented from overwriting the old data until the clock falls (and presumably, the combinational circuit has completed the computation). c. Build from gates, multiplexers, decoders, and/or adders (including 32-bit versions of each) a circuit that takes two 32-bit inputs, X and Y, and outputs the value of the larger of X and Y. That is, it computes the equivalent of the following C code: output = X>Y? X : Y;

The comparison is accomplished by performing a subtraction, Y-X, and then testing if the result is negative by using the highest bit of the result as the selector for a multiplexer whose inputs are X and Y. 7. As you probably remember from the project, the MIPS jalr instruction (jump-andlink, MIPS' version of the call instruction), jalr $rs has the following effect: register[31] = pc + 4 pc = register[rs] Build the data path for this instruction. Assume that the MIPS register file, the PC register, and any adder or ALU you want already exists (i.e. you don't need to build any of these, you can use them). Show all the wires that are involved in executing the instruction and be sure to the label the values that are carried on any wires that you draw.