0% found this document useful (0 votes)
21 views30 pages

micro - lecture-ch-3اءع ؤ

This chapter outlines arithmetic and logic instructions and programs in CPUs. It discusses unsigned addition and subtraction of individual bytes, words, and multi-word data using ADD and SUB instructions. Multiplication is covered for byte-byte, word-word, and word-byte operations. Division shows cases for byte/byte, word/word, word/byte, and doubleword/word. Logic instructions like AND, OR, XOR, and comparisons are explained alongside examples. Shift operations using SHR, SHL and rotate instructions ROR, ROL, RCR, RCL are defined. The document provides examples for converting lowercase to uppercase ASCII characters using CMP and bit masking.
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)
21 views30 pages

micro - lecture-ch-3اءع ؤ

This chapter outlines arithmetic and logic instructions and programs in CPUs. It discusses unsigned addition and subtraction of individual bytes, words, and multi-word data using ADD and SUB instructions. Multiplication is covered for byte-byte, word-word, and word-byte operations. Division shows cases for byte/byte, word/word, word/byte, and doubleword/word. Logic instructions like AND, OR, XOR, and comparisons are explained alongside examples. Shift operations using SHR, SHL and rotate instructions ROR, ROL, RCR, RCL are defined. The document provides examples for converting lowercase to uppercase ASCII characters using CMP and bit masking.
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/ 30

Chapter (3):

Arithmetic and Logic


Instructions and Programs

8/26/2022 1
Chapter (3):

Outlines:
➢ Unsigned addition & subtraction
➢ Unsigned multiplication & division
➢ Logic instructions and sample programs
➢ BCD & ASCII operands and instructions
➢ Rotate instructions
➢ Others

8/26/2022 2
❑ Add instruction:
➢ used to addition unsigned two numbers.

➢ Two cases, we will be discussing:


1. Additional of individual byte and word data.
2. Additional of multiward data.
❑ Case (1): Additional of individual byte and word data.
❑ Example (1):

8/26/2022 3
❑ Case (1): Additional of individual byte and word data. (Example cont.)

8/26/2022 4
❑ Case (1): Additional of individual byte and word data. (Example cont.)

❑ ADC AH,00 instruction: means AH+00+CF and place the result in AH.
❑ Example (2):

8/26/2022 5
❑ Case (1): Additional of individual byte and word data. (Example cont.)

8/26/2022 6
❑ Case (2): Additional of multiward numbers:
❑ If the numbers being added could be up to 8 bytes wide or more.
❑ Since registers are only 16 bits wide (2 bytes).
❑ Then the job of the programmer to write the code to break down these
large numbers into smaller chunks to be processed by the CPU.
❑ If a 16-bits register is used and the operand is 8 bytes wide, that would
take a total of four iterations.
❑ Example:

8/26/2022 7
❑ Case (2): Additional of multiward numbers: (Example cont.)

8/26/2022 8
❑ SUB instruction:
➢ used to subtraction unsigned two numbers.

➢ The following steps, To execute the SUB instruction in CPU:

8/26/2022 9
❑ SUB instruction:

8/26/2022 10
❑ Multiplication of unsigned numbers: the following cases
➢ byte x byte
➢ word x word
➢ word x byte

8/26/2022 11
❑ Multiplication of unsigned numbers:
➢ byte x byte

8/26/2022 12
❑ Multiplication of unsigned numbers:
➢ word x word

➢ word x byte

8/26/2022 13
❑ Division of unsigned numbers: the following cases
➢ byte / byte
➢ word / word
➢ word / byte
➢ doubleword / word

8/26/2022 14
❑ Division of unsigned numbers: the following cases
➢ byte / byte

8/26/2022 15
❑ We discuss the logic instructions (AND, OR, XOR, SHIFT, COMPARE)
➢ AND instruction
AND used to test register
contain zero (ZF=1)

According
to result Automatically reset to
0

8/26/2022 16
❑ We discuss the logic instructions (AND, OR, XOR, SHIFT, COMPARE)
➢ OR instruction
OR also used to test register
contain zero (ZF=1)
OR BL,0

According Automatically
According
to result reset to 0
to result Automatically reset to
0

8/26/2022 17
❑ We discuss the logic instructions (AND, OR, XOR, SHIFT, COMPARE)
➢ XOR instruction

According According Automatically


to result Automatically
to result reset to 0
0

8/26/2022 18
❑ We discuss the logic instructions (AND, OR, XOR, SHIFT, COMPARE)
➢ XOR instruction

XOR also used to see if the two registers have the same value (ZF=1)
XOR BL,AL

8/26/2022 19
❑ We discuss the logic instructions (AND, OR, XOR, SHIFT, COMPARE)
➢ SHIFT
➢ Two kinds of shift:
1. Logical shift (for unsigned numbers) used SHR & SHL instructions
2. Arithmetic shift (for signed numbers)
➢ SHR instruction:

8/26/2022 20
❑ We discuss the logic instructions (AND, OR, XOR, SHIFT, COMPARE)
➢ SHL instruction:

8/26/2022 21
❑ We discuss the logic instructions (AND, OR, XOR, SHIFT, COMPARE)
➢ COMPARE of unsigned numbers
➢ CMP instruction:

8/26/2022 22
❑ We discuss the logic instructions (AND, OR, XOR, SHIFT, COMPARE)

JA

JB

8/26/2022 23
❑ Example:

8/26/2022 24
❑ Example:
➢ Write assembly program uses the CMP instruction to find
the lowercase and uppercase ASCII characters and then
convert the lowercase to uppercase?

To change from lowercase to uppercase, d5 must be change, by


masked (ANDed) the lowercase with 1101 1111B or DFH
8/26/2022 25
❑ Example:

8/26/2022 26
❑ Used to rotate the bitwise of an operand right and left.
❑ Discuss the instructtions (ROR – ROL – RCR - RCL).
❑ Rotate Right (ROR)

❑ Rotate Left (ROL)

8/26/2022 27
❑ Example:

8/26/2022 28
❑ Rotate Right through carry (RCR)

❑ Rotate Left through carry (RCL)

8/26/2022 29
Any Question?

8/26/2022 30

You might also like