Computer Science Final Examination Wednesday December 13 th 2006

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

COMPUTER ENGINEERING DEPARTMENT

Basic Pentium Instructions. October 18

Q1: Multiple choice / 20 Q2: Data transfers and memory addressing

16.317: Microprocessor Systems Design I Fall 2013

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB

We will first study the basic instructions for doing multiplications and divisions

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

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

EECE.3170: Microprocessor Systems Design I Spring 2016

Signed number Arithmetic. Negative number is represented as

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

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

16.317: Microprocessor Systems Design I Spring 2014

Lecture 9. INC and DEC. INC/DEC Examples ADD. Arithmetic Operations Overflow Multiply and Divide

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

Q1: Multiple choice / 20 Q2: Memory addressing / 40 Q3: Assembly language / 40 TOTAL SCORE / 100

The x86 Architecture

Q1: Multiple choice / 20 Q2: Protected mode memory accesses

22 Assembly Language for Intel-Based Computers, 4th Edition. 3. Each edge is a transition from one state to another, caused by some input.

/ 30 Q3: Arithmetic instructions / 30 Q4: Logical instructions / 20 TOTAL SCORE / 100 Q5: EXTRA CREDIT / 10

EC 333 Microprocessor and Interfacing Techniques (3+1)

ECOM Computer Organization and Assembly Language. Computer Engineering Department CHAPTER 7. Integer Arithmetic

COMPUTER ENGINEERING DEPARTMENT

Intel 8086: Instruction Set

Module 3 Instruction Set Architecture (ISA)

Marking Scheme. Examination Paper Department of CE. Module: Microprocessors (630313)

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

Reverse Engineering Low Level Software. CS5375 Software Reverse Engineering Dr. Jaime C. Acosta

Computer Architecture and Assembly Language. Practical Session 3

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

LAB 5 Arithmetic Operations Simple Calculator

Arithmetic Instructions

Scott M. Lewandowski CS295-2: Advanced Topics in Debugging September 21, 1998

Basic Assembly Instructions

Q1: Multiple choice / 20 Q2: Memory addressing / 40 Q3: Assembly language / 40 TOTAL SCORE / 100

Program Exploitation Intro

Practical Malware Analysis

Inline Assembler. Willi-Hans Steeb and Yorick Hardy. International School for Scientific Computing

Lab 4: Basic Instructions and Addressing Modes

Marking Scheme. Examination Paper. Module: Microprocessors (630313)

Chapter 3: Addressing Modes

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2016 Lecture 12

Instructions moving data

Integer Arithmetic Part2

3.1 DATA MOVEMENT INSTRUCTIONS 45

Assembly Language: IA-32 Instructions

Real Arithmetic. Fractional binary numbers. Fractional binary numbers examples. Binary real numbers

ADDRESSING MODES. Operands specify the data to be used by an instruction

Defining and Using Simple Data Types

Ex: Write a piece of code that transfers a block of 256 bytes stored at locations starting at 34000H to locations starting at 36000H. Ans.

Basic Execution Environment

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

Addressing Modes on the x86

Complex Instruction Set Computer (CISC)

IBM PC Hardware CPU 8088, Pentium... ALU (Arithmetic and Logic Unit) Registers. CU (Control Unit) IP.

Introduction to IA-32. Jo, Heeseung

We can study computer architectures by starting with the basic building blocks. Adders, decoders, multiplexors, flip-flops, registers,...

INTRODUCTION TO IA-32. Jo, Heeseung

CS241 Computer Organization Spring 2015 IA

Computer Architecture and System Programming Laboratory. TA Session 3

Build a program in Release mode and an executable file project.exe is created in Release folder. Run it.

16.317: Microprocessor Systems Design I Fall 2014

16.317: Microprocessor Systems Design I Spring 2015

Faculty of Engineering Computer Engineering Department Islamic University of Gaza Assembly Language Lab # 2 Assembly Language Fundamentals

LABORATORY WORK NO. 7 FLOW CONTROL INSTRUCTIONS

16.317: Microprocessor Systems Design I Fall 2015

