Lecture Computer organization and assembly language: Chapter 17 - Dr. Safdar Hussain Bouk

pptx
Số trang Lecture Computer organization and assembly language: Chapter 17 - Dr. Safdar Hussain Bouk 21 Cỡ tệp Lecture Computer organization and assembly language: Chapter 17 - Dr. Safdar Hussain Bouk 462 KB Lượt tải Lecture Computer organization and assembly language: Chapter 17 - Dr. Safdar Hussain Bouk 0 Lượt đọc Lecture Computer organization and assembly language: Chapter 17 - Dr. Safdar Hussain Bouk 0
Đánh giá Lecture Computer organization and assembly language: Chapter 17 - Dr. Safdar Hussain Bouk
4.7 ( 19 lượt)
Nhấn vào bên dưới để tải tài liệu
Để tải xuống xem đầy đủ hãy nhấn vào bên trên
Chủ đề liên quan

Nội dung

CSC 221 Computer Organization and Assembly Language Lecture 17: Boolean and Comparison Instructions Lecture 16: Review • Creating Procedures • Documenting Procedures • Example: SumOf Procedure • CALL and RET Instructions • The CALL instruction calls a procedure – pushes offset of next instruction on the stack and copies the address of the called procedure into EIP • The RET instruction returns from a procedure Lecture 16: Review • Nested Procedure Calls • Local and Global Labels • Flowchart Symbols • USES Operator (cont.) Lecture Outline Boolean and Comparison Instructions – CPU Status Flags – AND Instruction – OR Instruction – XOR Instruction – NOT Instruction – Applications – TEST Instruction – CMP Instruction Status Flags - Review • The Zero flag is set when the result of an operation equals zero. • The Carry flag is set when an instruction generates a result that is too large (or too small) for the destination operand. • The Sign flag is set if the destination operand is negative, and it is clear if the destination operand is positive. Status Flags - Review • The Overflow flag is set when an instruction generates an invalid signed result (bit 7 carry is XORed with bit 6 Carry). • The Parity flag is set when an instruction generates an even number of 1 bits in the low byte of the destination operand. • The Auxiliary Carry flag is set when an operation produces a carry out from bit 3 to bit 4 AND Instruction • Performs a Boolean AND operation between each pair of matching bits in two operands • Syntax: AND destination, source (same operand types as MOV) 00111011 AND 0 0 0 0 1 1 1 1 cleared 00001011 unchanged AND OR Instruction • Performs a Boolean OR operation between each pair of matching bits in two operands • Syntax: OR destination, source OR 00111011 OR 0 0 0 0 1 1 1 1 unchanged 00111111 set XOR Instruction • Performs a Boolean exclusive-OR operation between each pair of matching bits in two operands XOR • Syntax: XOR destination, source 00111011 XOR 0 0 0 0 1 1 1 1 unchanged 00110100 inverted XOR is a useful way to toggle (invert) the bits in an operand. NOT Instruction • Performs a Boolean NOT operation on a single destination operand NOT • Syntax: NOT destination NOT 00111011 11000100 inverted Applications (1 of 4) • Task: Convert the character in AL to upper case. ‘a’ = ASCII 7 Bits : 1100001 ‘A’ = ASCII 7 Bits : 1000001 • Solution: Use the AND instruction to clear bit 5. mov al,'a' and al,11011111b ; AL = 01100001b ; AL = 01000001b Applications (2 of 4) • Task: Convert a binary decimal byte into its equivalent ASCII decimal digit. 0 : ASCII : 0011 0000 1 : ASCII : 0011 0001 ……. • Solution: Use the OR instruction to set bits 4 and 5. mov al,6 or al,00110000b ; AL = 00000110b ; AL = 00110110b The ASCII digit '6' = 00110110b Applications (3 of 4) • Task: Jump to a label if an integer is even. • Solution: AND the lowest bit with a 1. If the result is Zero, the number was even. mov ax,wordVal and ax,1 jz EvenValue ; low bit set? ; jump if Zero flag set JZ (jump if Zero) is covered in Next Lecture. Your turn: Write code that jumps to a label if an integer is negative. Applications (4 of 4) • Task: Jump to a label if the value in AL is not zero. • Solution: OR the byte with itself, then use the JNZ (jump if not zero) instruction. or al,al jnz IsNotZero ; jump if not zero ORing any number with itself does not change its value. TEST Instruction • Performs a nondestructive AND operation between each pair of matching bits in two operands • No operands are modified, but the Zero flag is affected. • Example: jump to a label if either bit 0 or bit 1 in AL is set. test al,00000011b jnz ValueFound • Example: jump to a label if neither bit 0 nor bit 1 in AL is set. test al,00000011b jz ValueNotFound CMP Instruction (1 of 3) • Compares the destination operand to the source operand – Nondestructive subtraction of source from destination (destination operand is not changed) • Syntax: CMP destination, source • Example: destination == source mov al,5 cmp al,5 ; Zero flag set • Example: destination < source mov al,4 cmp al,5 ; Carry flag set CMP Instruction (2 of 3) • Example: destination > source mov al,6 cmp al,5 ; ZF = 0, CF = 0 (both the Zero and Carry flags are clear) CMP Instruction (3 of 3) The comparisons shown here are performed with signed integers. • Example: destination > source mov al,5 cmp al,-2 ; Sign flag == Overflow flag • Example: destination < source mov al,-1 cmp al,5 ; Sign flag != Overflow flag Summary • Examples of PROC • CPU Status Flags • AND Instruction – AND destination, source • OR Instruction – OR destination, source • XOR Instruction – XOR destination, source • NOT Instruction – NOT destination Summary • Applications • TEST Instruction – Performs a nondestructive AND operation between each pair of matching bits in two operands. ZERO Flag • CMP Instruction – CMP destination, source – Zero (Dest. Equal) and Carry (Dest. Less) Flags Reference Most of the Slides are taken from Presentation: Chapter 6 Assembly Language for Intel-Based Computers, 4th Edition Kip R. Irvine (c) Pearson Education, 2002. All rights reserved. You may modify and copy this slide show for your personal use, or for use in the classroom, as long as this copyright statement, the author's name, and the title are not changed.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.