CS 3843 Final Exam Fall 2012

Similar documents
CSE2421 FINAL EXAM SPRING Name KEY. Instructions: Signature

CS241 Computer Organization Spring 2015 IA

System Programming and Computer Architecture (Fall 2009)

CS , Fall 2001 Exam 1

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

CSE351 Autumn 2014 Midterm Exam (29 October 2014)

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

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

Assembly level Programming. 198:211 Computer Architecture. (recall) Von Neumann Architecture. Simplified hardware view. Lecture 10 Fall 2012

CS61, Fall 2012 Midterm Review Section

CS , Fall 2004 Exam 1

4) C = 96 * B 5) 1 and 3 only 6) 2 and 4 only

CSE351 Autumn 2012 Midterm Exam (5 Nov 2012)

CSE351 Autumn 2014 Midterm Exam (29 October 2014)

CS3330 Exam 1 Spring Name: CS3330 Spring 2015 Exam 1 Page 1 of 6 ID: KEY

Introduction to Computer Systems. Exam 1. February 22, Model Solution fp

Chapter 4 Processor Architecture: Y86 (Sections 4.1 & 4.3) with material from Dr. Bin Ren, College of William & Mary

Computer Organization Chapter 4. Prof. Qi Tian Fall 2013

Instruction Set Architecture

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

EECS 213 Fall 2007 Midterm Exam

Sungkyunkwan University

Process Layout and Function Calls

Assembly Language: IA-32 Instructions

Full Name: CISC 360, Fall 2008 Example of Exam

CS61 Section Solutions 3

CS429: Computer Organization and Architecture

Assembly Language: Function Calls

CS241 Computer Organization Spring Introduction to Assembly

Question 4.2 2: (Solution, p 5) Suppose that the HYMN CPU begins with the following in memory. addr data (translation) LOAD 11110

Process Layout, Function Calls, and the Heap

Assembly Language: Function Calls" Goals of this Lecture"

Introduction to Computer Systems. Exam 1. February 22, This is an open-book exam. Notes are permitted, but not computers.

Instruction Set Architecture

CS220 Logic Design AS06-Advanced Assembly. AS06-Advanced Assembly Shift Operations. AS06-Advanced Assembly Shift Operations

Instruction Set Architecture

15-213/18-213, Fall 2011 Exam 1

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

Assembly Language: Function Calls" Goals of this Lecture"

Assembly I: Basic Operations. Computer Systems Laboratory Sungkyunkwan University

CS , Spring 2004 Exam 1

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

Datorarkitektur, 2009 Tentamen

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

X86 Stack Calling Function POV

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

Instruction Set Architecture

CISC 360 Instruction Set Architecture

Machine-Level Programming II: Control and Arithmetic

Questions about last homework? (Would more feedback be useful?) New reading assignment up: due next Monday

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

Chapter 4! Processor Architecture!

Assembly I: Basic Operations. Jo, Heeseung

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

ASSEMBLY I: BASIC OPERATIONS. Jo, Heeseung

Representation of Information

Do not turn the page until 5:10.

Do not turn the page until 5:10.

This is a medical robot, guided by a skilled surgeon and designed to get to places doctors are unable to reach without opening a pacent up.

CPS104 Recitation: Assembly Programming

CPEG421/621 Tutorial

Credits and Disclaimers

Machine Programming 1: Introduction

Meet & Greet! Come hang out with your TAs and Fellow Students (& eat free insomnia cookies) When : TODAY!! 5-6 pm Where : 3rd Floor Atrium, CIT

CSE351 Spring 2018, Midterm Exam April 27, 2018

ASSEMBLY III: PROCEDURES. Jo, Heeseung

UW CSE 351, Winter 2013 Midterm Exam

Assembly III: Procedures. Jo, Heeseung

Instructor: Alvin R. Lebeck

Procedure Calls. Young W. Lim Sat. Young W. Lim Procedure Calls Sat 1 / 27

CIS 2107 Computer Systems and Low-Level Programming Spring 2012 Final

Credits to Randy Bryant & Dave O Hallaron

CSE 351 Midterm Exam Spring 2016 May 2, 2015

Machine-Level Programming II: Arithmetic & Control /18-243: Introduction to Computer Systems 6th Lecture, 5 June 2012

CS241 Computer Organization Spring Addresses & Pointers

Lecture 15 Intel Manual, Vol. 1, Chapter 3. Fri, Mar 6, Hampden-Sydney College. The x86 Architecture. Robb T. Koether. Overview of the x86

