COMPUTER ENGINEERING DEPARTMENT

Similar documents
COMPUTER ENGINEERING DEPARTMENT

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

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

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

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

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

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

Lab 6: Conditional Processing

16.317: Microprocessor Systems Design I Fall 2014

Week /8086 Microprocessor Programming

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

Week /8086 Microprocessor Programming II

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

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

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.

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

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

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

Conditional Processing

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

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

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

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

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 8. Conditional Processing

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

Chapter 7 Integer Arithmetic

Lecture (08) x86 programming 7

16.317: Microprocessor Systems Design I Fall 2013

Assembly Language: IA-32 Instructions

PESIT Bangalore South Campus

Lab 5: Input/Output using a Library of Procedures

Module 3 Instruction Set Architecture (ISA)

CS-202 Microprocessor and Assembly Language

Computer Architecture and Assembly Language. Practical Session 3

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

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

3.1 DATA MOVEMENT INSTRUCTIONS 45

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

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

The x86 Architecture

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 5: Procedures. Chapter Overview. The Book's Link Library

Chapter 3: Addressing Modes

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

16.317: Microprocessor Systems Design I Spring 2015

16.317: Microprocessor Systems Design I Fall 2015

UNIVERSITY OF CALIFORNIA, RIVERSIDE

Assembly Language Lab # 9

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

EEM336 Microprocessors I. Addressing Modes

UMBC. 1 (Feb. 9, 2002) seg_base + base + index. Systems Design & Programming 80x86 Assembly II CMPE 310. Base-Plus-Index addressing:

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

.code. lea dx,msg2. Page 1/8. Problem 1: Programming in Assembly [25 Points]

Introduction to IA-32. Jo, Heeseung

INTRODUCTION TO IA-32. Jo, Heeseung

Proposed Common Configuration Method

Libraries and Procedures

EC 333 Microprocessor and Interfacing Techniques (3+1)

Reverse Engineering II: Basics. Gergely Erdélyi Senior Antivirus Researcher

A4 Sample Solution Ch3

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

Libraries and Procedures

Reverse Engineering II: The Basics

Lab 3. The Art of Assembly Language (II)

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

Reverse Engineering II: The Basics

CSE351 Spring 2018, Midterm Exam April 27, 2018

8086 INSTRUCTION SET

Microprocessors ( ) Fall 2010/2011 Lecture Notes # 15. Stack Operations. 10 top

Basic Execution Environment

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

Intel 8086: Instruction Set

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

CPS104 Recitation: Assembly Programming

Q1: Define a character string named CO_NAME containing "Internet Services" as a constant?

Complex Instruction Set Computer (CISC)

Computer Science Final Examination Wednesday December 13 th 2006

Philadelphia University Student Name: Student Number:

Basic Assembly Instructions

ELEC 242 Time Delay Procedure

COE 205. Computer Organization and Assembly Language Dr. Aiman El-Maleh

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

Basic Pentium Instructions. October 18

Logic Instructions. Basic Logic Instructions (AND, OR, XOR, TEST, NOT, NEG) Shift and Rotate instructions (SHL, SAL, SHR, SAR) Segment 4A

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

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

Lab 3: Defining Data and Symbolic Constants

UMBC. contain new IP while 4th and 5th bytes contain CS. CALL BX and CALL [BX] versions also exist. contain displacement added to IP.

Branching and Looping

Instructions moving data

Experiment 8 8 Subroutine Handling Instructions and Macros

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

LABORATORY WORK NO. 7 FLOW CONTROL INSTRUCTIONS

An Introduction to x86 ASM

Week /8086 Microprocessor Programming I

SOEN228, Winter Revision 1.2 Date: October 25,

CS241 Computer Organization Spring 2015 IA

mith College Computer Science CSC231 Assembly Week #11 Fall 2017 Dominique Thiébaut

Defining and Using Simple Data Types

Program Exploitation Intro

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

Transcription:

