Lecture 5 Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU
Agenda Logic Instructions – AND, OR, XOR and NOT TEST Instruction Shift and Rotate Instructions Stack Operations Introduction to Procedures
AND, OR and XOR Instructions AND destination, source OR destination, source XOR destination, source Memory-to-memory operations are not allowed Effect on flags – SF, ZF, PF reflect the result – AF is undefined – CF, OF = 0
Use of Logic Instructions Selectively modify the bits of destination – b AND 1 = b(b represents a bit, 0/1) – b AND 0 = 0 – b OR 0 = b – b OR 1 = 1 – b XOR 0 = b – b XOR 1 = ~b (complement of b) So, AND cab be used to clear specific destination bit OR can be used to set specific destination bit XOR can be used to complement specific destination bit
Examples Example 7.2: Clear the sign bit of AL while leaving the other bits unchanged. AND AL, 7Fh Example 7.3: Set the msb and lsb of AL while preserving the other bits. ORAL, 81h Example 7.4: Change the sign bit of DX XOR DX, 8000h = 7Fh = 81h
NOT Instruction Complement operation NOT destination Example 7.5: Complement the bits in AX NOTAX
Agenda Logic Instructions – AND, OR, XOR and NOT TEST Instruction Shift and Rotate Instructions Stack Operations Introduction to Procedures
TEST Instruction TEST performs AND on the destination TEST destination, source Effects on flags – SF, ZF, PF reflect the result – AF is undefined – CF, OF = 0 TEST vs. CMP – CMP is subtraction operation
TEST Example Jump to label BELOW if AL contains an even number TESET AL, 1; is AL even? JZBELOW; yes, go to BELOW
Agenda Logic Instructions – AND, OR, XOR and NOT TEST Instruction Shift and Rotate Instructions Stack Operations Introduction to Procedures
Shift and Rotate Instructions Two types of shift and rotate instructions – Logical Shift / Rotate – Arithmetic Shift/Rotate Both logical and arithmetic left shift are identical But right shifts are different
Shift and Rotate Instructions SHL DH, 3; DH = DH = C = 1 SAL DH, 2; DH = DH = C = 1 SHR DH, 3; DH = DH = C = 1 SAR DH, 2; DH = DH = C = 1
Rotate Instructions Let DH = 8Ah = CF = 1 After first RCR DH = CF = 0 After second RCR DH = CF = 1
Agenda Logic Instructions – AND, OR, XOR and NOT TEST Instruction Shift and Rotate Instructions Stack Operations Introduction to Procedures
Stack vs. Queue Stack – LIFO : Last In First Out Queue – FIFO : First In First Out Stack Queue
PUSH vs. POP in Stack
Stack Operations
PUSH Instructions
POP Instructions
Stack example
Agenda Logic Instructions – AND, OR, XOR and NOT TEST Instruction Shift and Rotate Instructions Stack Operations Introduction to Procedures
Procedure Example Product = 0 REPEAT IF lsb of B is 1 THEN product = product + A END_IF Shift left A Shift right B UNTIL B = 0
References Ch 7, Assembly Language Programming – by Charls Marut Ch 4, Intel Microprocessors – by Brey