CSE2421 FINAL EXAM SPRING Name KEY. Instructions: Signature

Similar documents
CS241 Computer Organization Spring 2015 IA

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

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

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

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

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

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

Instruction Set Architecture

Process Layout and Function Calls

The x86 Architecture

CS 3843 Final Exam Fall 2012

UMBC. A register, an immediate or a memory address holding the values on. Stores a symbolic name for the memory location that it represents.

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

Assembly Language: IA-32 Instructions

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

Credits and Disclaimers

CSE351 Spring 2018, Midterm Exam April 27, 2018

Sungkyunkwan University

The Hardware/Software Interface CSE351 Spring 2013

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

Instruction Set Architecture

Instruction Set Architecture

Machine Level Programming II: Arithmetic &Control

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

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

ASSEMBLY II: CONTROL FLOW. Jo, Heeseung

CS429: Computer Organization and Architecture

Chapter 4! Processor Architecture!

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

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

Machine-Level Programming II: Control and Arithmetic

Instruction Set Architectures

CS61 Section Solutions 3

Computer Organization Chapter 4. Prof. Qi Tian Fall 2013

Instruction Set Architecture

CISC 360 Instruction Set Architecture

MODE (mod) FIELD CODES. mod MEMORY MODE: 8-BIT DISPLACEMENT MEMORY MODE: 16- OR 32- BIT DISPLACEMENT REGISTER MODE

Chapter 3 Machine-Level Programming II Control Flow

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

Module 3 Instruction Set Architecture (ISA)

Instruction Set Architectures

Do not turn the page until 5:10.

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

Intro to GNU Assembly Language on Intel Processors

CS241 Computer Organization Spring Introduction to Assembly

cmovxx ra, rb 2 fn ra rb irmovl V, rb rb V rmmovl ra, D(rB) 4 0 ra rb D mrmovl D(rB), ra 5 0 ra rb D OPl ra, rb 6 fn ra rb jxx Dest 7 fn Dest

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

Addressing Modes on the x86

Access. Young W. Lim Fri. Young W. Lim Access Fri 1 / 18

Machine-Level Programming II: Control Flow

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

EXPERIMENT WRITE UP. LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM

Credits and Disclaimers

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

Access. Young W. Lim Sat. Young W. Lim Access Sat 1 / 19

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

CPS104 Recitation: Assembly Programming

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

Process Layout, Function Calls, and the Heap

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

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

Introduction to IA-32. Jo, Heeseung

INTRODUCTION TO IA-32. Jo, Heeseung

CS241 Computer Organization Spring Addresses & Pointers

Chapter 3 Machine-Level Programming II (Sections )

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

Complex Instruction Set Computer (CISC)

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

Credits to Randy Bryant & Dave O Hallaron

Intel x86-64 and Y86-64 Instruction Set Architecture

Assembly I: Basic Operations. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2016 Lecture 12

Machine-Level Programming Introduction

4/9/2018. Outline. Chapter 3 Machine-Level Programming II (Sections ) CISC instruction sets. RISC instruction sets. Compare Y86 and IA32

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

Condition Codes The course that gives CMU its Zip! Machine-Level Programming II Control Flow Sept. 13, 2001 Topics

Interfacing Compiler and Hardware. Computer Systems Architecture. Processor Types And Instruction Sets. What Instructions Should A Processor Offer?

MACHINE-LEVEL PROGRAMMING I: BASICS COMPUTER ARCHITECTURE AND ORGANIZATION

Machine Language, Assemblers and Linkers"

CF Carry Flag SF Sign Flag ZF Zero Flag OF Overflow Flag. ! CF set if carry out from most significant bit. "Used to detect unsigned overflow

The von Neumann Machine

System Programming and Computer Architecture (Fall 2009)