Page 1 of 11 COMPUTER ENGINEERING DEPARTMENT December 31, 2007 COE 205 COMPUTER ORGANIZATION & ASSEMBLY PROGRAMMING Major Exam II First Semester (071) Time: 7:00 PM-9:30 PM Student Name : KEY Student ID. : Question Max Points Score Q1 30 Q2 10 Q3 25 Q4 15 Q5 20 Total 100 Dr. Aiman El-Maleh

Page 2 of 11 [30 Points] (Q1) Determine whether the following is true or false, and if it is false correct it: (1) (True, False) Assume that the instruction JMP NEXT is at offset address 000000A1H in the code segment, its size is 2 bytes, and the label NEXT is at offset 00000020H. Then, the address stored in the assembled instruction for the label NEXT is 7DH. The address stored = NEXT IP = 20h (A1h + 2) = 20h A3h = 20h + 5Dh = 7Dh. (2) (True, False) After executing the instruction SAL AX, 2, the content of register AX is equal to 2*AX, for both signed and unsigned content. It is equal 2 2 *Ax=4*AX. (3) (True, False) Assuming that EBX=FFFFFFFE and ESI=00000010, the address of the source operand in this instruction MOV AL, [EBX+ESI*2-5] is 00000019 and its addressing mode is Indexed. The address of the sourse operand is FFFFFFFE + 00000010*2 5 = -2 + 32 5 = 25d = 00000019h. The addressing mode is Based Indexed. (4) (True, False) Given that EAX=FFFF5783, executing the instruction CWD will make the content of EAX=00005783. EAX will not change. DX will be set to 0000. (5) (True, False) The conditional jump instructions JB and JC are equivalent. (6) (True, False) The instruction IN CL, DX inputs the byte whose port address is in DX to register CL. We cannot use CL in the desitination. The desination must be AL, AX or EAX. (7) (True, False) The code given below implements the conditional statement if ((CX < 1) AND (AX > 100)) Then CX=0 CMP CX, 1 JL Zero_index CMP AX, 100 JLE end_if Zero_index: XOR CX, CX End_if: It implements if ((CX < 1) OR (AX > 100)) Then CX=0.

Page 3 of 11 (8) (True, False) Assuming that AX=0FFFH and BX=100F, executing the instruction SHLD AX, BX, 4 will set AX=FFF1 and BX=00F0. BX will not change and its value remians 100FH. (9) (True, False) The interrupt flag (IF) is used to mask all kinds of interrupts. It is used to mask only maskable hardware interrupts. (10) (True, False) The address of the interrupt service routine for INT 21H is stored in the interrupt vector table (IVT) at entry 84H. The address is 21h*4 = 84h. (11) (True, False) Assuming that AL contains an Alphabatic character, the instruction AND AL, 0DFH will guarantee that the character in AL is an upper case character. Note that the ASCII code of character A is 41H while that of character a is 61H. (12) (True, False) Assuming that AL=91H, executing the instruction SAR AL, 33 will make AL=48H. AL is shifted by one bit to the right. Thus, AL=1100 1000B=C8H. (13) (True, False) Assuming that AX=1234H and DX=0001H, executing the sequence of instructions: {PUSH DX; PUSH AX; POP EAX} will result in EAX=00011234H. (14) (True, False) Assuming that AX=00F2H and BX=0008H, executing the instruction DIV BL will result in AX=1E02H. It will result in AX=021E. (15) (True, False) Executing the instruction IRET pops one double word from the stack and stores it into EIP. It pops a double word and stores in the EIP register, then pops a word and stores in CS register and finally it pops a double word and stores it in EFLAGS register.

