ACOE2511 Assembly Language Arithmetic and Logic Instructions.

Slides:



Advertisements
Similar presentations
NEG Instruction Change operand content into two’s complement (negative value) and stored back into its operand mov bl, b neg bl; bl = mov.
Advertisements

1 x86’s instruction sets. 2 Instruction Set Classification  Transfer Move  Arithmetic Add / Subtract Mul / Div, etc.  Control Jump Call / Return, etc.
Computer Organization & Assembly Language
80x86 Instruction Set Dr. Qiang Lin.
ADD Instruction ADD destination,source ADD AX,BX ADD SUM,EAX
Gursharan Singh Tatla 21-Nov-20101www.eazynotes.com.
8086 : INSTRUCTION SET By, Pramod Sunagar Assistant Professor
© 2006 Pearson Education, Upper Saddle River, NJ All Rights Reserved.Brey: The Intel Microprocessors, 7e Chapter 5 Arithmetic and Logic Instructions.
Flow Control Instructions
9-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
Shift and Rotate Instructions
Microcomputer & Interfacing Lecture 3
Ch. 7 Logic, Shift and Rotate instr.
Khaled A. Al-Utaibi  Introduction  Arithmetic Instructions  Basic Logical Instructions  Shift Instructions  Rotate Instructions.
Lecture 5 Multiplication, Division and Branches Dr. Dimitrios S. Nikolopoulos CSL/UIUC.
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Arithmetic Flags and Instructions
1 Logic, Shift, and Rotate Instructions Read Sections 6.2, 7.2 and 7.3 of textbook.
Assembly Language. Symbol Table Variables.DATA var DW 0 sum DD 0 array TIMES 10 DW 0 message DB ’ Welcome ’,0 char1 DB ? Symbol Table Name Offset var.
Arithmetic and Logic Instructions
EEL 3801 Part V Conditional Processing. This section explains how to implement conditional processing in Assembly Language for the 8086/8088 processors.
LEA instruction The LEA instruction can be used to get the offset address of a variable Example ORG 100h MOV AL, VAR1 ; check value of VAR1 by moving it.
3.4 Addressing modes Specify the operand to be used. To generate an address, a segment register is used also. Immediate addressing: the operand is a number.
Chapter 7: Integer Arithmetic. 2 Chapter Overview Shift and Rotate Instructions Shift and Rotate Applications Multiplication and Division Instructions.
Lecture 12 Integer Arithmetic Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Arithmetic Flags and Instructions Chapter 7 S. Dandamudi.
COMP 2003: Assembly Language and Digital Logic Chapter 2: Flags and Instructions Notes by Neil Dickson.
The Assemble, Unassemble commands of the debugger: U Command for converting machine code language source Equivalent machine code instructions Equivalent.
Chapter 7 Bit Manipulation. 7.1 Logical Operations.
Microprocessor & Assembly Language Arithmetic and logical Instructions.
Jumps, Loops and Branching. Unconditional Jumps Transfer the control flow of the program to a specified instruction, other than the next instruction in.
Assembly Language Wei Gao. Assembler language Instructions.
Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
K.K. Leung Fall 2008Introductory Pentium Programming1 Pentium Architecture: Introductory Programming Kin K. Leung
Computer Architecture and Assembly Language
Chapter Nov-2010
Data Transfers, Addressing, and Arithmetic
Homework Reading Labs PAL, pp
Practical Session 2.
Today we are going to discuss about,
Microprocessor Systems Design I
Instruksi Set Prosesor 8088
Microprocessor and Assembly Language
EE3541 Introduction to Microprocessors
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Instruction System - Bit Manipulation Instruction
INSTRUCTION SET.
Machine control instruction
INSTRUCTION SET.
More on logical instruction and
Assembly Language Programming Part 2
Processor Processor characterized by register set (state variables)
4.2 Arithmetic Instructions
INSTRUCTION SET OF 8086 PAWAN KUMAR SINGH.
CS 301 Fall 2002 Assembly Instructions
X86’s instruction sets.
Flags Register & Jump Instruction
Shift & Rotate Instructions)
ADDITION Register Addition. ADD AX,BX AX=AX+BX 2. Immediate Addition.
Shift & Rotate Instructions)
Flow Control Instructions
X86 Assembly Review.
Chapter 5 Arithmetic and Logic Instructions
UNIT-II Assembly Language Programs Involving Logical
Computer Organization and Assembly Language
CNET 315 Microprocessor & Assembly Language
Chapter 8: Instruction Set 8086 CPU Architecture
Computer Architecture and Assembly Language
CS-401 Computer Architecture & Assembly Language Programming
Presentation transcript:

ACOE2511 Assembly Language Arithmetic and Logic Instructions