Lecture (08) x86 programming 7

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

Registers. Ray Seyfarth. September 8, Bit Intel Assembly Language c 2011 Ray Seyfarth

CS61 Section Solutions 3

ELEC 242 Time Delay Procedure

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

db "Please enter up to 256 characters (press Enter Key to finish): ",0dh,0ah,'$'

Lab 3. The Art of Assembly Language (II)

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

Computer Systems Lecture 9

Digital Forensics Lecture 3 - Reverse Engineering

CSE2421 FINAL EXAM SPRING Name KEY. Instructions: Signature

6/20/2011. Introduction. Chapter Objectives Upon completion of this chapter, you will be able to:

Computer Architecture Prof. Smruti Ranjan Sarangi Department of Computer Science and Engineering Indian Institute of Technology, Delhi

Assembly Language Programming: Procedures. EECE416 uc. Charles Kim Howard University. Fall

CMSC 313 Lecture 07. Short vs Near Jumps Logical (bit manipulation) Instructions AND, OR, NOT, SHL, SHR, SAL, SAR, ROL, ROR, RCL, RCR

Faculty of Engineering Student Number:

Lab 2: Introduction to Assembly Language Programming

Assembly Language Lab # 9

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 7. Procedures and the Stack

An Introduction to x86 ASM

16.317: Microprocessor Systems Design I Fall 2013

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 10. Advanced Procedures

BAHAR DÖNEMİ MİKROİŞLEMCİLER LAB4 FÖYÜ

Integer Arithmetic. Shift and rotate. Overview. Shift and Rotate Instructions

Assembler Programming. Lecture 2

Week /8086 Microprocessor Programming I

CONTENTS. 1. Display a Message Display a one Digit Number Accept a Character from keyboard and display the character 4

Arithmetic and Logic Instructions And Programs

8086 Programming. Multiplication Instructions. Multiplication can be performed on signed and unsigned numbers.

Conditional Processing

CSE351 Spring 2018, Midterm Exam April 27, 2018

Transcription:

Computer Science 03-60-266 Final Examination Wednesday December 13 th 2006 Dr. Alioune Ngom Last Name: First Name: Student Number: INSTRUCTIONS EXAM DURATION IS 3 hours. OPEN NOTES EXAM: lecture notes, textbook, past exam solutions, and lab notes. Calculators (including your brain and fingers) are allowed. READ ALL QUESTIONS CAREFULLY BEFORE ANSWERING. Write all answers and work in the space provided. Use no other paper. WRITE YOUR FINAL ANSWERS WITH A PEN. There are 6 required questions (2 questions/hour). Answer all of them. QUESTION #7 is a bonus question. You are required to solve the first 6 questions. There are 20 pages. Count them before you start. If you need to make any assumptions, state them clearly with your answers. Write your answer neatly. Messy work is very hard to read and may cause you to lose marks. Q#1 Q#2 Q#3 Q#4 Q#5 Q#6 Total Q#7 (Page 2) (Page 4) (Page 6) (Page 8) (Page 10) (Page 12) (Page 14) 16 10 14 10 20 30 100 16 1

Question #1. (16 points) Write the following recursive Greatest Common Divisor program into ASM. public static long GCD(long a, long b) { If (b == 0) return a; Else return GCD(b, a % b); } Function GCD returns a value into EAX. Also, write a piece of the main program code that calls GCD. Assume that the Caller cleans the stack. 2

3

Question #2. (10 marks) Translate the following ASM function into a formula, or a pseudo-code or C, C++, Java. Sofint: PUSH EBP MOV EBP, ESP MOV EBX, [EBP + 8] CMP EBX, 1 JA Continue MOV EAX, 1 JMP Exit Continue: DEC EBX PUSH EBX CALL Sofint ; result in EAX ADD ESP, 4 MOV EBX, [EBP + 8] ADD EAX, EBX Exit: POP EBP RET ; EAX contains result Piece of the program that calls Sofint is.... MOV n, 4 ; n is a double-word PUSH n CALL Sofint ; result in EAX PUTINT EAX.... What does Sofint do? What is the printed value of EAX when n = 4? 4