Page 4 of 11 [10 Points] (Q2) Suppose that you have the following initial content of registers and memory after fetching each of the instructions shown below: EAX=00001F20H EBX=FFFFFC55H ESP=00001000H EIP=000030B0H Determine the content of ESP, modified registers, modified flags, and modified memory locations after the execution of each of the following instructions starting from the initial content of the registers and memory for the execution of each instruction. (i) POP EAX. (ii) PUSH BX. (iii) Call Sub, where Sub is at an offset address 00001000H. (iv) RET 2. (i) POP EAX EAX = 90807060 ESP=ESP+4=00001000+4=00001004 (ii) PUSH BX ESP=ESP-2=00001000-2=00000FFE [00000FFF:00000FFE]=FC55 Memory Location Content 00000FFA FF 00000FFB 10 00000FFC 20 00000FFD 30 00000FFE 40 00000FFF 50 00001000 60 00001001 70 00001002 80 00001003 90 00001004 A0 00001005 B0 00001006 C0 (iii) Call Sub ESP=ESP-4=00001000-4=00000FFC [00000FFF:00000FFC]=EIP=000030B0 EIP=00001000 (iv) RET 2 EIP=90807060 ESP=ESP+4+2=00001000+6=00001006

Page 5 of 11 [25 Points] (Q3) Answer the following questions. Show how you obtained your answer: (i) Given that TABLE1 and TABLE2 are defined as: TABLE1 BYTE I like COE 205 TABLE2 BYTE I like COE 308 Determine the content of AX after executing the following code: AGAIN: DONE: MOV ECX, lengthof TABLE1 MOV EBX, -1 XOR AX, AX JECXZ DONE INC EBX MOV DL, TABLE1[EBX] CMP DL, TABLE2[EBX] LOOPE AGAIN JE DONE INC AX JMP AGAIN The content of register AX will be 2 as the program counts the number of mismatch characters between the two tables. (ii) Given that ARRAY is defined as: ARRAY BYTE ABCDEF Determine the content of ARRAY after executing the following code: REP PUSH DS POP ES STD LEA ESI, ARRAY[4] LEA EDI, ARRAY[5] MOV BH, [EDI] MOV ECX, 5 MOVSB MOV [EDI], BH The content of ARRAY wil be FABCDE.

Page 6 of 11 (iii) Given that TABLE is defined as shown below: TABLE BYTE 16 DUP(?) Determine the content of TABLE after executing the following code: AGAIN: MOV AX, 0E765H MOV ECX, 16 LEA EBX, TABLE XOR DL, DL ROL AX, 1 ADC DL, 0 MOV [EBX], DL INC EBX LOOP AGAIN The content of TABLE will be 1110011101100101 as this program stores the binary content of register AX in TABLE. (iv) Next: Again: Determine the content of register EAX after exeucting the following code: MOV EAX, 739 MOV EBX, 10 XOR ECX, ECX XOR EDX, EDX DIV EBX ADD ECX, EDX TEST EAX, EAX JNZ Again MOV EAX, ECX CMP EAX, 9 JA Next The content of EAX will be 1. The program adds individual digits of the number in EAX to get another integer.this process is repeated until a single digit is obtained. Thus, initially 7+3+9=19. Then, 1+9=10. Finally, 1+0=1.

Page 7 of 11 (v) Determine the content of register EAX after executing the fllowing code:.686.model FLAT, STDCALL.STACK INCLUDE Irvine32.inc.DATA TABLE DWORD -10, 20, 30, -50, 66, 12, 330, 1.CODE main PROC PUSH offset TABLE ; pushed as 32-bit PUSH lengthof TABLE ; pushed as 32-bit CALL MYPROC exit main ENDP MYPROC: MOV EBP, ESP PUSH EBX PUSH ECX MOV ECX, [EBP+4] MOV EBX, [EBP+8] MOV EAX, [EBX] DEC ECX ADD EBX, 4 NEXT: CMP EAX, [EBX] JL SKIP MOV EAX, [EBX] SKIP: ADD EBX, 4 LOOP NEXT POP ECX POP EBX RET 8 END main The content of register EAX will be FFFFFFCE=-50d as the program computes the minimum of the elements of TABLE.