Assembly III: Procedures. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Homework. In-line Assembly Code Machine Language Program Efficiency Tricks Reading PAL, pp 3-6, Practice Exam 1

Machine-Level Programming II: Arithmetic & Control. Complete Memory Addressing Modes

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

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2016 Lecture 12

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

Homework 0: Given: k-bit exponent, n-bit fraction Find: Exponent E, Significand M, Fraction f, Value V, Bit representation

CSCI 192 Engineering Programming 2. Assembly Language

CMSC 313 Fall2009 Midterm Exam 2 Section 01 Nov 11, 2009

Function Calls COS 217. Reading: Chapter 4 of Programming From the Ground Up (available online from the course Web site)

Handout #2: Machine-Level Programs

Second Part of the Course

Machine Programming 2: Control flow

Machine-level Programming (3)

CSCI 2121 Computer Organization and Assembly Language PRACTICE QUESTION BANK

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

Reading assignment. Chapter 3.1, 3.2 Chapter 4.1, 4.3

Machine Level Programming II: Arithmetic &Control

CS213. Machine-Level Programming III: Procedures

Practical Malware Analysis

Chapter 3 Machine-Level Programming II Control Flow

CPSC W Term 2 Problem Set #3 - Solution

Software. Hardware. x86 basics. ISA View. a brief history of x86 10/6/15. Program, Application. Programming Language. Compiler/Interpreter

Transcription:

CS 3843 Final Exam Fall 2012 Name (Last), (First) ID Please indicate your session: Morning Afternoon You may use a calculator and two sheets of notes on this exam, but no other materials and no computer. This test has a full score of 120 points. Answer question worth 110 points or more. The exam will be graded for a maximum score of 110 points. Show all the major steps in your work to receive partial credits. Problem 1 (14 points) (a) (1 point) Convert to decimal number: 0xA9C4 Sol: 0xA9C4 = 10 16 3 +9 16 2 +12 16+4= 43460 (b) (1 point) Convert to binary: 0xC7EF Sol: 0xC7EF = (1100,0111, 1110, 1111) 2 (c) (2 point) Convert from decimal to hexadecimal and binary: 2617 Sol: 2617 = 10 16 2 + 3 16+9= 0xA39 Convert to binary= (1010, 0011, 1001) 2 (d) (4 points) Convert decimal number 382.45 to octal number (base 8) (hint: Division and Multiply method for converting integer and fraction part) Sol: 1) integer part 382 = (576) 8 382= 5*8 2 +7*8+6 2) fraction part.45= (.34631,4631,4631,...) 8.45.60.80.40.20.60 8 8 8 8 8 8 -------- -------- ------ ----- ----- ----- (3).6 (4).8 (6).4 (3).2 (1).6 (4).8... Therefore 382.45 =(576.34631,4631,4631,...) 8 1

(e) (3 points) Use a 10-bit word, find the binary representation of -456 in i) two's complement ii) one's complement iii) sign-magnitude Sol: 456=(01,1100,1000) 2 = N i) N*=(10,0011,1000) 2 ii) = (10,0011,0111) 2 iii) N =(11,1100,1000) 2 (f) (3 points) repeat problem (e) using a 12-bit word. Sol: 456=(0001,1100,1000) 2 = N i) N*=(1110,0011,1000) 2 ii) = (1110,0011,0111) 2 iii) N =(1001,1100,1000) 2 Problem 2 (9 points) Assume x = 0xFDC4 and y=0x79a8, what is the following value: (a) (1.5 points) ~x = ~0xFDC4 = (0000, 0010, 0011, 1011) 2 y = 0x79A8 = (0111, 1001, 1010, 1000) 2 ~x & y = (0000, 0000, 0010, 1000) 2 = 0x28 (b) (1.5 points) x ~y x = 0xFDC4 = (1111, 1101, 1100, 0100) 2 ~y = ~0x79A8 = (1000, 0110, 0101, 0111) 2 x ~y = (1000, 0100, 0100, 0100) 2 = 0x8444 (c) (1.5 points) ~x & ~y ~x = ~0xFDC4 = (0000, 0010, 0011, 1011) 2 ~y = ~0x79A8 = (1000, 0110, 0101, 0111) 2 ~x ~y = (0000, 0010, 0001, 0011) 2 = 0x213 2