5

Question #3. (14 marks) 1. Write the hexadecimal content of AX and the values of CF and OF flags, immediately after the execution of the instruction MUL AH, when AX = F8C7h? 2. Write the hexadecimal content of AX and the values of CF and OF flags, immediately after the execution of the instruction IMUL AH, when AX = F8C7h? 3. Write the hexadecimal content of the quotient and remainder registers, or write Divide Overflow if any, immediately after the execution of the instruction DIV BL, when AX = F8C7h and BL = FCh? 4. Write the hexadecimal content of the quotient and remainder registers, or write Divide Overflow if any, immediately after the execution of the instruction IDIV BL, when AX = F8C7h and BL = FCh? 5. Write the hexadecimal content of the destination register and the values of CF and OF flags, immediately after the execution of the instruction ADD AL, BL, when AL = F8h and BL = C7h? 6. Write the hexadecimal content of the destination register and the values of CF and OF flags, immediately after the execution of the instruction SUB AL, BL, when AL =F8h and BL = C7h? 6

7

Question #4. (10 marks) Complete the following data segment and its corresponding memory map.data SpNb1 DD 123.321 ; single-precision floating-point number SpNb2 DD ; single-precision floating-point number ; (fill in its decimal value) 0 1 2 3 0000 0004 3Ch D2h 1Eh F0h If necessary, limit the precisions to 7 digits after the dot. 8

9

Question #5. (20 marks) Write an ASM program which computes the formula x3 ac R = 1.2 cos( ) 4π Your program should use all 5 of the addressing modes shown on page 11 of chapter 10. Please specify an addressing mode by its initials (for instance, CSAM for Classical Stack Addressing Mode, RPAM for Register+Pop Addressing Mode,... ) beside the instruction that is using the addressing mode. See Lecture 10, Page 22, for instructions cos and?. Show all your FPU stack frames as I have done in lab. 10

11

Question #6. (30 marks) 1. How many bytes are contained in the following declaration? Var DD "AB", ABh, 10 DUP(10 DUP("AB"), 10 DUP(ABh), "AB", ABh) 2. Give the hexadecimal value of AH after SAR AH, 3 when AH = -32 initially. 3. Will this jump to Target? Circle Yes or No. MOV AX, 12EFh CMP AX, F1h JS Target 4. Which instructions are illegal? (Circle its letter) (a) PUSH AL (b) MOVZX AX, BX (c) MOV AL, WORD PTR [EBX] (d) ADD [AL], [CH] (e) INC 1Ah 5. The OF flag is updated only by arithmetic instructions. Circle True or False 6. Using CMP on two numbers will set the ZF flag if the operands are equal, but will not update the CF and OF flags. Circle True or False 7. ESP cannot be used to access the parameters of a procedure. Circle True or False 8. If 4 double-words parameters are passed to a procedure, then RET 4 will remove all the 4 parameters from the ASM stack upon returning from the procedure. Circle True or False 9. Upon execution of JMP Next (where label Next is defined in a separate file F1 and specified as public), the CPU will jump to the instruction labeled by Next in file F1. Is this allowed in ASM? Circle True or False. 10. The arithmetic instructions of the FPU, such as FADD, FSUB,..., will update the EFLAGS register upon their execution. Circle True or False 12

13

BONUS Question #7. (?? points) This question is not required. Write a program that uses a for-loop to calculate the first 20 values in the Fibonacci number sequence, {0, 1, 1, 2, 3, 5, 8, 13,...}. That is, your program is non-recursive. Your data segment should at least define an array of byte integers called Fibo. By definition, we have Fibo[0] = 0, Fibo[1] = 1, Fibo[2] = 1 and Fibo[k] = Fibo[k-2] + Fibo[k-1] for k > 2. Register ESI should initially contain the offset address of Fibo. Correct answer to this question will be used to fix your mark, only if it is necessary. 14

15

Space for Scrap Work 16

Space for Scrap Work 17

Space for Scrap Work 18

Space for Scrap Work 19

Space for Scrap Work 20