Condition Codes. Lecture 4B Machine-Level Programming II: Control Flow. Setting Condition Codes (cont.) Setting Condition Codes (cont.

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

Lecture 3: Instruction Set Architecture

Assembly I: Basic Operations. Computer Systems Laboratory Sungkyunkwan University

Reading assignment. Chapter 3.1, 3.2 Chapter 4.1, 4.3

Machine/Assembler Language Putting It All Together

Machine Programming 2: Control flow

IA-32 CSE 5302 Spring 2011 Ngoc Tam Tran

Assembly I: Basic Operations. Jo, Heeseung

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

ASSEMBLY I: BASIC OPERATIONS. Jo, Heeseung

x86 Assembly Tutorial COS 318: Fall 2017

Giving credit where credit is due

Procedure Calls. Young W. Lim Mon. Young W. Lim Procedure Calls Mon 1 / 29

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

CSE2421 Systems1 Introduction to Low-Level Programming and Computer Organization

Machine Programming 1: Introduction

Assembly Language Each statement in an assembly language program consists of four parts or fields.

Transcription:

CSE2421 FINAL EXAM SPRING 2013 Name KEY Instructions: This is a closed-book, closed-notes, closed-neighbor exam. Only a writing utensil is needed for this exam. No calculators allowed. If you need to go to the bathroom, get a drink or have a snack, do so prior to the start of the exam; you will not be allowed to leave the room until you are finished with your exam (i.e. once you leave, you are done); eating during the exam is prohibited. All cell phones and electronic equipment must be silenced and stored until after you leave the exam room. This is a timed exam. You have the university designated 1 hour 45 minute time frame with a start and end time as specified by the university and listed on your syllabus since the first day of the term. When time is called, you must stop writing immediately. Once the exam starts, and until every exam has been turned in, you will not talk with anyone in the classroom. In accordance with The Ohio State University Code of Student Conduct, I certify that I have neither received nor given aid on this examination, that I shall not discuss the contents of this examination with anyone in CSE 2421 who has not already taken the exam, and that I have not written down and taken from the room any questions or answers from this exam. You must read these instructions and sign your name below for this exam to be graded. Failure to follow any of these instructions will result in point penalization, up to and including a score of zero on the exam, to be determined by the instructor. Signature CSE2421 Spring 2013 Reeves Page 1

MULTIPLE CHOICE (8 pts) Fill in the blank (do NOT circle the letter!) IA32 and Y86 have the following in common EXCEPT: A. No memory to memory transfer with a single instruction B. 3 types of operands: immediate, register and memory C. Memory addressing including absolute, indirect, base+displacement, and indexed. D. Single-bit condition code registers. The IA-32 push instruction: A. adds 4 to the stack pointer then stores a value a value onto the stack B. stores a value onto the stack then adds 4 to the stack pointer C. subtracts 4 from the stack pointer then stores a value onto the stack D. stores a value onto the stack then subtracts 4 from the stack pointer The IA32 instruction, movl %esp, %ebp, can do all of the following at some point EXCEPT: A. moves the old base pointer onto the stack B. sets the stack pointer and the base pointer to the same location C. sets the base pointer to point to the bottom of the stack D. sets the starting point of a new frame on the stack The condition codes that result from adding two single-byte (i.e. signed char) values 0xAC and 0x8A on an IA32 machine are: A. ZF = 1, SF = 0, CF = 0, OF = 1 B. ZF = 0, SF = 0, CF = 1, OF = 1 C. ZF = 0, SF = 1, CF = 0, OF = 0 D. ZF = 1, SF = 0, CF = 1, OF = 1 The IA32 instructions jl and cmovl both have the same option to execute when certain condition codes are set, which is: A. D ZF B. D ~SF C. D SF ^ OF D. D ~(SF ^ OF) & ~ZF IA-32 implements a jump table for which of the following C constructs: A. For loop B. IF structure C. Switch statement D. None of the above The stack is used to: A. Pass function arguments B. Store local variables C. Save registers for later restoration D. All of the above The offset of each structure member is determined at: A. Compile time B. Assembly time C. Link time D. Execution CSE2421 Spring 2013 Reeves Page 2

TRUE/FALSE (8 pts) - Circle T or F for each statement T F The machine level program generated has no information about data types. T F A byte is the smallest addressable unit of memory. T F A disassembler is a tool that determines the instruction sequence represented by an executable program. T F Both IA32 and Y86 call statements/instructions push the return address onto the stack. T F Both IA32 and Y86 are considered load/store architectures. T F Relocatable object files do not yet have a starting address in memory. T F The IA32 cmpl instruction executes the same as the Y86 subl instruction. T F Conditional move statements in Y86 execute the movement operations according to condition codes. (4 pts) Determine if the following descriptions are generally considered true for CISC or RISC instruction sets by putting a C for CISC and an R for RISC. Fewer, simpler instructions (R) Arithmetic instructions can access memory (C) Variable length instructions (C) Stack intensive procedure/function linkages (C) SHORT ANSWER (8 pts) On a Little Endian machine that is byte addressable, show how the following values are stored in memory. FYI: A is 0x41 (in hex). NOTE: Only fill in the boxes that apply. That is, if you do not fill in the memory location, i.e. the value does not use the memory location, then be sure to leave it blank. Assume the starting memory location for value to be stored is 0x100. Value 0x100 0x101 0x102 0x103 ABC 41 42 43 \0 or empty 0x1234 34 12 empty empty (4 pts) Determine the pointer generated to point to the structure member a[2] in the given structure where the start of the structure is designated by address R, the size of an integer and a pointer are both 4 bytes, and IDX designates the subscript value (in this case, the 2 in a[2]). struct rec int i; int a[3]; int *p; r+4+4*idx CSE2421 Spring 2013 Reeves Page 3

(4 pts) Given the signed char value 0xAF, determine the binary byte value (i.e. not hex) for this byte in memory only, which remains after *each* of the following actions (start with the given value for each): Shift the value0xaf left by 3 1010 1111 to 0111 1000 Shift the value 0xAF right arithmetically by 2 1010 1111 to 1110 1011 (10 pts) Given the following initial values and IA32 instructions, use these initial values for each question given below (i.e. each question is based on the initial values, not any changes the previous question might or might not implement). A. movl 0x100, %eax What is stored in %eax? 0xFF B. movl (%eax,%edx,4), %ecx What is stored in %ecx? 0x11 C. decl %ecx What is stored in %ecx? 0x0 D. subl %edx, 4(%eax) Which value is changed? Be sure to designate the appropriate destination address that is changed and what value is stored there. Destination address is to value 0x104/0xA8 (6 pts) Give the IA-32 instruction format encoding (machine code) in hex notation for the following instructions where the opcode for part A is 0x8B, the opcode for part B is 0x8D, and the opcode for part C is 0x89: A. mov 0x8(ebp), %ecx 8B 4D 08 B. lea 0x4(%ecx,%eax,1),%eax 8D 44 01 04 C. mov %eax, (%ecx) 89 01 (4 pts) Why doesn t Y86 have a CF flag? (do not use more than the line given for your answer) Y86 does not have an unsigned option; Y86 is signed only; CF is for unsigned arithmetic (8 pts) The following function is called by function domath: int arith(int x, int y, int z) Assume that %ebp(1) to %esp to the left of the actual stack is the stack frame for the domath function. Fill in the 4 locations on the stack between the and %ebp(1) STACK Decreasing %esp, %ebp(2) %ebp(1) address return address x y z %ebp(1) CSE2421 Spring 2013 Reeves Page 4

CODE EVALUATION (4 pts) Given the following C code, fill in the blanks to create equivalent IA-32 code: int max(int x, int y) if (x > y) return x; else return y; movl 8(%ebp), %edx // where edx = x movl 12(%ebp), %eax // where eax = y %eax, %edx cmpl L9 jle movl %edx, %eax L9: // done (12 pts) Given the following C code, fill in the blanks to create equivalent IA-32 code: int fact_while(int x) int result = 1; while ( x > 1) result *= x; x = x - 1; return result; fact_while: pushl %ebp movl %esp, %ebp movl 8(%ebp), %edx movl $1, %eax cmpl $1, %edx jle.l3.l6: imull %edx, %eax subl $1, %edx jne.l6.l3: popl %ebp or jg ret CSE2421 Spring 2013 Reeves Page 5

(12 pts) Given the following C code, fill in the blanks to create equivalent Y86 code: // compute the sum of an // integer array int Sum(int *Start, int Count) int sum = 0; while (Count) sum += *Start; Start++; Count--; return sum; Sum: pushl %ebp rrmovl %esp, %ebp mrmovl 8(%ebp), %ecx mrmovl 12(%ebp), %edx xorl %eax, %eax andl %edx, %edx je End Loop: mrmovl (%ecx), %esi addl %esi, %eax irmovl $4, %ebx addl %ebx, %ecx irmovl $-1, %ebx addl %ebx, %edx jne Loop End: rrmovl %ebp, %esp popl %ebp ret also subl (8 pts) Convert the given leal instruction to an equivalent group of IA32 assembly instructions. Make sure that when the converted code is complete, both the leal instruction and the converted code have the same values in registers %eax, %ecx and %ebx. You cannot use any other registers besides the 3 given in the leal instruction. NOTE: any instruction you need here has an example in the above IA32 code evaluation questions. GIVEN: leal 0x4(%eax, %ecx, 8), %ebx movl %ecx, %ebx imull $8, %ebx addl %eax, %ebx addl $4, %ebx *** could switch first two movl $8, %ebx imull %ecx, %ebx *** could switch last two addl $4, %ebx addl %eax, %ebx CSE2421 Spring 2013 Reeves Page 6

CSE2421 Spring 2013 Reeves Page 7

IA32 integer registers Fast-access locations that the CPU uses, rather than storing all variables in memory (starts with e for extended) ORIGIN accumulator 31 ID# 15 8 7 0 %eax 0 %ax %ah %al counter %ecx 1 %cx %ch %cl data %edx 2 %dx %dh %dl base %ebx 3 %bx %bh %bl source index %esi 6 %si destination index %edi 7 %di STACK POINTER %esp 4 %sp BASE/FRAME POINTER %ebp 5 %bp ID=8 is no register THE VIRTUAL REGISTERS DO NOT HAVE AN ADDRESS ASSOCIATED WITH THEM 16-bit virtual registers (backward compatibility) CSE2421 Spring 2013 Reeves Page 8

All IA-32 instruction encodings Are subsets of the general instruction format shown below, in the given order Instructions consist of: optional instruction prefixes (in any order) 1-3 opcode bytes determines the action of the statement an addressing-form specifier (if required) consisting of: the ModR/M byte - addressing modes register/memory sometimes the SIB (Scale-Index-Base) byte a displacement (if required) an immediate data field (if required). Mod=00 First operand a register, specified by Reg # Second operand in memory; address stored in a register numbered by R/M. That is, Memory[Reg[R/M]] Exceptions: R/M=100 (SP): SIB needed R/M=101 (BP): disp32 needed Mod=01, same as Mod 00 with 8-bit displacement. Second operand: Memory[disp8+Reg[R/M]. Exception: SIB needed when R/M=100 Mod=10, same as Mod 01 with 32-bit displacement Mod=11 Second operand is also a register, numbered by R/M. Do not confuse displacement width with data width. Data width is specified by the opcode. For example, the use of disp8 does not imply 8-bit data. *** For some opcodes, the reg# is used as an extension of the opcode. Specify how a memory address is calculated Address = Reg[base] + Reg[Index] * 2 scale Exceptions: SP cannot be an index, and BP cannot be a base. CSE2421 Spring 2013 Reeves Page 9