Mnem. Meaning Format Operation Flags affected ADD Addition ADD D,S (D) (S)+(D) (CF) Carry ADC Add with ADC D,C (D) (S)+(D)+(CF) O,S,Z,A,P,C

Similar documents
8088/8086 Programming Integer Instructions and Computations

INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI

Week /8086 Microprocessor Programming I

Signed number Arithmetic. Negative number is represented as

Arithmetic Instructions

EEM336 Microprocessors I. Arithmetic and Logic Instructions

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

Instructions moving data

Intel 8086: Instruction Set

EC 333 Microprocessor and Interfacing Techniques (3+1)

Arithmetic and Logic Instructions And Programs

3.1 DATA MOVEMENT INSTRUCTIONS 45

Lecture (07) x86 programming 6

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

Kingdom of Saudi Arabia Ministry of Higher Education. Taif University. Faculty of Computers & Information Systems

Adding Binary Integers. Part 4. Negative Binary. Integers. Adding Base 10 Numbers. Adding Binary Example = 10. Arithmetic Logic Unit

Integer Arithmetic. Pu-Jen Cheng. Adapted from the slides prepared by Kip Irvine for the book, Assembly Language for Intel-Based Computers, 5th Ed.

Integer Arithmetic Part2

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

Adding Binary Integers. Part 5. Adding Base 10 Numbers. Adding 2's Complement. Adding Binary Example = 10. Arithmetic Logic Unit

APPENDIX C INSTRUCTION SET DESCRIPTIONS

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

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

Ex : Write an ALP to evaluate x(y + z) where x = 10H, y = 20H and z = 30H and store the result in a memory location 54000H.

1-Operand instruction types 1 INC/ DEC/ NOT/NEG R/M. 2 PUSH/ POP R16/M16/SR/F 2 x ( ) = 74 opcodes 3 MUL/ IMUL/ DIV/ DIV R/M

Defining and Using Simple Data Types

Basic Assembly SYSC-3006

ASSEMBLY LANGUAGE PROGRAMMING OF THE MICROCOMPUTER

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

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

Lesson 1. Fundamentals of assembly language

8086 ASSEMBLY LANGUAGE PROGRAMMING

Code segment Stack segment

8086 INSTRUCTION SET

Chapter Four Instructions Set

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

8086 INTERNAL ARCHITECTURE

16.317: Microprocessor Systems Design I Spring 2014

Assembler lecture 4 S.Šimoňák, DCI FEEI TU of Košice

Assignment no:4 on chapter no :3 : Instruction set of 8086

LAB 5 Arithmetic Operations Simple Calculator

UNIT III MICROPROCESSORS AND MICROCONTROLLERS MATERIAL OVERVIEW: Addressing Modes of Assembler Directives. Procedures and Macros

Computer Architecture and System Programming Laboratory. TA Session 3

Summer 2003 Lecture 4 06/14/03

ENE 334 Microprocessors

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

Introduction to 8086 Assembly

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

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

Lecture 9. INC and DEC. INC/DEC Examples ADD. ADD Examples SUB. INC adds one to a single operand DEC decrements one from a single operand

Chapter 7 Integer Arithmetic

Intel 8086 MICROPROCESSOR ARCHITECTURE

1 The mnemonic that is placed before the arithmetic operation is performed is A. AAA B. AAS C. AAM D. AAD ANSWER: D

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

Week /8086 Microprocessor Programming

UNIT II 16 BIT MICROPROCESSOR INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING. The Intel 8086 Instruction Set

PESIT Bangalore South Campus

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

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.

Computer Architecture 1 ح 303

ET355 Microprocessors Thursday 6:00 pm 10:20 pm

16.317: Microprocessor Systems Design I Fall 2013

UNIT 2 PROCESSORS ORGANIZATION CONT.

Integer Arithmetic. Computer Organization and Assembly Languages Yung-Yu Chuang 2005/11/17. with slides by Kip Irvine

Intel 8086 MICROPROCESSOR. By Y V S Murthy

Microprocessors & Assembly Language Lab 1 (Introduction to 8086 Programming)

9/25/ Software & Hardware Architecture

Week /8086 Microprocessor Programming II

Hands on Experience for Faculty in Laboratories Phase I JNTUK, Kakinada

Basic Execution Environment

Jones & Bartlett Learning, LLC NOT FOR SALE OR DISTRIBUTION 80x86 Instructions

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

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Electronics and Communication

Introduction to Microprocessor

Practical Course File For

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

CHETTINAD COLLEGE OF ENGINEERING AND TECHNOLOGY COMMUNICATION ENGINEERING REG 2008 TWO MARKS QUESTION AND ANSWERS

1. Introduction to Assembly Language

UNIT 4. Modular Programming

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

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

INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI

Basic Pentium Instructions. October 18

Computer Architecture and System Software Lecture 04: Floating Points & Intro to Assembly

Lecture 5:8086 Outline: 1. introduction 2. execution unit 3. bus interface unit

Microprocessor and Assembly Language Week-5. System Programming, BCS 6th, IBMS (2017)

The x86 Architecture

ADVANCE MICROPROCESSOR & INTERFACING

Lecture 5: Computer Organization Instruction Execution. Computer Organization Block Diagram. Components. General Purpose Registers.

CS-202 Microprocessor and Assembly Language

The functional block diagram of 8085A is shown in fig.4.1.

CS401 Assembly Language Solved MCQS From Midterm Papers

EXPERIMENT - 1: ADDITION & SUBTRACTION

MPID MICROPROCESSOR AND ITS INTERFACING DEVICES EEE III II SEMESTER OBJECTIVE QUESTIONS

8051 Programming: Arithmetic and Logic

Experiment 3. TITLE Optional: Write here the Title of your program.model SMALL This directive defines the memory model used in the program.

ICAL EN LAB MANUAL CS MICROPROCESSOR AND MICROCONTROLLER LABORATORY. Regulation. Branch. Year & Semester. Dharmapuri : B.E. CSE.

ELEG3923 Microprocessor Ch.6 Arithmetic and Logics

Internal architecture of 8086

Floating-Point Arithmetic

Transcription:

ARITHMETIC AND LOGICAL GROUPS 6-1 Arithmetic and logical groups: The arithmetic group includes instructions for the addition, subtraction, multiplication, and division operations. The state that results from the execution of an arithmetic instruction is recorded in the flags register. The flags that are affected by the arithmetic instructions are C, A, S, Z, P, O. For the purpose of discussion, we divide the arithmetic instructions into four subgroups: addition, subtraction, multiplication, and division. 6-1-1 Addition Instructions: The general forms of these instructions are shown in figure 6-1. Mnem. Meaning Format Operation Flags affected ADD Addition ADD D,S (D) (S)+(D) (CF) Carry O,S,Z,A,P,C ADC Add with ADC D,C (D) (S)+(D)+(CF) O,S,Z,A,P,C carry (CF) Carry INC Increment INC D (D) (D) + 1 O,S,Z,A,P by 1 AAA ASCII adjust for addition AAA A,C O,S,Z,P undefined DAA Decimal adjust for addition DAA (a) S,Z,A,P,C O undefined Accumulator (b) Source Reg16 Reg8 (c) Fig 6-1 (a) addition instructions (b) Allowed operands for ADD and ADC instructions. (c) Allowed operands for INC. The result of executing ADD is expressed as:

(D) (S)+(D) That is the contents of the source operand are added to the contents of the destination operand. The carry is stored in the carry flag. This instruction performs the half-add binary arithmetic operation. The result of executing ADC is expressed as: (D) (S)+(D)+(CF) This instruction performs the operation of full-adder logic function. Another instruction of 8086 is INC. This instruction adds one to 8-bit register or 16-bit register or memory location. Another instruction of 8086 is AAA. This instruction is ASCII arithmetic instruction with ASCII-coded numbers. These numbers range in value from 30H to 39H for the numbers 0-9. The AAA instruction should be executed immediately after the ADD instruction that adds ASCII data. EXAMPLE6-1: What is the result of executing the following instruction sequence? ADD AL, BL AAA Assume that AL contains 32 16 (The ASCII code for number 2), BL contains 34 16 (The ASCII code for number 4), and AH=0. SOLUTION: Executing the ADD instruction give: (AL) = (AL) + (BL) = 32 16 + 34 16 = 66 16 The result after executing AAA is: (AL) = 06 & (AH) = 00 16 16 AF and CF remain cleared. Another instruction of 8086 is DAA. This instruction is used to perform an adjust operation similar to that performed by AAA but for the addition of BCD numbers instead of ASCII number. EXAMPLE6-2: What is the result of executing the following instruction sequence? MOV DX, 1234H MOV BX, 3099H MOV AL, BL ADD AL, DL DAA MOV CL, AL MOV AL, BH ADC AL, DH DAA MOV CH, AL