ACOE2512 Arithmetic Instructions: (Addition) A.Addition: (Flags affected: A,C,O,P,S,Z) –ADDAL,BL ; AL  AL + BL, BL unchanged –ADD CX,DI ; CX  CX + DI, DI unchanged –ADD AH,45H ; AH  AH + 45H –ADD [BX],AL ; [BX]  [BX] + AL –ADD CX,[BX] ; CX  CX + [BX] –ADD AL,CX ; INVALID B. Add with Carry: (Flags affected: A,C,O,P,S,Z) –ADC AH,BH ; AH  AH + BH + Carry –ADC AX,CX ; AX  AX + CX + Carry –ADC AL,[BX+SI] ; AL  AL + [BX+SI] + Carry

ACOE2513 Arithmetic Instructions: (Subtraction) C. Subtraction: (Flags affected: A,C,O,P,S,Z) –SUB AL,BL ; AL  AL - BL ;BL unchanged –SUB CX,DI ; CX  CX - DI ;DI unchanged –SUB AH,45H ; AH  AH - 45H –SUB BL,ARRAY ; BL  BL - [ARRAY] –SUB [BX],AL ; [BX]  [BX] - AL –SUB AL,CX ; INVALID D. Subtract with Borrow: (Flags affected: A,C,O,P,S,Z) –SBB AH,BH ; AH  AH - BH - Carry –SBB AX,CX ; AX  AX - CX - Carry –SBB AL,[BX+SI] ; AL  AL - [BX+SI] - Carry

ACOE2514 Arithmetic Instructions: (Increment, Decrement) E. Increment: (Flags affected: A,O,P,S,Z) –INC AL ; AL  AL + 1 –INC SP ; SP  SP + 1 –INC COUNT1 ; [COUNT1]  [COUNT1] + 1 –INC BYTE PTR[BX] ; [BX]  [BX] + 1 –INC WORD PTR[BX] ; [BX]  [BX] + 1 F. Decrement: (Flags affected: A,O,P,S,Z) –DEC AL ; AL  AL - 1 –DEC SP ; SP  SP - 1 –DEC COUNT1 ; [COUNT1]  [COUNT1] - 1 –DEC BYTE PTR[BX] ; [BX]  [BX] - 1 –DEC WORD PTR[BX] ; [BX]  [BX] - 1

ACOE2515 Examples What will be the values of the carry, overflow, sign and zero flags after the execution of each of the following instructions: MOV DX,0 DEC DX MOV AX,720H SUB AX, 0E6H MOV DX,0 DEC DX

ACOE2516 Example: Fill up the trace table given below.

ACOE2517 Arithmetic Instructions: (Multiplication) G. Multiplication: (Flags affected: C,O, (A,P,S,Z are undefined)) Unsigned multiplication: –MUL CL ; AX  AL * CL –MUL CX ; DX,AX  AX * CX –MUL BYTE PTR [BX]; AX  AL * [BX] –MUL WORD PTR [SI] ; DX,AX  AX * [SI] Signed multiplication (2's complement): –IMUL BL ; AX  AL * BL –IMULBX ; DX,AX  AX * BX –IMUL BYTE PTR [BX]; AX  AL * [BX] –IMUL WORD PTR [SI] ; DX,AX  AX * [SI]

ACOE2518 Arithmetic Instructions: (Division) H. Division: (Flags affected: A,C,O,P,S,Z (all undefined)) Unsigned Division: –DIV CL ; AL  Quotient of AX/CL ; AH  Remainder of AX/CL –DIV CX ; AX  Quotient of DX,AX/CX ; DX  Remainder of DX,AX/CX Signed Division: –IDIV CL ; AL  Quotient of AX/CL ; AH  Remainder of AX/CL –IDIV CX ; AX  Quotient of DX,AX/CX ; DX  Remainder of DX,AX/CX

ACOE2519 Example: Fill up the trace table given below.

ACOE25110 Arithmetic Instructions: (BCD and ASCII Operations) I. BCD and ASCII Arithmetic: –DAA ; Decimal Adjust for Addition –DAS ; Decimal Adjust for Subtraction –AAA ; ASCII Adjust for Addition –AAS ; ASCII Adjust for Subtraction –AAM ; ASCII Adjust for Multiplication –AAD ; ASCII Adjust for Division

ACOE25111 Logic Instructions:( AND, OR, XOR, NOT, NEG and TEST ) Logic Instructions: AND AL,BL ; AL  AL AND BL (Always clears C and O flags) AND CL,33H ; CL  CL AND 33H AND AX,[DI] ; AX  AX AND [DI] OR AL,BL ; AL  AL OR BL OR AX,1234H ; AX  AX OR 1234H XOR AL,CL ; AL  AL EX-OR CL XOR BH,0FH ; BH  BH EX-OR 0FH NOT CH ; CH  1's complement of CH (No flags affected) NOT AX ; AX  1's complement of AX NEG CH ; CH  2's complement of CH (ALWAYS SETS CF) NEG BX ; BX  2's complement of BX TESTAL,30H ;Perform AL AND30H and set the flags. AL is unchanged.

ACOE25112 Example: Fill up the trace table given below.

ACOE25113 Program Control Instructions :(Jump and Call) Unconditional jump (JMP): –The JMP instruction specifies the address of the next instruction to be executed. There are three types of unconditional jump instructions: the SHORT, the NEAR, and the FAR. A SHORT jump is specified with only one byte which represents the displacement between the current instruction to the next instruction. The next instruction can be located at a distance from +127 to -128 memory locations away from the current instruction. A NEAR jump specifies the address of the next instruction within the current Code Segment. A FAR jump specifies the exact address of the next instruction by specifying the values of the CS and IP registers. –Examples: JMP NEXT JMP SHORT AGAIN JMP NEAR AGAIN JMP FAR AGAIN

ACOE25114 Program Control Instructions :(Jump and Call) Conditional jump: –Conditional jumps are executed only if the specified conditions are true. Usually the condition specified by a conditional jump instruction is the state of a flag. A list of the conditional jump instructions that check the state of flags is given below: Instruction Flags tested Action JC C = 1 Jump if carry set JZ Z = 1 Jump if equal or zero JS S = 1 Jump on sign (Negative) JO O = 1 Jump on overflow JNC C = 0 Jump if not carry JNZ Z = 0 Jump if not equal or 0 JNS S = 0 Jump if not sign (Positive) JNO O = 0 Jump if not overflow

ACOE25115 Example: Fill up the trace table given below.

ACOE25116 Program Control Instructions :(Jump and Call) Conditional jump using the Compare instruction: –Conditional jump instruction can be used after the compare ( CMP ) instruction. –Comparison of unsigned numbers is done using the Above or Below conditions. For example 81H is Above 7EH since 129>128. –Comparison of unsigned numbers is done using the Greater or Less conditions. For example 81H is Less than 7EH since -127<128. –The programmer can choose between the Above/Below or Greater/Less according to the application. If the values used in a program are always positive then these values are treated as unsigned numbers, and the Above /Below conditions are used, otherwise signed numbers are used and the Greater/Less conditions are used..

ACOE25117 Program Control Instructions :(Jump and Call) A list of the conditional jump instructions used with the Compare instruction is given below: Instruction Flags tested Action JA C = 0 & Z = 0 Jump if above JAE C = 0 Jump if above or equal JB C = 1 Jump if below JBE C = 1 or Z = 1 Jump if below or equal JE or JZ Z = 1 Jump if equal or zero JG O = Z AND S Jump if greater JGE S = O Jump if greater or equal JL S = O Jump if less JLE Z = 1 or S = O Jump if less or equal JNE or JNZ Z = 0 Jump if not equal or 0

ACOE25118 Example: Fill up the trace table given below.

ACOE25119 Program Control Instructions :(Jump and Call) Loops: –The LOOP instruction is a combination of the conditional jump and the decrement CX instructions. It will decrement the contents of CX and, if CX is not zero, jump to the label associated with the LOOP. If CX becomes zero, then the next sequential instruction is executed. –The LOOP instruction can also have conditional forms LOOPE (LOOPZ), and LOOPNE (LOOPNZ). –The conditional jump instruction JCXZ (Jump if CX = 0) can also be used. Procedures: –Procedures are implemented by using the PROC directive. The last instruction in a procedure must be the RET instruction. A procedure can be called by using the CALL instruction.

ACOE25120 Example: Fill up the trace table given below.

ACOE25121 Shift instructions SHL AL, BL ;Shifts the contents of AL to the left as many times as the value of BL, filling the lowest bit with zero and moving the highest to the carry flag SHR AL, BL ; The same principle, but now a right shift

ACOE25122 Arithmetic shifts SAL AL, BL ;Identical to SHL SAR AL, BL ;Shift right, but the most significant bit fills the leftmost position again

ACOE25123 Rotate instructions ROL ROR

ACOE25124 Rotate with carry instructions RCL RCR

ACOE25125 Example: Fill up the trace table given below.

ACOE25126 IN AND OUT INSTRUCTIONS IN AL, 3C ;Input byte from port 3Ch OUT 3Ch, AL ;Output byte to port 3Ch Use AX if you want to transfer 16 bits and EAX if you want to transfer 32 bits.