Assembly Language for Intel-Based Computers, 4th Edition PDF

Summary

This textbook, Assembly Language for Intel-Based Computers, 4th Edition by Kip R. Irvine, covers assembly language programming for Intel-based computers. It delves into conditional processing, Boolean operations, and applications, providing a detailed explanation of various instructions and their uses.

Full Transcript

Assembly Language for Intel-Based Computers, 4th EditionKip R. Irvine Chapter 6: Conditional Processing (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 a...

Assembly Language for Intel-Based Computers, 4th EditionKip R. Irvine Chapter 6: Conditional Processing (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. Chapter Overview Boolean and Comparison Instructions Conditional Jumps Conditional Loop Instructions Conditional Structures Application: Finite-State Machines Using the.IF Directive Irvine, Kip R. Assembly Language for Intel-Based Computers, 2 2003. Boolean and Comparison Instructions CPU Status Flags AND Instruction OR Instruction XOR Instruction NOT Instruction Applications TEST Instruction CMP Instruction Irvine, Kip R. Assembly Language for Intel-Based Computers, 3 2003. 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. 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 Irvine, Kip R. Assembly Language for Intel-Based Computers, 4 2003. AND Instruction Performs a Boolean AND operation between each pair of matching bits in two operands Syntax: AND destination, source AND (same operand types as MOV) 00111011 AND 00001111 cleared 00001011 unchanged Irvine, Kip R. Assembly Language for Intel-Based Computers, 5 2003. 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 Irvine, Kip R. Assembly Language for Intel-Based Computers, 6 2003. XOR Instruction Performs a Boolean exclusive-OR operation between each pair of matching bits in two operands Syntax: XOR XOR destination, source 00111011 XOR 00001111 unchanged 00110100 inverted XOR is a useful way to toggle (invert) the bits in an operand. Irvine, Kip R. Assembly Language for Intel-Based Computers, 7 2003. NOT Instruction Performs a Boolean NOT operation on a single destination operand Syntax: NOT NOT destination NOT 00111011 11000100 inverted Irvine, Kip R. Assembly Language for Intel-Based Computers, 8 2003. Applications (1 of 5) Task: Convert the character in AL to upper case. Solution: Use the AND instruction to clear bit 5. mov al,'a' ; AL = 01100001b and al,11011111b ; AL = 01000001b ASCII Table Irvine, Kip R. Assembly Language for Intel-Based Computers, 9 2003. Applications (2 of 5) Task: Convert a binary decimal byte into its equivalent ASCII decimal digit. Solution: Use the OR instruction to set bits 4 and 5. mov al,6 ; AL = 00000110b or al,00110000b ; AL = 00110110b The ASCII digit '6' = 00110110b Irvine, Kip R. Assembly Language for Intel-Based Computers, 10 2003. Applications (4 of 5) 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 ; low bit set? jz EvenValue ; jump if Zero flag set JZ (jump if Zero) is covered in Section 6.3. Your turn: Write code that jumps to a label if an integer is negative. Irvine, Kip R. Assembly Language for Intel-Based Computers, 12 2003. Applications (5 of 5) 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. Irvine, Kip R. Assembly Language for Intel-Based Computers, 13 2003. 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 Irvine, Kip R. Assembly Language for Intel-Based Computers, 14 2003. 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 Irvine, Kip R. Assembly Language for Intel-Based Computers, 15 2003. 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) Irvine, Kip R. Assembly Language for Intel-Based Computers, 16 2003. 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 Irvine, Kip R. Assembly Language for Intel-Based Computers, 17 2003. Irvine, Kip R. Assembly Language for Intel-Based Computers, 18 2003. Irvine, Kip R. Assembly Language for Intel-Based Computers, 19 2003. Irvine, Kip R. Assembly Language for Intel-Based Computers, 20 2003.

Use Quizgecko on...
Browser
Browser