1 / 17

Microprocessor & Assembly Language

Microprocessor & Assembly Language. Logical, shift, rotate, and bit Instructions. Basic Logic Instructions. Include AND, OR, Exclusive-OR, and NOT. – also TEST, a special form of the AND instruction – NEG, similar to the NOT instruction

sandifer
Download Presentation

Microprocessor & Assembly Language

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. Microprocessor & Assembly Language Logical, shift, rotate, and bit Instructions

  2. Basic Logic Instructions • Include AND, OR, Exclusive-OR, and NOT. – also TEST, a special form of the AND instruction – NEG, similar to the NOT instruction • Logic operations provide binary bit control in low-level software. –Can manipulate bits, do logical operations, allow bits to be set, cleared, or complemented and do arithmetic operations • Low-level software appears in machine language or assembly language form and often controls the I/O devices in a system. • Logic operations always clear the carry and overflow flags, while the other flags change to reflect the condition of the result • Except not instruction it does not affect any flags

  3. AND Instruction • The AND operation performs logical multiplication • Figures: (a) The truth table for the AND operation and (b) the logic symbol of an AND gate • The AND operation clears bits of a binary number • The task of clearing a bit in a binary number is called masking

  4. AND Examples • AND Form: • AND dest, source ;dest := dest and source • AND instruction uses any addressing mode except memory-to-memory and segment register addressing • The two operand must be the same size

  5. OR Instruction • The OR operation performs logical addition and is often called the Inclusive-OR function • Figure: (a) The truth table for the OR operation and (b) the logic symbol of an OR gate • The OR operation clears bits of a binary number

  6. OR Example • OR uses the same formats as AND

  7. XOR Instruction • Exclusive-OR: • If the inputs are both 0 or both 1, the output is 0 • If the inputs are different, the output is 1 • (a) truth table of XOR (b) Symbol of XOR gate • Exclusive-OR is sometimes called a comparator • XOR instruction allows part of a number to be inverted • A common use for the Exclusive-OR instruction is to clear a register to zero. For example, the XOR CH,CH instruction clears register CH to 00H

  8. XOR Example • XOR uses the same formats as AND

  9. TEST Instruction • The TEST instruction performs the AND operation BUT • AND instruction changes the destination operand • TEST instruction does not changes the destination operand • TEST only affects the condition of the flag register, which indicates the result of the test • The zero flag (Z) is a logic 1 if the bit under test is a zero, and (indicating a nonzero result) if the bit under test is not zero. • The TEST instruction functions in the same manner as a CMP instruction, The difference is • TEST instruction normally tests a single bit (or occasionally multiple bits) • CMP instruction tests the entire byte, word, or doubleword. • The TEST instruction uses the same addressing modes as the AND instruction • The destination operand is normally tested against immediate data • The value of immediate data is 1 to test the rightmost bit position, 2 to test the next bit, 4 for the next,and so on. • Usually the TEST instruction is followed by either the JZ (jump if zero) or JNZ (jump if not zero) instruction

  10. Test Example • Example 1: TEST AL,1 ;test right bit JNZ RIGHT ;if set TEST AL,128 ;test left bit JNZ LEFT ;if set • Examples:

  11. Additional Test Instructions • The 80386 through the Pentium 4 processors contain additional test instructions that test single bit positions • Example:

  12. NOT and NEG Instructions • Logical inversion, or the one’s complement (NOT), and arithmetic sign inversion, or the two’s complement (NEG) • NOT and NEG can use any addressing mode except segment register addressing • Examples:

  13. ShiftInstructions • Shift instructions position or move numbers to the left or right within a register or memory location. • They also perform :simple arithmetic such as • multiplication by powers of 2+n (left shift) • division by powers of 2-n (right shift) • The microprocessor’s instruction set contains four different shift instructions as shown in figure

  14. ShiftInstructions • Logical shift function with unsigned numbers • Arithmetic shift function with signed numbers • Logical shifts multiply or divide unsigned data; • arithmetic shifts multiply or divide signed data. – a shift left always multiplies by 2 for each bit position shifted – a shift right always divides by 2 for each position – shifting a two places, multiplies or divides by 4 • Shift form: • shl dest, count • shl dest, CL ; cl aontain count number • Destination can be memory location or register; Segment shift not allowed.

  15. Shift Examples • Two different forms of shifts:

  16. Rotate • Rotate instructions position binary data by rotating the information in a register or memory location, either from one end to another or through the carry flag • Rotation dressing modes are the same shifts • The four available rotate instructions appear:

  17. Rotation Examples

More Related