(d) (1.5 points) x && y x && y = TURE && TRUE = TRUE =0x1 (e) (1.5 points) x &! y x &! y = x &!TRUE = x & FALSE = x & 0 = 0 (f) (1.5 points) x ~ y x ~ y = TRUE TRUE = TRUE= 0x1 Problem 3 (12 points) Consider the following two 7-bit floating point representations based on the IEEE floating point format. Neither has a sign bit - they can only represent non-negative numbers. i). Format A. There are k=3 exponent bits. The exponent bias is 3. There are n=4 fraction bits. ii). Format B. There are k=4 exponent bits. The exponent bias is 7. There are n=3 fraction bits. Below, you are given some bit patterns in Format A, and your task is to convert them to the closest value in Format B. If necessary, you should apply the round-to-even rounding rule. In addition, give the values of numbers given by the Format A and Format B bit patterns. Give these as whole numbers (e.g., 17) or as fractions (e.g., 17/64). Format A Format B Bits Value Bits Value 011,0000 1 0111,000 1 101,1110 15/2 1001,111 15/2 010,1001 25/32 0110,100 ¾ 110,1111 31/2 1011,000 16 3

Problem 4 (12 points) Consider a hypothetical 10-bit IEEE floating point representation: ----------------------------------------------- s (1 bit) exp ( 5 bits) frac (4 bits) ----------------------------------------------- a) (2 points) What is the bias? b) (2 points) How many different values can be represented with 10 bits? c) (2 points) What is the smallest positive normalized value? d) (2 points) What is the largest positive normalized value? e) (2 points) What is the largest positive denormalized value? f) (2 points) What is the floating-point representation for 1.0? Sol: a) bias = 2 k-1-1=2 5-1 -1=2 4-1=15 b) 2 10 =1024 c) V = (-1) s M 2 E, s=0: positive value, E = exp-bias = (00001) 2-15=1-15=14 M=1+frac 2 -n =1+(0000) 2-4 =1.0 smallest normalized positive value = 1.0*2-14 =1/(2 14 ) d) largest normalized positive value s = 0, exp!=00000 and exp!=11111, exp=(11110) 2 =16+8+4+2=30 E=exp-bias=30-15=15, frac = (1111) 2 M = 1 + frac 2-4 =1+0.1111=1.1111=1+1/2+1/4+1/8+1/16=29/16 therefore, V = (-1) 0 29/16 2 E =29/16 2 15 = (1.1111) 2 15 =(1111,1000,0000,0000) 2 (e) largest denormalized value s = 0, exp =00000, frac = 1111 M=frac 2 4 =0.111, E=1-bias=1-15=14; V = M 2 E =0.1111 2-14 =(00, 0000, 0000, 0000, 1111) 2 f) V = 1.0= (-1) 0 1.0 2-0 s = 0, M = 1.0, E=0 E = 0 = exp - bias => exp = bias = 15 = (01111) 2 M = 1 + frac 2-4 =1.0 => frac = (0000) 2 therefore, 1.0 = s k=5 n=4 4

Problem 5 (8 points) For each of the following values of K, find ways to express x*k using only the specified number of operations, where we consider both additions and subtractions to have comparable cost. K shifts Add/Subs Expression 28 2 1 (x<<5)-(x<<2) 63 1 1 (x<<6)-x -12 2 1 (x<<2)-(x<<4) 97 2 2 (x<<7)-(x<<5)+x Problem 6 (9 points) Assume the following values are stored at the indicated memory addresses and registers Address Value Register Value 0x200 0x3A %eax 0x200 0x204 0x45 %ecx 0x08 0x208 0x3D %edx 0x03 0x20C 0x11 0x210 0x2F 0x214 0x09 a) (4 points) Fill the following table: Operand Value Operand Value 12(%eax) 0x11 4(%eax, %edx, 4) 0x09 4(%eax, %ecx) 0x11 0x1F0(, %edx, 8) 0x3D -3(%eax, %edx) 0x3A 0x200(%ecx, %edx, 4) 0x09 leal -0x10(%eax, %ecx, 8), %edx 0x206 leal 0xFC(%ecx), %edx 0x107 b) (5 points) Fill in the following table Instruction Destination Value xorl %edx, %ecx %ecx 0x0B subl %ecx, %edx %edx 0x05 addl %edx, 4(%eax, %ecx, 2) 0x214 0x0C imul $4, (%eax, %edx, 4) 0x20C 0x44 incl 0x8(%eax) 0x208 0x3E 5

Problem 7 (14 points) Fill in the following table. Assume that x and y are of a new type short integer which is 12 bits. Enter the value of (y-x) in decimal. This is the value that would be stored in z if short z = y - x; Consider the instruction: cmpw %eax, %ecx (2 points each) Fill in the value of the flags if %eax contains x and %ecx contains y. x y z = y - x ZF SF OF CF 15 7 7-15=-8(signed) 0 1 0 0-7 15 15-(-7)=22 (signed) 15-4089=-4074 (unsigned) -7-7 7 0x7fe (-7)-(-7)=0 2046-7=2039 7-0x7fe -2046-7=-2053(signed) 2050-7=2043(unsigned) 0x7fe 7 0x7fe 7-2046=-2039-7 -7-2046=-2053(signed) 4089-2046=2043 (unsigned) 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 1 0 Problem 8 (12 points) Please check whether the following instruction is TRUE or FALSE, and if FALSE, and what s wrong with each line? 1) movl %edx, 0xFD(%eax) TURE (X ) FALSE ( ) 2) movl (%ecx), 0xC(%esp) TURE ( ) FALSE (X) Ans: Cannot have both source and destination be memory address. 3) movb $0xFF, (%ah) TURE ( ) FALSE (X) Ans: Cannot use %al as address register 6

4) movw %ecx, (%edx) TURE ( ) FALSE (X) Ans: Mismatch between instruction suffix and register ID. 5) movb %cl, %dx TURE ( ) FALSE (X) Ans: Destination operand incorrect size. 6) movw %ax, $0xCD TURE ( ) FALSE (X) Ans: Cannot have immediate as destination Problem 9 (20 points) i) (5 points) comment each assembly instruction C Code (caller.c) int caller() { int arg1 = 38; int arg2 = 125; int diff = swap_subs(&arg1, &arg2); } int sum = arg1 + arg2; return sum+diff; Here is the assembly code generated: caller: pushl %ebp movl %esp, %ebp // Place your comments below subl $24, %esp // allocate 6 words on the stack movl $38, -4(%ebp) // 38 on the stack movl $125, -8(%ebp) // 125 on the stack leal -8(%ebp), %eax // &125 into %eax movl %eax, 4(%esp) // &125 on stack leal -4(%ebp), %eax // &38 into %eax movl %eax, (%esp) // &38 on stack call swap_subs.r1 addl -8(%ebp), %eax // %eax = %eax(diff) + 38; addl -4(%ebp), %eax // %eax += 125 leave // restore the stack pointer ret 7

C Code(swap_subs.c) int swap_subs(int *arg1, int *arg2) { int tmp = *arg1; *arg1 = *arg2; *arg2 = tmp; return *arg1 - *arg2; } Here is the assembly code generated: swap_subs: pushl %ebp movl %esp, %ebp pushl %ebx // Place your comments below movl 8(%ebp), %edx // arg1 into %edx movl 12(%ebp), %ecx // arg2 into %ecx movl (%edx), %ebx // %ebx = *arg1; movl (%ecx), %eax // %eax = *arg2 movl %eax, (%edx) // *arg1 = *arg2; movl %ebx, (%ecx) // *arg2 = *arg1; movl (%edx), %eax // %eax = *arg2(old); subl %ebx, %eax // %eax = *arg2(old) - *arg1(old) popl %ebx popl %ebp ret ii) (8 points) Fill the stack with the missing values for the procedure above. The current %esp = 0x1004 address Stack Bottom (10 points) 1004 1000 old %ebp FFC 38 125 FF8 125 38 FF4 FF0 FEC FF8 FE8 FFC FE4.R1 FE0 1000 FDC old %ebx Stack Top iii) (7 points) Keep track of register values: %eax, %ebx, %ecx, %edx, %ebp, %esp %eax FF8 FFC 125 125 87 125 250 %ebx 38 %ecx %edx FF8 FFC %ebp 1000 FE0 1000 Old %ebp %esp 1000 FE8 FE4 FE0 FDC FE0 FE4 FE8 1000 8

Problem 10 (10 points) For each byte sequence listed, determine the Y86 instruction sequences it encodes. If there is some invalid byte in the sequence, show the instruction sequence up to that point and indicate where the invalid value occurs. For each sequence, we show that the starting address, then a colon, and then the byte sequence. 0x100: 30F30F00000020314013FDFFFFFF60317008010000 Sol:.pos 0x100 # start code at address 0x100 irmovl $15, %ebx # load 15 into %ebx 0x100: 30f30f000000 rrmovl %ebx, %ecx # copy 15 to %ecx 0x106: 2031 loop: # loop 0x108: rmmovl %ecx, -3(%ebx) # save %ecx at address 15-3=12 0x108: 4013fdffffff addl %ebx, %ecx # increment %ecx by 15 0x10e: 6031 jmp loop # Goto loop 0x110: 7008010000 9