0% found this document useful (0 votes)
16 views17 pages

Lab8 نسخة

This document discusses arithmetic and logic instructions for microprocessors and microcontrollers. It describes instructions such as addition, subtraction, multiplication, division, AND, OR, XOR, shift, and rotate. It provides the format and operation of arithmetic instructions including ADD, SUB, ADC, SBB, MUL, and DIV. It also covers logic instructions such as AND, OR, XOR, and shift instructions SHR and SHL. The status flags in the microprocessor or microcontroller may change depending on the results of arithmetic and logic instructions.

Uploaded by

hosenalmalke.com
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views17 pages

Lab8 نسخة

This document discusses arithmetic and logic instructions for microprocessors and microcontrollers. It describes instructions such as addition, subtraction, multiplication, division, AND, OR, XOR, shift, and rotate. It provides the format and operation of arithmetic instructions including ADD, SUB, ADC, SBB, MUL, and DIV. It also covers logic instructions such as AND, OR, XOR, and shift instructions SHR and SHL. The status flags in the microprocessor or microcontroller may change depending on the results of arithmetic and logic instructions.

Uploaded by

hosenalmalke.com
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Southern Technical University

Engineering Technical College


Electromechanical Engineering Department

Microprocessor and Microcontroller

Fourth Stage

Lab8: Arithmetic and Logic Instructions

Lecturer: Ghada Salim Khefi


Arithmetic and Logic Instructions

 The arithmetic instructions: addition, subtraction, multiplication, division, comparison, increment,


decrement…

 The logic instructions: and, or, exclusive or, not, shift, rotate….

 Whenever arithmetic and logic instructions execute the contents of the status flags (Sign flag, Zero
flag, Carry flag, Auxiliary flag, Parity flag and Overflow flag) change.
Arithmetic Instructions

 Add with carry instruction (ADC)


 Adds the bit in the carry flag to the operands data.
 format:

ADC Destination , Source ; Destination = Destination + Source + CF


Arithmetic Instructions
Arithmetic Instructions
 Subtraction instruction (SUB)
 The source subtract from the destination with the result stored in the destination.
 format:

SUB Destination , Source ; Destination = Destination – Source

 If the CF=0, the result is positive and the destination has the result.
 If the CF=1, the result is negative and the destination has the 2’s complement of the result. NOT and
INC increment instructions can be used to change it.
Arithmetic Instructions

 Subtract with borrow instruction (SBB)


 The source and the bit in carry subtract from the destination with the result stored in the destination.
 format:

SBB Destination , Source ; Destination = Destination – Source – CF

 Used in multi-byte (multiword) numbers.


 If CF=0, SBB works exactly like SUB
 If CF=1, SBB subtracts 1 from the result
Arithmetic Instructions
Arithmetic Instructions
 Multiplication instruction (MUL)
 format:

MUL BL ; AX = AL * BL (8-bit multiplication)


MUL BX ; DX AX = AX * BX (16-bit multiplication)

 One of the operands must be in AL . The other operand can be either in a register or in memory.
 After the multiplication the result is in AX.
 when operand is a byte:
AX = AL * operand.
 when operand is a word:
(DX AX) = AX * operand.
Arithmetic Instructions
Arithmetic Instructions
 Division instruction (DIV)
 format:
DIV CL ; AL = AX / CL , AH = remainder
DIV CX ; AX = DX AX / CX , DX = remainder
 Numerator must be in AL and AH must be set to zero
 Denominator cannot be immediate but can be in memory or in a register.
 After the division AL will have the quotient and AH will have the remainder.
 when operand is a byte:
AL = AX / operand
AH = remainder (modulus)
 when operand is a word:
AX = (DX AX) / operand
DX = remainder (modulus)
Arithmetic Instructions
Logic Instructions
 AND Instruction
 format:

AND Destination , Source ; Destination = Destination & Source

 Both operand must be same size


Logic Instructions
 OR Instruction
 format:

OR Destination , Source ; Destination = Destination | Source

 Both operand must be same size


Logic Instructions
 Exclusive-OR Instruction (XOR )
 format:

XOR Destination , Source ; Destination = Destination ӿ Source

 Both operand must be same size


Logic Instructions
 Shift Right Instruction (SHR )
 format:

SHR Destination , Count ; shift destination right count times

MOV AX , 4
SHR AX , 1
0000 0100 0000 0010
Logic Instructions
 Shift Left Instruction (SHL)
 format:

SHL Destination , Count ; shift destination left count times

MOV AX , 2
SHL AX , 1
0000 0100 0000 0010
Logic Instructions

You might also like