Page 8 of 11 [15 Points] (Q4) (i) Write a procedure DISPAVG that receives as arguments the address of an array of unsigned integers (i.e. DWORD), Array, and the number of elements in the array, Size. The procedure will then compute the average of the numbers in the array and display it within a single decimal fraction digit. The procedure should preserve the content of all registers used. (ii) Use the procedure DISPAVG to display the average of the given array Array DWORD 15, 20, 30, 40 Note that your procedure should display the following in a new line: Average = 26.2 Note that the procedure WriteDec can be used for displaying the content of EAX in unsigned decimal format to standard output. The procedure WriteString writes a null-terminated string whose address is stored in EDX to standard output. The procedure WriteChar writes the character in register AL to standard output. The procedure Crlf writes end of line sequence (CR, LF) to standard output..686.model FLAT, STDCALL.STACK INCLUDE Irvine32.inc.DATA Array DWORD 15, 20, 30, 40.CODE main PROC MOV ESI, offset Array MOV ECX, lengthof Array CALL DISPAVG exit ; exit to operating system main ENDP

Page 9 of 11 ;------------------------------------------------------------------------ ; DISPAVG: Computes the average of an array of integers ; Receives: ESI = pointer to an array of doublewords ; ECX = number of array elements ; Returns: Displays the average upto a single decimal digit ;------------------------------------------------------------------------ DISPAVG PROC PUSHAD MOV EBX, ECX ; display message LEA EDX, MSG CALL WriteString ; compute the average XOR EAX, EAX Next: ADD EAX, [ESI] ; compute the sum ADD ESI, 4 LOOP Next XOR EDX, EDX DIV EBX ; compute the average ; print integer part CALL WriteDec ; print the decimal point MOV AL, '.' CALL WriteChar ; print fractional part MOV EAX, 10 MUL EDX DIV EBX CALL WriteDec POPAD RET MSG BYTE 10, 13, "Average = ",0 DISPAVG ENDP END main

Page 10 of 11 [20 Points] (Q5) (i) Write a procedure BinarySearch to search an array which has been previously sorted in an ascending order. Each element in the array is a 32-bit signed integer. Three parameters should be passed on the stack: the address of the array to be searched, the size (number of elements) of the array, and the number to be searched. If the numer is found then BinarySearch returns in the EAX register the position of the number in the array. Otherwise, -1 is returned in EAX. All registers except EAX must be preserved by the procedure. The pseudocode for the BinarySearch procedure is given below: BinarySearch (array, size, number) { lower = 0; upper = size-1; while (lower <= upper) { middle = (lower + upper)/2; if (number == array[middle]) return middle; else if (number < array[middle]) upper = middle 1; else lower = middle+1; } return -1; } (ii) Write a complete program to use the procedure BinarySearch to search for the number 3 in the sorted array given below: Array DWORD 1, 3, 4, 5, 9, 11, 20, 29 Note that the size of the array in this case is 8 and the BinarySerach procedure should return the position of number 3 as 1..686.MODEL FLAT, STDCALL.STACK INCLUDE Irvine32.inc.DATA Array DWORD 1, 3, 4, 5, 9, 11, 20, 29.CODE main PROC PUSH offset Array PUSH lengthof Array PUSH 3

Page 11 of 11 CALL BinarySearch exit ; exit to operating system main ENDP BinarySearch PROC PUSH EBP MOV EBP, ESP PUSH EBX PUSH ECX PUSH ESI PUSH EDI PUSH EDX ; save registers MOV EBX, [EBP+8] ; number to be searched MOV ECX, [EBP+12] ; array size MOV ESI, [EBP+16] ; address of array XOR EDI, EDI ; lower=0 DEC ECX ; upper=size-1 WhileL: CMP EDI, ECX ; while (lower <= upper) { JA EndWhile MOV EDX, EDI ; middle = (lower + upper)/2; ADD EDX, ECX SHR EDX, 1 CMP EBX, [ESI+EDX*4] ; if (number == array[middle]) JNE Else1 MOV EAX, EDX ; return middle; JMP EndWhile Else1: JGE Else2 ; else if (number < array[middle]) MOV ECX, EDX ; upper = middle-1; DEC ECX JMP Skip Else2: MOV EDI, EDX ; lower = middle+1; INC EDI Skip: JMP WhileL EndWhile: POP EDX POP EDI POP ESI POP ECX POP EBX POP EBP RET 12 BinarySearch ENDP END main ; restore registers ; return and free parameters