micro - lecture-ch-3اءع ؤ
micro - lecture-ch-3اءع ؤ
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.
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.
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
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?
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)
8/26/2022 27
❑ Example:
8/26/2022 28
❑ Rotate Right through carry (RCR)
8/26/2022 29
Any Question?
8/26/2022 30