SOLUTION: In this example, a 1234 adds to a 3099. The result is in BCD and stored in CX. CX=4333 6-1-2 Subtraction Instructions:. The general forms of these instructions are shown in figure 6-2: Mnem Meaning Format Operation Flags affected SUB Subtract SUB D,S (D) (D)-(S) (CF) Borrow O,S,Z,A,P, C SBB Subtract with borrow SBB D,S (CF) (D)-(S)-(CF) (CF) Borrow O,S,Z,A,P, C DEC Decrement by 1 DEC D D (D)-1 O,S,Z,A,P NEG Negate NEG D D 0-(D) (CF) 1 DAS Decimal adjust for subtraction DAS S,Z,A,P,C O undefined AAS ASCII adjust for AAS A,C O,S,Z,P undefined subtraction (a) Source Reg16 Reg8 (b) (c) (d) Destinatio n Accumulator O,S,Z,A,P, C Fig 6-2 (a) Subtraction instructions. (b) Allowed operands for SUB and SBB instructions. (c) Allowed operands for DEC instruction. (d) Allowed operands for NEG instruction

The subtraction subgroup is similar to the addition subgroup. It performs subtraction instead of addition. The (NEG) instruction replaces the value of its operand by its negative. This is done by subtracts the contents of operand from zero and the result is returned to the operand. As an example if (BX) = 003A 16 and the instruction NEG BX is execute, the result is: (BX) = 0000 16 (BX) = 0000 16 003A 16 = FFC6 16 6-1-3 Multiplication and Division Instructions: The 8086 has instructions for multiplication and division of binary, BCD numbers, and signed or unsigned integers. Multiplication and division are performed on bytes or on words. Fig 6-3 shows the form of these instructions. Mnem Meaning Format Operation Flags affected MUL DIV Multiply (unsigned) Division (unsigned) MUL S DIV S (AL).(S8) (AX) (AX).(S16) (DX),(AX) 1-Q((AX)/(S8)) (AL) R((AX)/(S8)) (AH) 2-Q((DX,AX)/(S16)) (AX) R((DX,AX)/(S16)) (DX) If Q is FF 16 in case 1 or O,C, S,Z,A,P undefined O,S,Z,A,P,C undefined FFFF 16 type 0 interrupt occurs IMUL IDIV AAM AAD Multiply (signed) Division (signed) Adjust AL for division Adjust AX for division IMUL S IDIV S AAM AAD (AL).(S8) (AX) (AX).(S16) (DX),(AX) 1-Q((AX)/(S8)) (AL) R((AX)/(S8)) (AH) 2-Q((DX,AX)/(S16)) (AX) R((DX,AX)/(S16)) (DX) If Q is positive and exceed 7FFF 16 or if Q is negative and becomes less than 8001 16, then type 0 interrupt occurs Q((AL)/) (AH) R((AL)/) (AL) (AH)*+(AL) (AL) 00 (AH) O,C S,Z,A,P undefined O,S,Z,A,P,C undefined S,Z,P O,A,C undefined S,Z,P O,A,C undefined

CBW Convert byte CBW (MSB of AL) (All bits of None to word AH) CWD Convert byte to CWD (MSB of AX) (All bits of None double word DX) Fig 6-3 (a) Multiplication and division instructions. (b) Allowed operand 8-bit division: The result of a DIV or IDIV instruction for an 8-bit divisor is represented by: (AX) / (8-bit operand) (AL), (AH) Dividend Division quotient remainder 16-bit division: The result of a DIV or IDIV instruction for an 16-bit divisor is represented by: (DX), (AX)/ (16-bit operand) (DX), (AX) Dividend Division quotient remainder EXAMPLE 6-3: The 2 s-complement signed data contents of AL equal -3 and the contents of CL equal -2. What result is produced in AX by executing the following instruction? MUL CL And IMUL CL SOLUTION: As binary data, the contents of AL and CL are: (AL)=-3(as2 s-complement) = (FF-3+1) = 111111 = FD 16 (CL)=-2(as2 s-complement) = (FF-2+1) = 111111 = FE 16 Executing the MUL CL instruction give: (AX) = 111111 2 111111 2 = 1111100001 2 = FA06 16 Executing the IMUL CL instruction give: (AX) = 3 16 2 16 = 6 AAM & AAD instructions: AAM instruction is adjust instruction for unpacked BCD multiplication. It follows the multiplication instruction. EXAMPLE 6-4: write a program that multiplies 5 by 6. SOLUTION: MOV AL, 5 MOV CL, 5 MUL CL

AAM HLT AAD instruction is adjust instruction for unpacked BCD division. Unlike all other adjustment instructions AAD instruction appears before a division. EXAMPLE 6-5: write a program that dived 72 by 9. SOLUTION: MOV BL, 9 MOV AX, 0702H AAD DIV BL HLT CBW & CWD instructions: The division instruction can also be used to divide a sign 8-bit dividend in AL by an 8-bit divisor. For this purpose we use (CBW) instruction. When (CBW) instruction is executed the value of AX register is as shown below: AH=0 if the number is positive. AH=1 if the number is negative. AL=8-bit dividend. EXAMPLE 6-6: What is the result of executing the following sequence of instructions? MOV AL, A1H CBW CWD SOLUTION: The first instruction loads AL with A1 16. This gives: (AL) = A1 16 = 0001 2 Executing the second instruction extends the MSB of AL, 1, into all bits of AH. The result is: (AH) = 11111111 2 = FF 16 (AX) = 111111110001 2 = FFA1 16 Executing the third instruction extends the MSB of AH, 1, into all bits of DX. The result is : (AX) = FFA1 16 (DX) = FFFF16 CMP instruction: The CMP (compare) instruction enables us to determine the relationship between two numbers-that is, whether they are equal or unequal, and when they are unequal, which one is larger. Mnem. Meaning Format Operation Flags CMP Compare CMP D,S (D)-(S) C,A,O, P,F,Z

Accumulator Source (b) (a) Figure 6-4 (a) Compare instruction. (b) Allowed operand. EXAMPLE 6-7: What is the result of executing the following sequence of instructions? MOV AL, 99H MOV BL, 1BH CMP AL, BL Assume that flags Z, S, C, A, O, and P are all initially reset. SOLUTION: The first instruction loads AL with 99 16. No status flags are affected. The second instruction loads AL with 1B 16. No status flags are affected. The third instruction CMP subtracts BL from AL: 0101 2 = -3-000111 2 = -(+27) 011111 2 = +126 In this process of subtraction, we get the status flag as shown below: A=1, C=0, O=1, P=1, S=0, Z=0. 6-2 Logical group: 6-2-1 AND, OR, XOR, and, NOT instructions: These instructions perform their respective logic operations. Fig 6-5 shows the format and the operand for these instructions. EXAMPLE 6-8: What is the result of executing the following sequence of instructions? MOV AL, 01B AND AL, 00011111B OR AL, 100000B XOR AL, 00001111B Solution: The result can be summarizes as shown below: Instruction MOV AL, 01B AND AL, 00011111B (AL) 01 0001

OR AL, 100000B XOR AL, 00001111B 11 11 Mnemonic Meaning Format Operation Flags affected AND Logical AND AND D,S (S).(D) (D) O,S,Z,P,C A undefined OR Logical OR OR D,S (S)+(D) (D) O,S,Z,P,C A undefined XOR Logical exclusive OR XOR D,S (S) (D) (D) O,S,Z,P,C A undefined NOT Logical NOT NOT D (Ď) (D) None Accumulator Source (b) Figure 6-5 (a) logical instructions (b) Allowed operands for AND, OR, XOR instructions. (c) Allowed operands for NOT instruction. (a) (C)