0% found this document useful (0 votes)
73 views36 pages

Arithmetic and Logic Instructions: By: Ngo Carlo

This chapter discusses arithmetic and logic instructions in CPUs. It covers addition, subtraction, multiplication, division, and comparison instructions. Addition simply adds operands and stores the sum. Subtraction takes the difference of operands. Multiplication performs multiplication on bytes, words, and doublewords. Division divides larger numbers by smaller operands, storing the quotient and remainder. Comparison subtracts operands and sets flag bits without changing values.

Uploaded by

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

Arithmetic and Logic Instructions: By: Ngo Carlo

This chapter discusses arithmetic and logic instructions in CPUs. It covers addition, subtraction, multiplication, division, and comparison instructions. Addition simply adds operands and stores the sum. Subtraction takes the difference of operands. Multiplication performs multiplication on bytes, words, and doublewords. Division divides larger numbers by smaller operands, storing the quotient and remainder. Comparison subtracts operands and sets flag bits without changing values.

Uploaded by

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

Chapter 5

Arithmetic and Logic


Instructions
By: Ngo Carlo

Quick Review!
Addressing Modes

Section Introduction
In this chapter, we examine the arithmetic instructions:
Addition
Subtraction
Multiplication
Division
Comparison
Increment and Decrement.

Addition
1. Addition (ADD))
2. Increment (INC)
3. Add with Carry(ADC)
4. Exchange and Add (XADD)

1. Addition (ADD)
-Simply adds the value of the destination and source
operands and stores the sum, of course at the
destination operand.

2. Increment
Adds a value of 1 to the one and only parameter that
the operand requires and you gave. Simple!
INC AX is similar to AX=AX+1

Addition with Carry (ADC)


Similar to the addition that we talked about in the 5th
slide, but we just add an extra value courtesy of the
Carry Flag. TNX!

4. Exchange and Add (XADD)


As the the name suggests you just exchange and add
the source and destination values
MOV AX,2h//initialization
MOV BX,1H
XADD AX,BX//here AX=1h & BX=2h hence, exchange
//then AX=2h+1h=3h

Subtraction
1. Subtraction (SUB)
2. Decrement (DEC)
3. Subtract with Borrow (SBB)
4. Comparison (CMP)

1. Subtraction (SUB)
Destination Source
Minuend will go to the Destination

2. Decrement (DEC)
Decrement subtraction (DEC) subtracts 1 from a register
or the contents of a memory location
DEC AX is similar to AX=AX-1

Subtract with Borrow (SBB)


Similar to SUB, wherein the value of the source is taken
away from the Destination and you take away another 1
from the destination if the carry flag is 1

Comparison (CMP)
The comparison instruction (CMP) is a subtraction that
changes only the flag bits; the destination operand
never changes.

Multiplication
Multiplication is performed on bytes, words, or
doublewords, and can be signed integer (IMUL) or
unsigned integer (MUL).
If two 8-bit numbers are multiplied, they generate a 16bit product; if two 16-bit numbers are multiplied, they
generate a 32-bit product;
8 bit MUL
16 bit MUL
32 bit MUL
64 bit MUL

8 bit Multiplication
With 8-bit multiplication, the multiplicand is always in
the AL register. whether signed or unsigned.
The multiplier can be any 8-bit register or any memory
location.
The multiplication instruction contains one operand
because it always multiplies the operand times the
contents of register AL.
After the multiplication, the unsigned product is placed
in AX
the choice of the multiplier is up to the programmer.

16-Bit Multiplication
AX contains the multiplicand instead of AL
DXAX instead of AX. (Where we store the product)
the choice of the multiplier is up to the programmer.

A Special Immediate 16-Bit


Multiplication.
the 80186 through the Core2 processors can do so by
using a special version of the multiply instruction.
The first operand is the 16-bit destination register;
the second operand is a register or memory location
that contains the 16-bit multiplicand
third operand is either 8-bit or 16-bit immediate data
used as the multiplier.
IMUL CX,DX,12H instruction multiplies 12H times DX
and leaves a 16-bit signed product in CX.

32-Bit Multiplication
With 32-bit multiplication, the contents of EAX are
multiplied by the operand specified with the instruction.
The product (64 bits wide) is found in EDXEAX, where
EAX contains the least significant 32 bits

64-Bit Multiplication.
The result of a 64-bit multiplication in the Pentium 4
appears in the RDX:RAX register pair as a 128-bit
product.
The value if the RAX is the multiplicand

Division
These numbers are signed (IDIV) or unsigned (DIV) integers.
an 8-bit division divides a 16-bit number by an 8-bit number; a 16bit division divides a 32-bit number by a 16-bit number
None of the flag bits change predictably for a division. A division can
result in two different types of errors; one is an attempt to divide by
zero and the other is a divide overflow.
8 bit DIV
16 bit DIV
32 bit DIV
64 bit DIV
Remainder

8 Bit Division
An 8-bit division uses the AX register to store the
dividend that is divided by the contents of any 8-bit
register or memory location.
The quotient moves into AL after the division with AH
containing a whole number remainder.
Sign of the remainder is the sign of the dividend
We can also use CBW (convert byte to word) to convert
the contents of the AL as a byte to AX as a word

16-Bit Division
Similar to 8-bit division, except, instead of dividing into
AX, the 16-bit number is divided into DXAX, a 32-bit
dividend.
The quotient appears in AX and the remainder appears
in DX after a 16-bit division.
If AX is a 16-bit signed number, the CWD (convert word
to doubleword) instruction sign-extends it into a signed
32-bit number.

Remainder
The remainder could be used to round the quotient or
just dropped to truncate the quotient.

32-Bit Division
The 64-bit contents of EDXEAX are divided by the
operand specified by the instruction
32-bit quotient in EAX and a 32-bit remainder in EDX.
CDQ (convert doubleword to quadword) instruction is
used to convert the 32-bit contents of EAX into a 64-bit
signed number in EDXEAX.

64 bit division
The 64-bit division uses the RDX:RAX register pair to
hold the dividend and the quotient is found in RAX and
the remainder is in RDX after the division.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy