1 / 23

Lecture 5

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

dasha
Download Presentation

Lecture 5

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 5 Presented By Dr. ShazzadHosain Asst. Prof. EECS, NSU

  2. Agenda • Logic Instructions • AND, OR, XOR and NOT • TEST Instruction • Shift and Rotate Instructions • Stack Operations • Introduction to Procedures

  3. 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

  4. 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

  5. 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. OR AL, 81h Example 7.4: Change the sign bit of DX XOR DX, 8000h 0111 1111 = 7Fh 1000 0001 = 81h

  6. NOT Instruction Complement operation NOT destination Example 7.5: Complement the bits in AX NOT AX

  7. Agenda • Logic Instructions • AND, OR, XOR and NOT • TEST Instruction • Shift and Rotate Instructions • Stack Operations • Introduction to Procedures

  8. 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

  9. TEST Example • Jump to label BELOW if AL contains an even number TESET AL, 1 ; is AL even? JZ BELOW ; yes, go to BELOW

  10. Agenda • Logic Instructions • AND, OR, XOR and NOT • TEST Instruction • Shift and Rotate Instructions • Stack Operations • Introduction to Procedures

  11. 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

  12. Shift and Rotate Instructions SHL DH, 3 ; DH = 1110 1111 SHR DH, 3 ; DH = 1110 1111 DH = 0111 1000 DH = 1011 1100 DH = 0001 1101 DH = 1111 1011 C = 1 C = 1 C = 1 C = 1 SAL DH, 2 ; DH = 1110 1111 SAR DH, 2 ; DH = 1110 1111

  13. Rotate Instructions Let DH = 8Ah = 1000 1010 CF = 1 After first RCR DH = 1100 0101 CF = 0 After second RCR DH = 0110 0010 CF = 1

  14. Agenda • Logic Instructions • AND, OR, XOR and NOT • TEST Instruction • Shift and Rotate Instructions • Stack Operations • Introduction to Procedures

  15. Stack vs. Queue • Stack • LIFO : Last In First Out • Queue • FIFO : First In First Out Queue Stack

  16. PUSH vs. POP in Stack

  17. Stack Operations

  18. PUSH Instructions

  19. POP Instructions

  20. Stack example

  21. Agenda • Logic Instructions • AND, OR, XOR and NOT • TEST Instruction • Shift and Rotate Instructions • Stack Operations • Introduction to Procedures

  22. 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

  23. References • Ch 7, Assembly Language Programming – by CharlsMarut • Ch 4, Intel Microprocessors – by Brey

More Related