AMD Am186 Series Instruction Set
Hide thumbs Also See for Am186 Series:
Table of Contents

Advertisement

Quick Links

Am186™ and Am188™ Family
Instruction Set Manual
February, 1997

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the Am186 Series and is the answer not in the manual?

Questions and answers

Summary of Contents for AMD Am186 Series

  • Page 1 Am186™ and Am188™ Family Instruction Set Manual February, 1997...
  • Page 2 AMD assumes no responsibility for the use of any circuitry other than the circuitry in an AMD product. The information in this publication is believed to be accurate in all respects at the time of publication, but is subject to change without notice. AMD assumes no responsibility for any errors or omissions, and disclaims responsibility for any consequences resulting from the use of the information included herein.
  • Page 3: Introduction And Overview

    PREFACE INTRODUCTION AND OVERVIEW ™ AMD has a strong history in x86 architecture and its E86 family meets customer requirements of low system cost, high performance, quality vendor reputation, quick time to market, and an easy upgrade strategy. ™ ™...
  • Page 4: E86 Family

    To order literature, contact the nearest AMD sales office or call 800-222-9323 (in the U.S. and Canada) or direct dial from any location 512-602-5651. Literature is also available in postscript and PDF formats on the AMD web site. To access the AMD home page, go to http:/ /www.amd.com.
  • Page 5: Table Of Contents

    MANUAL OVERVIEW ..........III AMD DOCUMENTATIONiv E86 Family .
  • Page 6 3.1.4 Comparison ......... 3-3 3.1.5 Control Transfer .
  • Page 7 Jump If Greater ................4-91 Jump If Greater or Equal............4-93 Jump If Less................4-95 Jump If Less or Equal ..............4-97 Jump Unconditionally ..............4-99 Jump If Not Above..............4-102 JNAE Jump If Not Above or Equal ............. 4-103 Jump If Not Below ..............
  • Page 8 PUSHA Push All 16-Bit General Registers onto Stack......4-184 PUSHF Push Flags onto Stack ............. 4-186 Rotate through Carry Left............4-187 Rotate through Carry Right ............4-189 Repeat..................4-191 REPE Repeat While Equal ..............4-193 REPNE Repeat While Not Equal............4-197 REPZ Repeat While Zero ..............
  • Page 9 LIST OF FIGURES Figure 1-1 Register Set ............1-2 Figure 1-2 Processor Status Flags Register (FLAGS) .
  • Page 10 Table of Contents...
  • Page 11: Programming

    CHAPTER PROGRAMMING All members of the Am186 and Am188 family of microcontrollers contain the same basic set of registers, instructions, and addressing modes, and are compatible with the original industry-standard 186/188 parts. REGISTER SET The base architecture for Am186 and Am188 microcontrollers has 14 registers (see Figure 1-1), which are controlled by the instructions detailed in this manual.
  • Page 12: Processor Status Flags Register

    Figure 1-1 Register Set 16-Bit 16-Bit Special Register Register Register Name Name Functions Byte Multiply/Divide Code Segment Addressable I/O Instructions (8-Bit Data Segment Loop/Shift/Repeat/Count Register Stack Segment Names Shown) Base Registers Extra Segment base pointer Segment Registers source index Index Registers destination index FLAGS Stack Pointer...
  • Page 13: Instruction Set

    Bit 10: Direction Flag (DF)—Causes string instructions to auto decrement the appropriate index registers when set. Clearing DF causes auto-increment. See the CLD and STD instructions, respectively, for how to clear and set the Direction Flag. Bit 9: Interrupt-Enable Flag (IF)—When set, enables maskable interrupts to cause the CPU to transfer control to a location specified by an interrupt vector.
  • Page 14: Figure 1-4 Memory And I/O Space

    The result is a 20-bit address of the target data or instruction. This allows for a 1-Mbyte physical address size. For example, if the segment register is loaded with 12A4h and the offset is 0022h, the resultant address is 12A62h (see Figure 1-3). To find the result: 1.
  • Page 15: I/O Space

    I/O SPACE The I/O space consists of 64K 8-bit or 32K 16-bit ports. The IN and OUT instructions address the I/O space with either an 8-bit port address specified in the instruction, or a 16-bit port address in the DX register. 8-bit port addresses are zero-extended so that A15–A8 are Low.
  • Page 16: Figure 1-5 Supported Data Types

    ASCII—A byte representation of alphanumeric and control characters using the ASCII standard of character representation. Packed BCD—A packed byte representation of two decimal digits (0–9). One digit is stored in each nibble (4 bits) of the byte. String—A contiguous sequence of bytes or words. A string can contain from 1 byte up to 64 Kbyte.
  • Page 17: Addressing Modes

    ADDRESSING MODES The Am186 and Am188 microcontrollers use eight categories of addressing modes to specify operands. Two addressing modes are provided for instructions that operate on register or immediate operands; six modes are provided to specify the location of an operand in a memory segment.
  • Page 18 Programming...
  • Page 19: Instruction Set Overview

    CHAPTER INSTRUCTION SET OVERVIEW OVERVIEW The instruction set used by the Am186 and Am188 family of microcontrollers is identical to the original 8086 and 8088 instruction set, with the addition of seven instructions (BOUND, ENTER, INS, LEAVE, OUTS, POPA, and PUSHA), and the enhancement of nine instructions (immediate operands were added to IMUL, PUSH, RCL, RCR, ROL, ROR, SAL/SHL, SAR, and SHR).
  • Page 20: Segment Override Prefix

    2.2.2 Segment Override Prefix To override the default segment register, place the following byte in front of the instruction, where RR determines which register is used. Only one segment override prefix can be used per instruction. Segment Override Prefix 00 = ES Register 01 = CS Register 10 = SS Register 11 = DS Register...
  • Page 21: Displacement

    Table 2-2 aux field If mod=11 and w=0 If mod=11 and w=1 * – When mod≠11, depends on instruction Table 2-3 r/m field Description EA* = (BX)+(SI)+DISP EA = (BX)+(DI)+DISP EA = (BP)+(SI)+DISP EA = (BP)+(DI)+DISP EA = (SI)+DISP EA = (DI)+DISP EA = (BP)+DISP (except if mod=00, then EA = disp-high:disp:low) EA = (BX)+DISP * –...
  • Page 22: Using This Manual

    USING THIS MANUAL Each instruction is detailed in Chapter 4. The following sections explain the format used when describing each instruction. 2.4.1 Mnemonics and Names The primary assembly-language mnemonic and its name appear at the top of the first page for an instruction (see Figure 2-1).
  • Page 23 Opcode The Opcode column specifies the machine-language opcodes for the different forms of an instruction. (For instruction prefixes, this column also includes the prefix.) Each opcode includes one or more numbers in hexadecimal format, and zero or more parameters, which are shown in italics.
  • Page 24: What It Does

    Description The Description column contains a brief synopsis of each form of the instruction. Clocks The Clocks columns (one for the Am186 and one for the Am188 microcontrollers) specify the number of clock cycles required for the different forms of an instruction. This parameter Indicates that The number of clocks required for a register operand is different than the...
  • Page 25: Operation It Performs

    2.4.6 Operation It Performs This section uses a combination of C-language and assembler syntax to describe the operation of the instruction in detail. In some cases, pseudo-code functions are used to simplify the code. These functions and the actions they perform are as follows: Pseudo-Code Function Action cat( componenta , componentb )
  • Page 26: Tips

    2.4.9 Tips This section contains hints and ideas about some of the ways in which the instruction can be used. Tips are marked with this icon. 2.4.10 Related Instructions This section lists other instructions related to the described instruction. Instruction Set Overview...
  • Page 27: Instruction Set Listing

    CHAPTER INSTRUCTION SET LISTING This chapter lists all the instructions for the Am186 and Am188 family of microcontrollers. The instructions are first grouped by type (see page 3-1) and then listed in alphabetical order (see page 3-11) INSTRUCTION SET BY TYPE The instructions can be classified into groups according to the type of operation they perform.
  • Page 28: Binary Arithmetic

    3.1.2 Binary Arithmetic The microcontroller supports binary arithmetic using numbers represented in the two’s complement system. The two’s complement system uses the high bit of an integer (a signed number) to determine the sign of the number. Unsigned numbers have no sign bit. Binary Addition Instructions Mnemonic Name...
  • Page 29: Comparison

    3.1.3 Block-Structured Language Block-Structured Language Instructions Mnemonic Name See Page ENTER Enter High-Level Procedure 4-53 LEAVE Leave High-Level Procedure 4-135 3.1.4 Comparison General Comparison Instructions Mnemonic Name See Page Compare Components 4-34 TEST Logical Compare 4-243 String Comparison Instructions Mnemonic Name See Page CMPS...
  • Page 30 Conditional Jump Instructions to Use after Unsigned Number Comparisons Mnemonic Name See Page Jump If Above 4-78 Jump If Above or Equal 4-80 Jump If Below 4-82 Jump If Below or Equal 4-84 Jump If Not Above ( Synonym for JBE) 4-84 JNAE Jump If Not Above or Equal ( Synonym for JB)
  • Page 31: Data Movement

    Conditional Loop Instructions Mnemonic Name See Page JCXZ Jump If CX Register Is Zero 4-87 LOOP Loop While CX Register is Not Zero 4-146 LOOPE Loop If Equal 4-148 LOOPNE Loop If Not Equal 4-150 LOOPNZ Loop If Not Zero ( Synonym for LOOPNE) 4-150 LOOPZ Loop If Zero ( Synonym for LOOPE)
  • Page 32: Decimal Arithmetic

    Stack Movement Instructions Mnemonic Name See Page Pop Component from Stack 4-175 POPA Pop All 16-Bit General Registers from Stack 4-178 POPF Pop Flags from Stack 4-180 PUSH Push Component onto Stack 4-181 PUSHA Push All 16-Bit General Registers onto Stack 4-184 PUSHF Push Flags onto Stack...
  • Page 33: Flag

    Unpacked-Decimal Adjustment Instructions Mnemonic Name See Page ASCII Adjust AL After Addition ASCII Adjust AX Before Division ASCII Adjust AL After Multiplication ASCII Adjust AL After Subtraction Packed-Decimal Adjustment Instructions Mnemonic Name See Page Decimal Adjust AL After Addition 4-42 Decimal Adjust AL After Subtraction 4-45 Consider using decimal arithmetic instead of binary arithmetic under the following...
  • Page 34: Input/Output

    3.1.9 Input/Output General I/O Instructions Mnemonic Name See Page Input Component from Port 4-67 Output Component to Port 4-171 String I/O Instructions Mnemonic Name See Page Input String Component from Port 4-71 INSB Input String Byte from Port ( Synonym for INS) 4-71 Input String Word from Port ( Synonym for INS) INSW...
  • Page 35: Processor Control

    3.1.11 Processor Control Processor Control Instructions Mnemonic Name See Page Halt 4-57 LOCK Lock the Bus 4-140 No Operation 4-165 Coprocessor Interface Instructions Mnemonic Name See Page Escape 4-56 WAIT Wait for Coprocessor 4-245 3.1.12 String A string is a contiguous sequence of components stored in memory. For example, a string might be composed of a list of ASCII characters or a table of numbers.
  • Page 36 String Direction Instructions Mnemonic Name See Page Clear Direction Flag 4-29 Set Direction Flag 4-231 String Movement Instructions Mnemonic Name See Page LODS Load String Component 4-141 LODSB Load String Byte ( Synonym for LODS) 4-141 Load String Word ( Synonym for LODS) LODSW 4-141 MOVS...
  • Page 37: Instruction Set In Alphabetical Order

    INSTRUCTION SET IN ALPHABETICAL ORDER Table 3-1 provides an alphabetical list of the instruction set for the Am186 and Am188 microcontrollers. Table 3-1 Instruction Set Mnemonic Instruction Name See Page ASCII Adjust AL After Addition ASCII Adjust AX Before Division ASCII Adjust AL After Multiplication ASCII Adjust AL After Subtraction Add Numbers with Carry...
  • Page 38 Table 3-1 Instruction Set (continued) Mnemonic Instruction Name See Page Jump If Equal 4-89 Jump If Greater 4-91 Jump If Greater or Equal 4-93 Jump If Less 4-95 Jump If Less or Equal 4-97 Jump Unconditionally 4-99 Jump If Not Above ( Synonym for JBE) 4-84 Jump If Not Above or Equal ( Synonym for JB) JNAE...
  • Page 39 Table 3-1 Instruction Set (continued) Mnemonic Instruction Name See Page One’s Complement Negation 4-167 Logical Inclusive OR 4-169 Output Component to Port 4-171 OUTS Output String Component to Port 4-173 OUTSB Output String Byte to Port ( Synonym for OUTS) 4-173 OUTSW Output String Word to Port ( Synonym for OUTS)
  • Page 40 3-14 Instruction Set Listing...
  • Page 41 CHAPTER INSTRUCTION SET INSTRUCTIONS This chapter contains a complete description of each instruction that is supported by the Am186 and Am188 family of microcontrollers. For an explanation of the format of each instruction, see Chapter 2 . Instruction Set...
  • Page 42 ASCII Adjust AL After Addition Clocks Form Opcode Description Am186 Am188 ASCII-adjust AL after addition What It Does AAA converts an 8-bit unsigned binary number that is the sum of two unpacked decimal (BCD) numbers to its unpacked decimal equivalent. Syntax Description Use the AAA instruction after an ADD or ADC instruction that leaves a byte result in the...
  • Page 43 Examples This example adds two unpacked decimal numbers. UADDEND1 ; 5 unpacked BCD UADDEND2 ; 7 unpacked BCD ; add unpacked decimal numbers AX,AX ; clear AX AL,UADDEND1 ; AL = 05h = 5 unpacked BCD AL,UADDEND2 ; AX = 000Ch = 12 ;...
  • Page 44: Aad Ascii Adjust Ax Before Division

    ASCII Adjust AX Before Division Clocks Form Opcode Description Am186 Am188 D5 0A ASCII-adjust AX before division What It Does AAD converts a two-digit unpacked decimal (BCD) number—ordinarily the dividend of an unpacked decimal division—to its unsigned binary equivalent. Syntax Description AAD prepares two unpacked BCD digits—the least significant digit in the AL register and the most significant digit in the AH register—for division by an unpacked BCD digit.
  • Page 45 This example uses AAD to convert a two-digit unpacked decimal number to its binary equivalent. UBCD 0801h ; 81 unpacked BCD ; convert unpacked decimal number to binary AX,UBCD ; AX = 0801h = 81 unpacked BCD ; AX = 0051h = 81 Tips The microcontroller can only divide unpacked decimal numbers.
  • Page 46: Aam Ascii Adjust Al After Multiplication

    ASCII Adjust AL After Multiplication Clocks Form Opcode Description Am186 Am188 D4 0A ASCII-adjust AL after multiplication What It Does AAM converts an 8-bit unsigned binary number—ordinarily the product of two unpacked decimal (BCD) numbers—to its unpacked decimal equivalent. Syntax Description Use AAM only after executing the MUL instruction between two unpacked BCD operands with the result in the AX register.
  • Page 47 This example uses AAM to divide an unsigned binary number by 10. (The binary number must be 99 or less.) Note that the quotient occupies the high byte of the result, and the remainder occupies the low byte of the result. If you use DIV to divide an unsigned number by 10, the quotient and remainder occupy the opposite halves of the result.
  • Page 48: Aas Ascii Adjust Al After Subtraction

    ASCII Adjust AL After Subtraction Clocks Form Opcode Description Am186 Am188 ASCII-adjust AL after subtraction What It Does AAS converts an 8-bit unsigned binary number that is the difference of two unpacked decimal (BCD) numbers to its unpacked decimal equivalent. Syntax Description Use AAS only after a SUB or SBB instruction that leaves the byte result in AL.
  • Page 49 Examples This example subtracts one unpacked decimal number (the subtrahend) from another unpacked decimal number (the minuend). UMINUEND 0103h ; 13 unpacked BCD USUBTRAHEND ; 5 unpacked BCD ; subtract unpacked decimal numbers AX,UMINUEND ; AX = 0103h = 13 unpacked BCD AL,USUBTRAHEND ;...
  • Page 50: Adc Add Numbers With Carry

    Add Numbers with Carry Clocks Form Opcode Description Am186 Am188 ADC AL, imm8 14 ib Add immediate byte to AL with carry ADC AX, imm16 15 iw Add immediate word to AX with carry ADC r/m8 , imm8 80 /2 ib Add immediate byte to r/m byte with carry 4/16 4/16...
  • Page 51 Flag Settings After Instruction OF DF IF TF SF ZF Processor Status – – – reserved Flags Register ? = undefined; – = unchanged OF=1 if result larger than destination operand CF=1 for carry or borrow to high-order bit OF=0 otherwise CF=0 otherwise SF=1 if result is 0 or positive PF=1 if low byte of result has even number of set bits...
  • Page 52 This example adds two 3-byte packed decimal numbers. PADDEND1 00h,25h,86h,17h ; 258617 packed BCD PADDEND2 00h,04h,21h,45h 42145 packed BCD ; multibyte packed decimal addition: PADDEND1 = PADDEND1 + PADDEND2 ; add right bytes AL,PADDEND1 + 3 AL,PADDEND2 + 3 PADDEND1 + 3,AL ;...
  • Page 53 Related Instructions If you want to Convert an 8-bit unsigned binary sum to its unpacked decimal equivalent Add two numbers Convert an 8-bit integer to its 16-bit equivalent Convert an 8-bit unsigned binary sum to its packed decimal equivalent Change the sign of an integer Instruction Set 4-13...
  • Page 54: Add Add Numbers

    Add Numbers Clocks Form Opcode Description Am186 Am188 ADD AL, imm8 04 ib Add immediate byte to AL ADD AX, imm16 05 iw Add immediate word to AX ADD r/m8 , imm8 80 /0 ib Add immediate byte to r/m byte 4/16 4/16 ADD r/m16 , imm16...
  • Page 55 Flag Settings After Instruction OF DF IF TF SF ZF Processor Status – – – reserved Flags Register ? = undefined; – = unchanged OF=1 if result larger than destination operand CF=1 for carry or borrow to high-order bit OF=0 otherwise CF=0 otherwise SF=1 if result is 0 or positive PF=1 if low byte of result has even number of set bits...
  • Page 56 The microcontroller does not provide an instruction that performs decimal addition. To add decimal numbers, use ADD to perform binary addition, and then convert the result to decimal using AAA or DAA. ADC, ADD, SBB, and SUB set AF when the result needs to be converted for decimal arithmetic.
  • Page 57: And Logical And

    Logical AND Clocks Form Opcode Description Am186 Am188 AND AL, imm8 24 ib AND immediate byte with AL AND AX, imm16 25 iw AND immediate word with AX AND r/m8 , imm8 80 /4 ib AND immediate byte with r/m byte 4/16 4/16 AND r/m16 , imm16...
  • Page 58 Examples This example converts an ASCII number to its unpacked decimal equivalent. BCD_MASK ; ASCII-to-decimal mask ASCII_NUM ; ASCII ’6’ ; convert ASCII number to decimal AL,ASCII_NUM ; AL = 36h = ASCII ”6” AL,BCD_MASK ; AL = 06h = decimal 6 This example extracts the middle byte of a word so it can be used by another instruction.
  • Page 59: Bound Check Array Index Against Bounds

    BOUND*Check Array Index Against Bounds BOUND Clocks Form Opcode Description Am186 Am188 BOUND r16 , m16&16 62 /r Check to see if word register is within bounds 33–35 33–35 What It Does BOUND determines whether an integer falls between two boundaries. Syntax BOUND index,bounds Description...
  • Page 60 BOUND BOUND Examples This example compares a word in a table to the value in AX. Before the comparison, BOUND checks to see if the table index is within the range of the table. If it is not, the microcontroller generates Interrupt 5.
  • Page 61: Call Call Procedure

    CALL Call Procedure CALL Clocks Form Opcode Description Am186 Am188 CALL rel16 E8 cw Call near, displacement relative to next instruction CALL r/m16 FF /2 Call near, register indirect/memory indirect 13/19 17/27 CALL ptr16:16 9A cd Call far to full address given CALL m16:16 FF /3 Call far to address at m16:16 word...
  • Page 62 CALL CALL Operation It Performs /* save return offset */ push(IP); if ( procedure == rel16 ) /* near direct call */ IP = IP + rel16 ; if ( procedure == r/m16 ) /* near indirect call */ IP = [ r/m16 ]; if (( procedure == ptr16:16 ) || ( procedure == m16:16 )) /* far call */ /* save return segment */...
  • Page 63 CALL CALL Tips The assembler generates the correct call (near or far) based on the declaration of the called procedure. Related Instructions If you want to Stop executing the current sequence of instructions and begin executing another JMP End a procedure and return to the calling procedure Instruction Set 4-23...
  • Page 64: Cbw Convert Byte Integer To Word

    Convert Byte Integer to Word Clocks Form Opcode Description Am186 Am188 Put signed extension of AL in AX What It Does CBW converts an 8-bit integer to a sign-extended 16-bit integer. Syntax Description CBW converts the signed byte in the AL register to a signed word in the AX register by extending the most significant bit of the AL register (the sign bit) into all of the bits of the AH register.
  • Page 65 This example converts an 8-bit integer to its 16-bit equivalent before dividing it by an 8-bit integer. SDIVIDEND ; 65h SDIVISOR ; FDh ; divide byte integers AL,SDIVIDEND ; AL = 65h = 101 ; AX = 0065h = 101 IDIV SDIVISOR ;...
  • Page 66: Clc Clear Carry Flag

    Clear Carry Flag Clocks Form Opcode Description Am186 Am188 Clear Carry Flag What It Does CLC clears the Carry Flag (CF) to 0. Syntax Description CLC clears CF. Operation It Performs /* clear carry flag */ CF = 0; Flag Settings After Instruction OF DF IF TF SF ZF Processor Status...
  • Page 67 This example scans a string in memory until it finds a character or until the entire string is scanned. The microcontroller scans the bytes, one by one, from first to last. If the string contains the character, the microcontroller sets the Carry Flag (CF) to 1; otherwise, it clears CF to 0.
  • Page 68 Tips You can use CF to indicate the outcome of a procedure, such as when searching a string for a character. For instance, if the character is found, you can use STC to set CF to 1; if the character is not found, you can use CLC to clear CF to 0. Then, subsequent instructions that do not affect CF can use its value to determine the appropriate course of action.
  • Page 69: Cld Clear Direction Flag

    Clear Direction Flag Clocks Form Opcode Description Am186 Am188 Clear Direction Flag so the Source Index (SI) and/or the Destination Index (DI) registers will increment during string instructions What It Does CLD clears the Direction Flag (DF) to 0, causing subsequent repeated string instructions to process the components of a string from a lower address to a higher address.
  • Page 70 This example copies one string of 16-bit integers in memory to another string in the same segment. Because the Direction Flag (DF) is cleared to 0 using CLD, the microcontroller copies the words, one by one, from first to last. ;...
  • Page 71: Cli Clear Interrupt-Enable Flag

    Clear Interrupt-Enable Flag Clocks Form Opcode Description Am186 Am188 Clear Interrupt-Enable Flag (IF) What It Does CLI clears the Interrupt-Enable Flag (IF), disabling all maskable interrupts. Syntax Description CLI clears IF. Maskable external interrupts are not recognized at the end of the CLI instruction—or from that point on—until IF is set.
  • Page 72 Examples This example of an interrupt-service routine: enables interrupts so that interrupt nesting can occur, resets a device, disables interrupts until the interrupted procedure is resumed, and then clears the in-service bits in the In-Service (INSERV) register by writing to the End- Of-Interrupt (EOI) register.
  • Page 73: Cmc Complement Carry Flag

    Complement Carry Flag Clocks Form Opcode Description Am186 Am188 Complement Carry Flag What It Does CMC toggles the value of the Carry Flag (CF). Syntax Description CMC reverses the setting of CF. Operation It Performs /* toggle value of carry flag */ CF = ~ CF;...
  • Page 74: Cmp Compare Components

    Compare Components Clocks Form Opcode Description Am186 Am188 CMP AL, imm8 3C ib Compare immediate byte to AL CMP AX, imm16 3D iw Compare immediate word to AX CMP r/m8 , imm8 80 /7 ib Compare immediate byte to r/m byte 3/10 3/10 CMP r/m16 , imm16...
  • Page 75 Flag Settings After Instruction OF DF IF TF SF ZF Processor Status – – – reserved Flags Register ? = undefined; – = unchanged OF=1 if result larger than destination operand CF=1 for carry or borrow to high-order bit OF=0 otherwise CF=0 otherwise SF=1 if result is 0 or positive PF=1 if low byte of result has even number of set bits...
  • Page 76: Cmps Compare String Components

    CMPS Compare String Components CMPS CMPSB Compare String Bytes CMPSW Compare String Words Clocks Form Opcode Description Am186 Am188 CMPS m8 , m8 Compare byte ES:[DI] to byte segment:[SI] CMPS m16 , m16 Compare word ES:[DI] to word segment:[SI] CMPSB Compare byte ES:[DI] to byte DS:[SI] CMPSW Compare word ES:[DI] to word DS:[SI]...
  • Page 77 CMPS CMPS Operation It Performs if (size( destination ) == 8) /* compare bytes */ temp = DS:[SI] - ES:[DI]; /* compare */ if (DF == 0) /* forward */ increment = 1; else /* backward */ increment = -1; if (size( destination ) == 16) /* compare words */ temp = DS:[SI] - ES:[DI];...
  • Page 78 CMPS CMPS Examples This example compares for equality one string of nonzero words stored in the segment specified in ES to another string of nonzero words located in the same segment. The microcontroller compares the words, one by one, from first to last, unless any two words being compared don’t match.
  • Page 79 CMPS CMPS Tips Before using CMPS, always set up CX with the length of the string, and use CLD (forward) or STD (backward) to establish the direction for string processing. To determine whether one string is the same as another, use the REPE (or REPZ) prefix to execute CMPS repeatedly.
  • Page 80: Cwd Convert Word Integer To Doubleword

    Convert Word Integer to Doubleword Clocks Form Opcode Description Am186 Am188 Put signed extension of AX in DX::AX What It Does CWD converts a 16-bit integer to a sign-extended 32-bit integer. Syntax Description CWD converts the signed word in the AX register to a signed doubleword in the DX::AX register pair by extending the most significant bit of the AX register into all the bits of the DX register.
  • Page 81 This example divides one 16-bit integer by another 16-bit integer. SDIVIDEND -1675 ; F975h SDIVISOR ; 00C8h ; divide word integers AX,SDIVIDEND ; AX = F975h = -1675 ; DX::AX = FFFFF975h = -1675 IDIV SDIVISOR ; AX = FFF8h = -8, the quotient ;...
  • Page 82: Daa Decimal Adjust Al After Addition

    Decimal Adjust AL After Addition Clocks Form Opcode Description Am186 Am188 Decimal-adjust AL after addition What It Does DAA converts an 8-bit unsigned binary number that is the sum of two single-byte packed decimal (BCD) numbers to its packed decimal equivalent. Syntax Description Execute DAA only after executing an ADD or ADC instruction that leaves a two-BCD-digit...
  • Page 83 Flag Settings After Instruction OF DF IF TF SF ZF Processor Status – – – reserved Flags Register ? = undefined; – = unchanged CF=1 for carry or borrow to high-order bit CF=0 otherwise SF=1 if result is 0 or positive PF=1 if low byte of result has even number of set bits SF=0 if result is negative PF=0 otherwise...
  • Page 84 Tips ADC, ADD, SBB, and SUB set AF when the result needs to be converted for decimal arithmetic. AAA, AAS, DAA, and DAS use AF to determine whether an adjustment is needed. This is the only use for AF. Related Instructions If you want to Convert an 8-bit unsigned binary sum to its unpacked decimal equivalent Add two numbers and the value of CF...
  • Page 85: Das Decimal Adjust Al After Subtraction

    Decimal Adjust AL After Subtraction Clocks Form Opcode Description Am186 Am188 Decimal-adjust AL after subtraction What It Does DAS converts an 8-bit unsigned binary number that is the difference of two single-byte packed decimal (BCD) numbers to its packed decimal equivalent. Syntax Description Execute DAS only after a SUB or SBB instruction that leaves a two-BCD-digit byte result...
  • Page 86 Flag Settings After Instruction OF DF IF TF SF ZF Processor Status – – – reserved Flags Register ? = undefined; – = unchanged CF=1 for carry or borrow to high-order bit CF=0 otherwise SF=1 if result is 0 or positive PF=1 if low byte of result has even number of set bits SF=0 if result is negative PF=0 otherwise...
  • Page 87 Tips ADC, ADD, SBB, and SUB set AF when the result needs to be converted for decimal arithmetic. AAA, AAS, DAA, and DAS use AF to determine whether an adjustment is needed. This is the only use for AF. Related Instructions If you want to Convert an 8-bit unsigned binary difference to its unpacked decimal equivalent Convert an 8-bit unsigned binary sum to its packed decimal equivalent...
  • Page 88: Dec Decrement Number By One

    Decrement Number by One Clocks Form Opcode Description Am186 Am188 DEC r/m8 FE /1 Subtract 1 from r/m byte 3/15 3/15 DEC r/m16 FF /1 Subtract 1 from r/m word 3/15 3/19 DEC r16 48+ rw Subtract 1 from word register What It Does DEC subtracts 1 from an integer or an unsigned number.
  • Page 89 Examples This example sends events to another device. CMP, JE, DEC, and JMP implement a construct equivalent to the C-language while loop. COUNT 1048 ; number of events to send ; send events to another device SEND: COUNT,0 ; is count 0? DONE ;...
  • Page 90: Div Divide Unsigned Numbers

    Divide Unsigned Numbers Clocks Form Opcode Description Am186 Am188 DIV r/m8 F6 /6 AL=AX/(r/m byte); AH=remainder 29/35 29/35 DIV r/m16 F7 /6 AX=DX::AX/(r/m word); DX=remainder 38/44 38/48 What It Does DIV divides one unsigned number by another unsigned number. Syntax DIV divisor Description DIV operates on unsigned numbers.
  • Page 91 Flag Settings After Instruction OF DF IF TF SF ZF Processor Status – – – ? res ? res ? res ? reserved Flags Register ? = undefined; – = unchanged Examples This example divides an 8-bit unsigned number by another 8-bit unsigned number. UDIVIDEND ;...
  • Page 92 Tips DIV requires the dividend to be twice the size of the divisor. To convert an 8-bit unsigned dividend to its 16-bit equivalent (or a 16-bit dividend to its 32-bit equivalent), use MOV to load the high half with 0. If the unsigned dividend will fit in a 16-bit register and you don’t need the remainder, use SHR to divide unsigned numbers by powers of 2.
  • Page 93: Enter Enter High-Level Procedure

    ENTER* Enter High-Level Procedure ENTER Clocks Form Opcode Description Am186 Am188 ENTER imm16 , imm8 C8 iw ib Create stack frame for nested procedure 22+16( n –1) 26+20( n –1) ENTER imm16 ,0 C8 iw 00 Create stack frame for non-nested procedure ENTER imm16 ,1 C8 iw 01 Create stack frame for nested procedure What It Does...
  • Page 94 ENTER ENTER Operation It Performs /* convert level to a number between 0 and 31 */ level = level % 32; /* save base and frame pointers */ push(BP); framePointer = SP; if ( level > 0) /* reserve storage for each nesting level */ for (i = 1;i <...
  • Page 95 ENTER ENTER This example includes two procedures, each of which uses ENTER to create its own stack frame. Each procedure uses LEAVE to destroy its stack frame before returning to the procedure that called it. ; top-level procedure Main PROC ENTER ;...
  • Page 96: Esc Escape

    ESC* Escape Clocks Form Opcode Description Am186 Am188 ESC m D8 / 0 Takes trap 7. ESC m D9 / 1 Takes trap 7. ESC m DA / 2 Takes trap 7. ESC m DB / 3 Takes trap 7. ESC m DC / 4 Takes trap 7.
  • Page 97: Hlt Halt

    Halt Clocks Form Opcode Description Am186 Am188 Suspend instruction execution What It Does HLT causes the microcontroller to suspend instruction execution until it receives an interrupt request or it is reset. Syntax Description HLT places the microcontroller in a suspended state, leaving the CS and IP registers pointing to the instruction following HLT.
  • Page 98 Examples This example interrupt-service routine (ISR) flashes the LEDs that are mapped to eight of the microcontroller’s programmable input/output (PIO) pins and then suspends instruction execution. ; flash the LEDs a few times and stop executing instructions ISR_DEFAULT: PUSHA ; save general registers ;...
  • Page 99 Tips If you want a procedure to wait for an interrupt request, use HLT instead of an endless loop. On-board peripherals including timers, serial ports, and DMA continue to operate in HLT. These devices may issue interrupts which bring the processor out of HLT. Related Instructions If you want to Disable all maskable interrupts...
  • Page 100: Idiv Divide Integers

    IDIV Divide Integers IDIV Clocks Form Opcode Description Am186 Am188 IDIV r/m8 F6 /7 AL=AX/(r/m byte); AH=remainder 44–52/50–58 44–52/50–58 IDIV r/m16 F7 /7 AX=DX::AX/(r/m word); DX=remainder 53–61/59–67 53–61/63–71 What It Does IDIV divides one integer by another integer. Syntax IDIV divisor Description IDIV operates on signed numbers (integers).
  • Page 101 IDIV IDIV Operation It Performs if (size( divisor ) == 8) /* signed byte division */ temp = AX / divisor ; if (size(temp) > size(AL)) /* quotient too large */ interrupt(0); else AH = AX % divisor ; /* remainder */ AL = temp;...
  • Page 102 IDIV IDIV This example divides one 16-bit integer by another. SDIVIDEND 4800 ; 12C0h SDIVISOR -321 ; FEBFh ; divide word integers AX,SDIVIDEND ; AX = 12C0h = 4800 ; DX::AX = 000012C0h = 4800 IDIV SDIVISOR ; AX = 00F2h = -14, the quotient ;...
  • Page 103: Imul Multiply Integers

    IMUL* Multiply Integers IMUL Clocks Form Opcode Description Am186 Am188 IMUL r/m8 F6 /5 AX=(r/m byte)•AL 25–28/31–34 25–28/31–34 IMUL r/m16 F7 /5 DX::AX=(r/m word)•AX 34–37/40–43 34–37/44–47 IMUL r16 , r/m16 , imm8 6B /r ib (word register)=(r/m word)•(sign-ext. byte integer) 22–25 22–25 IMUL r16 , imm8...
  • Page 104 IMUL IMUL Operation It Performs if (operands() == 1) /* multiply multiplicand with accumulator */ if (size( multiplicand ) == 8) /* signed byte multiplication */ temp = multiplicand * AL; if (size(temp) == size(AL)) /* byte result */ /* store result */ AL = temp;...
  • Page 105 IMUL IMUL /* (continued) */ if (operands() == 2) /* substitute ”product” for multiplicand */ multiplicand = product ; if (operands() >= 2) temp = multiplicand * multiplier ; if (size(temp) == size( product )) /* product will fit */ /* store result */ product = temp;...
  • Page 106 IMUL IMUL Tips Use SAL instead of IMUL to multiply integers by powers of 2. When multiplying an integer by a power of 2, it is faster to use SAL than IMUL. When using the single-operand form of IMUL, you can often ignore the high half of the destination because the product is small enough to fit in only the low half of the destination.
  • Page 107: In Input Component From Port

    Input Component from Port Clocks Form Opcode Description Am186 Am188 IN AL, imm8 E4 ib Input byte from immediate port to AL IN AX, imm8 E5 ib Input word from immediate port to AX IN AL,DX Input byte from port in DX to AL IN AX,DX Input word from port in DX to AX What It Does...
  • Page 108 Examples This example reads ASCII characters from a port in I/O space to a string in memory. The microcontroller copies the bytes and stores them, one by one, from first to last. STRING 128 DUP (?) ; read characters from I/O port to string ;...
  • Page 109: Inc Increment Number By One

    Increment Number by One Clocks Form Opcode Description Am186 Am188 INC r/m8 FE /0 Increment r/m byte by 1 3/15 3/15 INC r/m16 FF /0 Increment r/m word by 1 3/15 3/19 INC r16 40+ rw Increment word register by 1 What It Does INC adds 1 to an integer or an unsigned number.
  • Page 110 Examples This example writes pixel values to a buffer. INC, CMP, and JL implement a construct equivalent to the C-language do-while loop. COUNT ; write pixel values to buffer CL,0 ; set up counter WRITE: ; write a pixel CALL WRITE_PIXEL ;...
  • Page 111: Ins Input String Component From Port

    INS* Input String Component from Port INSB Input String Byte from Port INSW Input String Word from Port Clocks Form Opcode Description Am186 Am188 INS m8 ,DX Input byte from port in DX to ES:[DI] INS m16 ,DX Input word from port in DX to ES:[DI] INSB Input byte from port in DX to ES:[DI] INSW...
  • Page 112 Operation It Performs if (size( destination ) == 8) /* input bytes */ ES:DI = [DX]; /* byte in I/O memory */ if DF == 0 /* forward */ increment = 1; else /* backward */ increment = -1; if (size( destination ) == 16) /* input words */ ES:DI = [DX];...
  • Page 113: Int Generate Interrupt

    Generate Interrupt INTO Generate Interrupt If Overflow Clocks Form Opcode Description Am186 Am188 INT 3 Generate interrupt 3 (trap to debugger) INT imm8 CD ib Generate type of interrupt specified by immediate byte INTO Generate interrupt 4 if Overflow Flag (OF) is 1 48,4 48,4 What It Does...
  • Page 114 Operation It Performs /* save flags */ push(FLAGS); /* clear trap and interrupt flags */ TF = IF = 0; /* save address of next instruction */ push(CS); push(IP); /* begin execution at location indicated by vector */ /* in interrupt vector table */ CS = [ type <<...
  • Page 115 Related Instructions If you want to Call a procedure CALL End an interrupt handler and resume the interrupted procedure IRET End a procedure and return to the calling procedure Instruction Set 4-75...
  • Page 116: Iret Interrupt Return

    IRET Interrupt Return IRET Clocks Form Opcode Description Am186 Am188 IRET Return from interrupt handler to interrupted procedure What It Does IRET ends an interrupt handler and resumes the interrupted procedure. Syntax IRET Description Used at the end of an interrupt handler, IRET restores the Instruction Pointer (IP) register, the Code Segment (CS) register, and the Processor Status Flags (FLAGS) register from the stack, and then resumes the interrupted procedure.
  • Page 117 IRET IRET Examples This example interrupt-service routine resets the Timer 1 Count (T1CNT) register. ; reset Timer 1 ISR_T0: PUSHA ; save general registers ; reset Timer 1 DX,TMR1_CNT_ADDR ; address of T1CNT register AX,0 ; reset count DX,AX ; write count to register ;...
  • Page 118: Ja Jump If Above

    Jump If Above JNBE Jump If Not Below or Equal Clocks Form Opcode Description Am186 Am188 JA rel8 77 cb Jump short if above (CF=0 and ZF=0) 13,4 13,4 JNBE rel8 77 cb Jump short if not below or equal (CF=0 and ZF=0) 13,4 13,4 What It Does...
  • Page 119 Examples This example converts a zero-terminated string to uppercase and replaces the original string. astring dup30db (?) ; set DS:[SI] and ES:[DI] to both point to astring PUSH ; save DS and ES PUSH AX, SEG astring DS,AX ES,AX DI,offset astring SI,offset astring LCONVERT_START: LODSB...
  • Page 120: Jae Jump If Above Or Equal

    Jump If Above or Equal Jump If Not Below Jump If Not Carry Clocks Form Opcode Description Am186 Am188 JAE rel8 73 cb Jump short if above or equal (CF=0) 13,4 13,4 JNB rel8 73 cb Jump short if not below (CF=0) 13,4 13,4 JNC rel8...
  • Page 121 Tips If you need to jump to an instruction at farlabel that is more than 128 bytes away, use the following sequence of statements: JNAE nearlabel ; This does the equivalent of a long jump JMP farlabel ; based on the JAE condition. nearlabel: Related Instructions If you want to...
  • Page 122: Jb Jump If Below

    Jump If Below Jump If Carry JNAE Jump If Not Above or Equal Clocks Form Opcode Description Am186 Am188 JB rel8 72 cb Jump short if below (CF=1) 13,4 13,4 JC rel8 72 cb Jump short if carry (CF=1) 13,4 13,4 JNAE rel8 72 cb...
  • Page 123 Examples This example checks the selection of 10 numbered items. ; check selection of 0-n+ item Num_items=10 ; 10 total items numbered (0-9) START_SEL: mGetSelection ; value in AL AL,Num_items ; compare to max# of items JNAE SEL_GOOD ; okay, selection in 0-(n-1) mPrintError START_SEL SEL_GOOD:...
  • Page 124: Jbe Jump If Below Or Equal

    Jump If Below or Equal Jump If Not Above Clocks Form Opcode Description Am186 Am188 JBE rel8 76 cb Jump short if below or equal (CF=1 or ZF=1) 13,4 13,4 JNA rel8 76 cb Jump short if not above (CF=1 or ZF=1) 13,4 13,4 What It Does...
  • Page 125 Tips If you need to jump to an instruction at farlabel that is more than 128 bytes away, use the following sequence of statements: JNBE nearlabel ; This does the equivalent of a long jump JMP farlabel ; based on the JBE condition. nearlabel: Related Instructions If you want to...
  • Page 126: Jc Jump If Carry

    Jump If Carry Clocks Form Opcode Description Am186 Am188 JC rel8 72 cb Jump short if carry (CF=1) 13,4 13,4 What It Does If the previous instruction sets the Carry Flag (CF), JB, JC, and JNAE stop executing the current sequence of instructions and begin executing a new sequence of instructions; otherwise, execution continues with the next instruction.
  • Page 127: Jcxz Jump If Cx Register Is Zero

    JCXZ Jump If CX Register Is Zero JCXZ Clocks Form Opcode Description Am186 Am188 JCXZ rel8 E3 cb Jump short if CX register is 0 15,5 15,5 What It Does If the previous instruction leaves 0 in CX, JCXZ stops executing the current sequence of instructions and begins executing a new sequence of instructions;...
  • Page 128 JCXZ JCXZ Examples This example waits for a character from the serial port. DEC, JCXZ, and JMP implement a construct equivalent to the C-language do-while loop. CMP and JNE implement an if statement within the loop. ; loop for a maximum number of times or until a ;...
  • Page 129: Je Jump If Equal

    Jump If Equal Jump If Zero Clocks Form Opcode Description Am186 Am188 JE rel8 74 cb Jump short if equal (ZF=1) 13,4 13,4 JZ rel8 74 cb Jump short if 0 (ZF=1) 13,4 13,4 What It Does If the previous instruction sets the Zero Flag (ZF), JE and JZ stop executing the current sequence of instructions and begin executing a new sequence of instructions;...
  • Page 130 Examples This example reads a character from the serial port, and then uses that character to select a menu item. CMP, JE, and JMP implement a construct equivalent to the C-language switch statement. ; display menu and read character from serial port into AX MENU: mREAD_SPORT_CHAR ;...
  • Page 131: Jg Jump If Greater

    Jump If Greater JNLE Jump If Not Less or Equal Clocks Form Opcode Description Am186 Am188 JG rel8 7F cb Jump short if greater (ZF=0 and SF=OF) 13,4 13,4 JNLE rel8 7F cb Jump short if not less or equal (ZF=0 and SF=OF) 13,4 13,4 What It Does...
  • Page 132 Tips If you need to jump to an instruction at farlabel that is more than 128 bytes away, use the following sequence of statements: JNG nearlabel ; This does the equivalent of a long jump JMP farlabel ; based on the JG condition. nearlabel: Related Instructions If you want to...
  • Page 133: Jl Jump If Less

    Jump If Greater or Equal Jump If Not Less Clocks Form Opcode Description Am186 Am188 JGE rel8 7D cb Jump short if greater or equal (SF=OF) 13,4 13,4 JNL rel8 7D cb Jump short if not less (SF=OF) 13,4 13,4 What It Does If the previous instruction modifies the Sign Flag (SF) and the Overflow Flag (OF) so that they are the same, JGE and JNL stop executing the current sequence of instructions and...
  • Page 134 Tips If you need to jump to an instruction at farlabel that is more than 128 bytes away, use the following sequence of statements: JNGE nearlabel ; This does the equivalent of a long jump JMP farlabel ; based on the JGE condition. nearlabel: Related Instructions If you want to...
  • Page 135 Jump If Less JNGE Jump If Not Greater or Equal Clocks Form Opcode Description Am186 Am188 JL rel8 7C cb Jump short if less (SF≠ OF) 13,4 13,4 JNGE rel8 7C cb Jump short if not greater or equal (SF≠OF) 13,4 13,4 What It Does...
  • Page 136 Tips If you need to jump to an instruction at farlabel that is more than 128 bytes away, use the following sequence of statements: JNL nearlabel ; This does the equivalent of a long jump JMP farlabel ; based on the JL condition. nearlabel: Related Instructions If you want to...
  • Page 137: Jle Jump If Less Or Equal

    Jump If Less or Equal Jump If Not Greater Clocks Form Opcode Description Am186 Am188 JLE rel8 7E cb Jump short if less or equal (ZF=1 or SF≠OF) 13,4 13,4 JNG rel8 7E cb Jump short if not greater (ZF=1 or SF≠OF) 13,4 13,4 What It Does...
  • Page 138 Tips If you need to jump to an instruction at farlabel that is more than 128 bytes away, use the following sequence of statements: JNLE nearlabel ; This does the equivalent of a long jump JMP farlabel ; based on the JLE condition. nearlabel: Related Instructions If you want to...
  • Page 139: Jmp Jump Unconditionally

    Jump Unconditionally Clocks Form Opcode Description Am186 Am188 JMP rel8 EB cb Jump short direct, displacement relative to next instruction JMP rel16 E9 cw Jump near direct, displacement relative to next instruction JMP r/m16 FF /4 Jump near indirect 11/17 11/21 JMP ptr16:16 EA cd...
  • Page 140 Operation It Performs if ( label == rel8 )/* short direct */ /* extend sign of label */ if ( label < 0) displacement = 0xFF00 | label ; else displacement = 0x00FF & label ; /* branch to labeled instruction */ IP = IP + displacement;...
  • Page 141 Examples This example uses the integer in DX to determine the course of action. CMP and JL implement a construct equivalent to a C-language if statement. CMP, JG, and JMP implement an if-else statement. ; branch according to the value of the integer in DX DX,0 ;...
  • Page 142: Jna Jump If Not Above

    Jump If Not Above Clocks Form Opcode Description Am186 Am188 JNA rel8 76 cb Jump short if not above (CF=1 or ZF=1) 13,4 13,4 What It Does If the previous instruction sets the Carry Flag (CF) or the Zero Flag (ZF), JBE and JNA stop executing the current sequence of instructions and begin executing a new sequence of instructions;...
  • Page 143: Jnae Jump If Not Above Or Equal

    JNAE Jump If Not Above or Equal JNAE Clocks Form Opcode Description Am186 Am188 JNAE rel8 72 cb Jump short if not above or equal (CF=1) 13,4 13,4 What It Does If the previous instruction sets the Carry Flag (CF), JB, JC, and JNAE stop executing the current sequence of instructions and begin executing a new sequence of instructions;...
  • Page 144: Jnb Jump If Not Below

    Jump If Not Below Clocks Form Opcode Description Am186 Am188 JNB rel8 73 cb Jump short if not below (CF=0) 13,4 13,4 What It Does If the previous instruction clears the Carry Flag (CF), JAE, JNB, and JNC stop executing the current sequence of instructions and begin executing a new sequence of instructions;...
  • Page 145: Jnbe Jump If Not Below Or Equal

    JNBE Jump If Not Below or Equal JNBE Clocks Form Opcode Description Am186 Am188 JNBE rel8 77 cb Jump short if not below or equal (CF=0 and ZF=0) 13,4 13,4 What It Does If the previous instruction clears the Carry Flag (CF) and the Zero Flag (ZF), JA and JNBE stop executing the current sequence of instructions and begin executing a new sequence of instructions;...
  • Page 146: Jnc Jump If Not Carry

    Jump If Not Carry Clocks Form Opcode Description Am186 Am188 JNC rel8 73 cb Jump short if not carry (CF=0) 13,4 13,4 What It Does If the previous instruction clears the Carry Flag (CF), JAE, JNB, and JNC stop executing the current sequence of instructions and begin executing a new sequence of instructions;...
  • Page 147: Jne Jump If Not Equal

    Jump If Not Equal Jump If Not Zero Clocks Form Opcode Description Am186 Am188 JNE rel8 75 cb Jump short if not equal (ZF=0) 13,4 13,4 JNZ rel8 75 cb Jump short if not zero (ZF=0) 13,4 13,4 What It Does If the previous instruction clears the Zero Flag (ZF), JNE and JNZ stop executing the current sequence of instructions and begin executing a new sequence of instructions;...
  • Page 148 Examples This example subtracts an integer or an unsigned number in DX from another number of the same type in AX, and then uses the difference to determine the course of action. SUB and JNE implement a construct equivalent to a C-language if statement. ;...
  • Page 149: Jng Jump If Not Greater

    Jump If Not Greater Clocks Form Opcode Description Am186 Am188 JNG rel8 7E cb Jump short if not greater (ZF=1 or SF≠OF) 13,4 13,4 What It Does If the previous instruction sets the Zero Flag (ZF), or modifies the Sign Flag (SF) and the Overflow Flag (OF) so that they are not the same, JLE and JNG stop executing the current sequence of instructions and begin executing a new sequence of instructions;...
  • Page 150: Jnge Jump If Not Greater Or Equal

    JNGE Jump If Not Greater or Equal JNGE Clocks Form Opcode Description Am186 Am188 JNGE rel8 7C cb Jump short if not greater or equal (SF≠OF) 13,4 13,4 What It Does If the previous instruction modifies the Sign Flag (SF) and the Overflow Flag (OF) so that they are not the same, JL and JNGE stop executing the current sequence of instructions and begin executing a new sequence of instructions;...
  • Page 151: Jnl Jump If Not Less

    Jump If Not Less Clocks Form Opcode Description Am186 Am188 JNL rel8 7D cb Jump short if not less (SF=OF) 13,4 13,4 What It Does If the previous instruction modifies the Sign Flag (SF) and the Overflow Flag (OF) so that they are the same, JGE and JNL stop executing the current sequence of instructions and begin executing a new sequence of instructions;...
  • Page 152: Jnle Jump If Not Less Or Equal

    JNLE Jump If Not Less or Equal JNLE Clocks Form Opcode Description Am186 Am188 JNLE rel8 7F cb Jump short if not less or equal (ZF=0 and SF=OF) 13,4 13,4 What It Does If the previous instruction clears the Zero Flag (ZF), and modifies the Sign Flag (SF) and the Overflow Flag (OF) so that they are the same, JG and JNLE stop executing the current sequence of instructions and begin executing a new sequence of instructions;...
  • Page 153: Jno Jump If Not Overflow

    Jump If Not Overflow Clocks Form Opcode Description Am186 Am188 JNO rel8 71 cb Jump short if not overflow (OF=0) 13,4 13,4 What It Does If the previous instruction clears the Overflow Flag (OF), JNO stops executing the current sequence of instructions and begins executing a new sequence of instructions; otherwise, execution continues with the next instruction.
  • Page 154 Tips If you need to jump to an instruction at farlabel that is more than 128 bytes away, use the following sequence of statements: JO nearlabel ; This does the equivalent of a long jump JMP farlabel ; based on the JNO condition. nearlabel: Related Instructions If you want to...
  • Page 155: Jnp Jump If Not Parity

    Jump If Not Parity Clocks Form Opcode Description Am186 Am188 JNP rel8 7B cb Jump short if not parity (PF=0) 13,4 13,4 What It Does If the previous instruction clears the Parity Flag (PF), JPO and JNP stop executing the current sequence of instructions and begin executing a new sequence of instructions;...
  • Page 156: Jns Jump If Not Sign

    Jump If Not Sign Clocks Form Opcode Description Am186 Am188 JNS rel8 79 cb Jump short if not sign (SF=0) 13,4 13,4 What It Does If the previous instruction clears the Sign Flag (SF), JNS stops executing the current sequence of instructions and begins executing a new sequence of instructions; otherwise, execution continues with the next instruction.
  • Page 157 Tips If you need to jump to an instruction at farlabel that is more than 128 bytes away, use the following sequence of statements: JS nearlabel ; This does the equivalent of a long jump JMP farlabel ; based on the JNS condition. nearlabel: Related Instructions If you want to...
  • Page 158: Jnz Jump If Not Zero

    Jump If Not Zero Clocks Form Opcode Description Am186 Am188 JNZ rel8 75 cb Jump short if not zero (ZF=0) 13,4 13,4 What It Does If the previous instruction clears the Zero Flag (ZF), JNE and JNZ stop executing the current sequence of instructions and begin executing a new sequence of instructions;...
  • Page 159: Jo Jump If Overflow

    Jump If Overflow Clocks Form Opcode Description Am186 Am188 JO rel8 70 cb Jump short if overflow (OF=1) 13,4 13,4 What It Does If the previous instruction sets the Overflow Flag (OF), JO stops executing the current sequence of instructions and begins executing a new sequence of instructions; otherwise, execution continues with the next instruction.
  • Page 160 Related Instructions If you want to Compare two components using subtraction and set the flags accordingly Jump unconditionally Jump if the result of a previous operation cleared OF to 0 Set the flags according to whether particular bits of a component are set to 1 TEST 4-120 Instruction Set...
  • Page 161: Jp Jump If Parity

    Jump If Parity Clocks Form Opcode Description Am186 Am188 JP rel8 7A cb Jump short if parity (PF=1) 13,4 13,4 What It Does If the previous instruction sets the Parity Flag (PF), JPE and JP stop executing the current sequence of instructions and begin executing a new sequence of instructions; otherwise, execution continues with the next instruction.
  • Page 162: Jpe Jump If Parity Even

    Jump If Parity Even Jump If Parity Clocks Form Opcode Description Am186 Am188 JPE rel8 7A cb Jump short if parity even (PF=1) 13,4 13,4 JP rel8 7A cb Jump short if parity (PF=1) 13,4 13,4 What It Does If the previous instruction sets the Parity Flag (PF), JPE and JP stop executing the current sequence of instructions and begin executing a new sequence of instructions;...
  • Page 163 Tips If you need to jump to an instruction at farlabel that is more than 128 bytes away, use the following sequence of statements: JPO nearlabel ; This does the equivalent of a long jump JMP farlabel ; based on the JPE condition. nearlabel: Related Instructions If you want to...
  • Page 164: Jpo Jump If Parity Odd

    Jump If Parity Odd Jump If Not Parity Clocks Form Opcode Description Am186 Am188 JPO rel8 7B cb Jump short if parity odd (PF=0) 13,4 13,4 JNP rel8 7B cb Jump short if not parity (PF=0) 13,4 13,4 What It Does If the previous instruction clears the Parity Flag (PF), JPO and JNP stop executing the current sequence of instructions and begin executing a new sequence of instructions;...
  • Page 165 Tips If you need to jump to an instruction at farlabel that is more than 128 bytes away, use the following sequence of statements: JPE nearlabel ; This does the equivalent of a long jump JMP farlabel ; based on the JPO condition. nearlabel: Related Instructions If you want to...
  • Page 166: Js Jump If Sign

    Jump If Sign Clocks Form Opcode Description Am186 Am188 JS rel8 78 cb Jump short if sign (SF=1) 13,4 13,4 What It Does If the previous instruction sets the Sign Flag (SF), JS stops executing the current sequence of instructions and begins executing a new sequence of instructions; otherwise, execution continues with the next instruction.
  • Page 167 Tips If you need to jump to an instruction at farlabel that is more than 128 bytes away, use the following sequence of statements: JNS nearlabel ; This does the equivalent of a long jump JMP farlabel ; based on the JS condition. nearlabel: Related Instructions If you want to...
  • Page 168: Jz Jump If Zero

    Jump If Zero Clocks Form Opcode Description Am186 Am188 JZ rel8 74 cb Jump short if 0 (ZF=1) 13,4 13,4 What It Does If the previous instruction sets the Zero Flag (ZF), JE and JZ stop executing the current sequence of instructions and begin executing a new sequence of instructions; otherwise, execution continues with the next instruction.
  • Page 169: Lahf Load Ah With Flags

    LAHF Load AH with Flags LAHF Clocks Form Opcode Description Am186 Am188 LAHF Load AH with low byte of Processor Status Flags register What It Does LAHF copies the low byte of the Processor Status Flags (FLAGS) register to AH. Syntax LAHF Description...
  • Page 170 LAHF LAHF This example prevents an intervening instruction from modifying the Carry Flag (CF), which is used to indicate the status of a hardware device. SMINUEND -6726 SSUBTRAHEND 22531 ; prevent subtraction from modifying CF, which is used ; as a device status indicator ;...
  • Page 171: Lds Load Ds With Segment And Register With Offset

    Load DS with Segment and Register with Offset LDS Clocks Form Opcode Description Am186 Am188 LDS r16,m16:16 C5 /r Load DS:r16 with segment:offset from memory What It Does LDS copies the segment portion of a full address stored in a doubleword to DS, and copies the offset portion of the full address to another register.
  • Page 172 Related Instructions If you want to Load the offset of a memory component into a register Load a full address stored in a doubleword into ES and another register 4-132 Instruction Set...
  • Page 173: Lea Load Effective Address

    Load Effective Address Clocks Form Opcode Description Am186 Am188 LEA r16,m16 8D /r Load offset for m16 word in 16-bit register What It Does LEA loads the offset of a memory component into a register. Syntax LEA offset,component Description LEA calculates the effective address (offset part) of the component and stores it in the specified register.
  • Page 174 Related Instructions If you want to Load a full address stored in a doubleword into DS and another register Load a full address stored in a doubleword into ES and another register 4-134 Instruction Set...
  • Page 175: Leave Leave High-Level Procedure

    LEAVE* Leave High-Level Procedure LEAVE Clocks Form Opcode Description Am186 Am188 LEAVE Destroy procedure stack frame What It Does LEAVE removes the storage for the local variables of a procedure from the stack. Syntax LEAVE Description LEAVE destroys the stack frame created by ENTER. LEAVE releases the portion of the stack allocated for the procedure’s local variables by copying BP to SP, and then restores the calling procedure’s frame by popping its frame pointer into BP.
  • Page 176 LEAVE LEAVE Examples This example procedure uses ENTER to: push the current frame pointer (BP) onto the stack, set up BP to point to its stack frame, reserve 4 bytes on the stack for its local variables, and indicate that it is not called by another procedure. The procedure uses LEAVE to remove the local variables from the stack and restore BP.
  • Page 177 LEAVE LEAVE This example includes two procedures, each of which uses ENTER to create its own stack frame. Each procedure uses LEAVE to destroy its stack frame before returning to the procedure that called it. ; top-level procedure Main PROC ENTER ;...
  • Page 178: Les Load Es With Segment And Register With Offset

    Load ES with Segment and Register with Offset LES Clocks Form Opcode Description Am186 Am188 LES r16,m16:16 C4 /r Load ES:r16 with segment:offset from memory What It Does LES copies the segment portion of a full address stored in a doubleword to ES, and copies the offset portion of the full address to another register.
  • Page 179 Examples This example copies several of the characters in a string stored in memory to a series of bytes in the same string that overlap the original characters. The microcontroller copies the bytes, one by one, from last to first to avoid overwriting the source bytes. ;...
  • Page 180: Lock Lock The Bus

    LOCK* Lock the Bus LOCK Prefix Clocks Form Description Am186 Am188 Opcode LOCK Asserts LOCK during an instruction execution What It Does The LOCK prefix asserts the LOCK signal for the specified instruction to prevent an external master from requesting the bus. Syntax LOCK instr Description...
  • Page 181: Lods Load String Component

    LODS Load String Component LODS LODSB Load String Byte LODSW Load String Word Clocks Form Opcode Description Am186 Am188 LODS m8 Load byte segment:[SI] in AL LODS m16 Load word segment:[SI] in AX LODSB Load byte DS:[SI] in AL LODSW Load word DS:[SI] in AX What It Does LODS copies a component from a string to a register.
  • Page 182 LODS LODS Operation It Performs if (size( source ) == 8) /* load bytes */ AL = DS:[SI]; if (DF == 0) /* forward */ increment = 1; else /* backward */ increment = -1; if (size( source ) == 16) /* load words */ AX = DS:[SI];...
  • Page 183 LODS LODS Examples This example copies a string of 16-bit integers in one segment to a string in another segment. The microcontroller copies the words and changes their sign—one by one, from first to last—before storing them in the other string. Before setting up the registers for the string operation, this example exchanges DS for ES in order to address the destination string using ES.
  • Page 184 LODS LODS This example counts the number of carriage returns in a string of characters in memory. The microcontroller copies the bytes and compares them with the carriage-return character, one by one, from first to last. STRING 512 DUP (?) ;...
  • Page 185 LODS LODS Related Instructions If you want to Process string components from lower to higher addresses Copy a component from a port in I/O memory to a string in main memory Copy a component from one string to another string MOVS Copy a component from a string in main memory to a port in I/O memory OUTS...
  • Page 186: Loop Loop While Cx Register Is Not Zero

    LOOP Loop While CX Register Is Not Zero LOOP Clocks Form Opcode Description Am186 Am188 LOOP rel8 Decrement count; jump short if CX≠ 0 16,6 16,6 What It Does LOOP repeatedly executes a sequence of instructions; an unsigned number in CX tells the microcontroller how many times to execute the sequence.
  • Page 187 LOOP LOOP Examples This example converts a list of unpacked decimal digits in memory to their ASCII equivalents. LIST 01h,08h,06h L_LENGTH ; convert a list of unpacked BCD digits to ASCII SI,0 ; point to first byte in list CX,L_LENGTH ;...
  • Page 188: Loope Loop If Equal

    LOOPE Loop If Equal LOOPE LOOPZ Loop If Zero Clocks Form Opcode Description Am186 Am188 LOOPE rel8 E1 cb Decrement count; jump short if CX≠ 0 and ZF=1 16,6 16,6 LOOPZ rel8 E1 cb Decrement count; jump short if CX≠ 0 and ZF=1 16,6 16,6 What It Does...
  • Page 189 LOOPE LOOPE Flag Settings After Instruction OF DF IF TF SF ZF Processor Status – – – – – – res – res – res – reserved Flags Register ? = undefined; – = unchanged Examples This example searches one row of a table in memory for a number other than 0. If the row contains a number other than 0, the microcontroller sets the Carry Flag (CF) to 1;...
  • Page 190: Loopne Loop If Not Equal

    LOOPNE Loop If Not Equal LOOPNE LOOPNZ Loop If Not Zero Clocks Form Opcode Description Am186 Am188 LOOPNE rel8 E0 cb Decrement count; jump short if CX≠ 0 and ZF=0 16,6 16,6 LOOPNZ rel8 E0 cb Decrement count; jump short if CX≠ 0 and ZF=0 16,6 16,6 What It Does...
  • Page 191 LOOPNE LOOPNE Flag Settings After Instruction OF DF IF TF SF ZF Processor Status – – – – – – res – res – res – reserved Flags Register ? = undefined; – = unchanged Examples This example searches a list of characters stored in memory for a null character. If the list contains a null character, the microcontroller sets the Carry Flag (CF) to 1;...
  • Page 192: Loopz Loop If Zero

    LOOPZ Loop If Zero LOOPZ Clocks Form Opcode Description Am186 Am188 LOOPZ rel8 E1 cb Decrement count; jump short if CX≠ 0 and ZF=1 16,6 16,6 What It Does LOOPE and LOOPZ repeatedly execute a sequence of instructions in which two components are compared;...
  • Page 193: Mov Move Component

    Move Component Clocks Form Opcode Description Am186 Am188 MOV r/m8,r8 88 /r Copy register to r/m byte MOV r/m16,r16 89 /r Copy register to r/m word MOV r8,r/m8 8A /r Copy r/m byte to register MOV r16,r/m16 8B /r Copy r/m word to register MOV r/m16,sreg 8C /sr Copy segment register to r/m word...
  • Page 194 Examples This example defines and sets up the stack for a program. ; define stack segment SEG_STACK SEGMENT ’STACK’ 500 DUP (?) STACK: SEG_STACK ENDS ; set up stack (in code segment) AX,SEG_STACK ; load stack segment into SS SS,AX ;...
  • Page 195 This example sets up the Data Segment (DS) register and the Extra Segment (ES) register with different segment addresses. ; set up DS and ES with different segment addresses ; direct assembler that DS and ES point to ; different segments of memory ASSUME DS:SEG_A, ES:SEG_B ;...
  • Page 196: Movs Move String Component

    MOVS Move String Component MOVS MOVSB Move String Byte MOVSW Move String Word Clocks Form Opcode Description Am186 Am188 MOVS m8,m8 Copy byte segment:[SI] to ES:[DI] MOVS m16,m16 Copy word segment:[SI] to ES:[DI] MOVSB Copy byte DS:[SI] to ES:[DI] MOVSW Copy word DS:[SI] to ES:[DI] What It Does MOVS copies a component from one string to another string.
  • Page 197 MOVS MOVS Operation It Performs if (size( destination ) == 8) /* copy bytes */ ES:[DI] = DS:[SI]; if (DF == 0) /* forward */ increment = 1; else /* backward */ increment = -1; if (size( destination ) == 16) /* copy words */ ES:[DI] = DS:[SI];...
  • Page 198 MOVS MOVS Examples This example copies several of the characters in a string stored in memory to a series of bytes in the same string that overlap the original characters. The microcontroller copies the bytes, one by one, from last to first to avoid overwriting the source bytes. ;...
  • Page 199 MOVS MOVS This example copies one string of 16-bit integers stored in memory to another string located in the same segment. Because the Direction Flag (DF) is cleared to 0 using CLD, the microcontroller copies the words, one by one, from first to last. ;...
  • Page 200: Mul Multiply Unsigned Numbers

    Multiply Unsigned Numbers Clocks Form Opcode Description Am186 Am188 MUL r/m8 F6 /4 AX=(r/m byte)•AL 26–28/32–34 26–28/32–34 MUL r/m16 F7 /4 DX::AX=(r/m word)•AX 35–37/41–43 35–37/45–47 What It Does MUL multiplies two unsigned numbers. Syntax mul multiplicand Description MUL operates on unsigned numbers. The operand you specify is the multiplicand. MUL assumes that the number by which it is to be multiplied (the multiplier) is in AL or AX.
  • Page 201 Operation It Performs /* multiply multiplicand with accumulator */ if (size( multiplicand ) == 8) /* unsigned byte multiplication */ temp = multiplicand * AL; if (size(temp) == size(AL)) /* byte result */ /* store result */ AL = temp; /* extend into AX */ AH = 0x00;...
  • Page 202 Flag Settings After Instruction OF DF IF TF SF ZF Processor Status – – – ? res ? res ? res reserved Flags Register ? = undefined; – = unchanged OF and CF = 0 if upper half of result is 0 OF and CF = 1 otherwise Examples This example multiplies a 16-bit unsigned number in CX by a 16-bit unsigned number in...
  • Page 203: Neg Two's Complement Negation

    Two’s Complement Negation Clocks Form Opcode Description Am186 Am188 NEG r/m8 F6 /3 Perform a two’s complement negation of r/m byte 3/10 3/10 NEG r/m16 F7 /3 Perform a two’s complement negation of r/m word 3/10 3/14 What It Does NEG changes the sign of an integer.
  • Page 204 Examples This example uses addition to find the difference between two integers. INTEGER1 2000 ; 7D0h INTEGER2 1600 ; 640h ; calculate difference using sign change and addition INTEGER2 ; INTEGER2 = F9C0h = -1600 ; signed addition: INTEGER1 = INTEGER1 + INTEGER2 INTEGER1,INTEGER2 ;...
  • Page 205: Nop No Operation

    No Operation Clocks Form Opcode Description Am186 Am188 Perform no operation What It Does NOP expends clock cycles exchanging AX with itself. Syntax Description NOP performs no operation. It is a 1-byte instruction that takes up space in the code segment, but affects none of the machine context except the instruction pointer.
  • Page 206 Tips Use NOP during a debugging session to fill code space left vacant after replacing an instruction with a shorter instruction. Related Instructions If you want to Suspend instruction execution 4-166 Instruction Set...
  • Page 207: Not One's Complement Negation

    One’s Complement Negation Clocks Form Opcode Description Am186 Am188 NOT r/m8 F6 /2 Complement each bit in r/m byte 3/10 3/10 NOT r/m16 F7 /2 Complement each bit in r/m word 3/10 3/14 What It Does NOT toggles all bits of a component. Syntax NOT component Description...
  • Page 208 This example for the SD186EM demonstration board controls the LEDs that are mapped (using negative logic) to eight of the microcontroller’s programmable input/output (PIO) pins according to the signal levels in AL. Because some of the LEDs on the board are mapped to the low eight PIO pins (5–0)—and some are mapped to the next eight PIO pins (15–...
  • Page 209: Or Logical Inclusive Or

    Logical Inclusive OR Clocks Form Opcode Description Am186 Am188 OR AL, imm8 0C ib OR immediate byte with AL OR AX, imm16 0D iw OR immediate word with AX OR r/m8,imm8 80 /1 ib OR immediate byte with r/m byte 4/16 4/16 OR r/m16,imm16...
  • Page 210 Examples This example converts an unpacked decimal digit to its ASCII equivalent. ASCII_MASK ; decimal-to-ASCII mask BCD_NUM ; convert decimal number to ASCII AL,BCD_NUM ; AL = 06h = 6 AL,ASCII_MASK ; AL = 36h = ASCII ’6’ Tips To convert an unpacked decimal digit to its ASCII equivalent, use OR to add 30h (ASCII 0) to the digit.
  • Page 211: Out Output Component To Port

    Output Component to Port Clocks Form Opcode Description Am186 Am188 OUT imm8 ,AL E6 ib Output AL to immediate port OUT imm8 ,AX E7 ib Output AX to immediate port OUT DX,AL Output AL to port in DX OUT DX,AX Output AX to port in DX What It Does OUT copies a component from a register to a port in I/O memory.
  • Page 212 Examples This example for the SD186EM demonstration board lights all of the LEDs that are mapped to eight of the PIO pins on the microcontroller. ; assert PIO pins 15-14 and 5-0 ; set up PIO pins 15-0 as outputs DX,PIO_DIR0_ADDR ;...
  • Page 213: Outs Output String Component To Port

    OUTS* Output String Component to Port OUTS OUTSB Output String Byte to Port OUTSW Output String Word to Port Clocks Form Opcode Description Am186 Am188 OUTS DX, m8 Output byte DS:[SI] to port in DX OUTS DX, m16 Output word DS:[SI] to port in DX OUTSB Output byte DS:[SI] to port in DX OUTSW...
  • Page 214 OUTS OUTS Operation It Performs if (size( source ) == 8) /* output bytes */ [DX] = DS:[SI]; if (DF == 0) /* forward */ increment = 1; else /* backward */ increment = -1; if (size( source ) == 16) /* output words */ [DX] = DS:[SI];...
  • Page 215: Pop Pop Component From Stack

    Pop Component from Stack Clocks Form Opcode Description Am186 Am188 POP m16 8F /0 Pop top word of stack into memory word POP r16 58+ rw Pop top word of stack into word register POP DS Pop top word of stack into DS POP ES Pop top word of stack into ES POP SS...
  • Page 216 Examples This example copies a string of 16-bit integers in one segment of memory to a string in another segment. The words are copied, one by one, from last to first. ; defined in SEG_A STRING1 -30000,10250,31450,21540,-16180 S1_LENGTH ; defined in SEG_B STRING2 S1_LENGTH DUP (?) S2_END_ADDR...
  • Page 217 This example procedure for the SD186EM demonstration board turns an LED on or off by toggling the signal level of programmable I/O (PIO) pin 3 in the PIO Data 0 (PDATA0) register. PIO3_MASK 0008h ; PDATA0 bit 3 ; toggle PDATA0 bit 3 TOGGLE_PIO3 PROC NEAR...
  • Page 218: Popa Pop All 16-Bit General Registers From Stack

    POPA* Pop All 16-Bit General Registers from Stack POPA Clocks Form Opcode Description Am186 Am188 POPA Pop DI, SI, BP, BX, DX, CX, and AX What It Does POPA copies each of eight components from the top of the stack to one of the 16-bit general registers and then removes the storage space for the components from the stack.
  • Page 219 POPA POPA Examples This example of an interrupt-service routine enables interrupts so that interrupt nesting can occur, resets a device, disables interrupts until the interrupted procedure is resumed, and then clears the in-service bits in the In-Service (INSERV) register by writing to the End-Of- Interrupt (EOI) register.
  • Page 220: Popf Pop Flags From Stack

    POPF Pop Flags from Stack POPF Clocks Form Opcode Description Am186 Am188 POPF Pop top word of stack into Processor Status Flags register What It Does POPF copies a component from the top of the stack, loads it into the Processor Status Flags (FLAGS) register, and then removes the storage space for the component from the stack.
  • Page 221: Push Push Component Onto Stack

    PUSH* Push Component onto Stack PUSH Clocks Form Opcode Description Am186 Am188 PUSH m16 FF /6 Push memory word onto stack PUSH r16 50+ rw Push register word onto stack PUSH imm8 Push sign-extended immediate byte onto stack PUSH imm16 Push immediate word onto stack PUSH CS Push CS onto stack...
  • Page 222 PUSH PUSH Examples This example copies a string of 16-bit integers in one segment to a string in another segment. The microcontroller copies the words and changes their sign—one by one, from first to last—before storing them in the other string. Before setting up the registers for the string operation, this example exchanges DS for ES in order to address the destination string using ES.
  • Page 223 PUSH PUSH This example procedure turns an LED on or off by toggling the signal level of programmable I/O (PIO) pin 3 in the PIO Data 0 (PDATA0) register. PIO3_MASK 0008h ; PDATA0 bit 3 ; toggle PDATA0 bit 3 TOGGLE_PIO3 PROC NEAR...
  • Page 224: Pusha Push All 16-Bit General Registers Onto Stack

    PUSHA* Push All 16-Bit General Registers onto Stack PUSHA Clocks Form Opcode Description Am186 Am188 PUSHA Push AX, CX, DX, BX, original SP, BP, SI, and DI What It Does PUSHA creates storage space for eight components on the stack and then copies each of the eight 16-bit general registers to the stack.
  • Page 225 PUSHA PUSHA Examples This example of an interrupt-service routine enables interrupts so that interrupt nesting can occur, resets a device, disables interrupts until the interrupted procedure is resumed, and then clears the in-service bits in the In-Service (INSERV) register by writing to the End-Of- Interrupt (EOI) register.
  • Page 226: Pushf Push Flags Onto Stack

    PUSHF Push Flags onto Stack PUSHF Clocks Form Opcode Description Am186 Am188 PUSHF Push Processor Status Flags register What It Does PUSHF creates storage space for a component on the stack and then copies the Processor Status Flags (FLAGS) register to the stack. Syntax PUSHF Description...
  • Page 227: Rcl Rotate Through Carry Left

    RCL* Rotate through Carry Left Clocks Form Opcode Description Am186 Am188 RCL r/m8 ,1 D0 /2 Rotate 9 bits of CF and r/m byte left once 2/15 2/15 RCL r/m8 ,CL D2 /2 Rotate 9 bits of CF and r/m byte left CL times 5+ n /17+ n 5+ n /17+ n RCL r/m8,imm8...
  • Page 228 Flag Settings After Instruction If count =0, flags are unaffected. Otherwise, flags are affected as shown below: OF DF IF TF SF ZF Processor Status reserved – – – – – res – res – res Flags Register ? = undefined; – = unchanged Undefined unless single-bit rotation, then: CF=value of bit shifted into it OF=1 if result larger than destination operand...
  • Page 229: Rcr Rotate Through Carry Right

    RCR* Rotate through Carry Right Clocks Form Opcode Description Am186 Am188 RCR r/m8 ,1 D0 /3 Rotate 9 bits of CF and r/m byte right once 2/15 2/15 RCR r/m8 ,CL D2 /3 Rotate 9 bits of CF and r/m byte right CL times 5+ n /17+ n 5+ n /17+ n RCR r/m8,imm8...
  • Page 230 Flag Settings After Instruction If count =0, flags are unaffected. Otherwise, flags are affected as shown below: OF DF IF TF SF ZF Processor Status reserved – – – – – res – res – res Flags Register ? = undefined; – = unchanged Undefined unless single-bit rotation, then: CF=value of bit shifted into it OF=1 if result larger than destination operand...
  • Page 231: Rep Repeat

    Repeat Clocks Form Prefix Opcode Description Am186 Am188 REP INS m8 ,DX Input CX bytes from port in DX to ES:[DI] 8+8 n 8+8 n REP INS m16 ,DX Input CX words from port in DX to ES:[DI] 8+8 n 12+8 n REP LODS m8 6+11 n...
  • Page 232 Flag Settings After Instruction Instruction prefixes do not affect the flags. See the instruction being repeated for the flag values. Examples This example copies one string of ASCII characters stored in memory to another string in the same segment. The microcontroller copies the characters, one by one, from first to last. ;...
  • Page 233: Repe Repeat While Equal

    REPE Repeat While Equal REPE REPZ Repeat While Zero Clocks Form Prefix Opcode Description Am186 Am188 REPE CMPS m8,m8 5+22 n 5+22 n Find nonmatching bytes in ES:[DI] and segment:[SI] REPE CMPS m16,m16 F3 Find nonmatching words in ES:[DI] and segment:[SI] 5+22 n 9+22 n REPE SCAS m8...
  • Page 234 REPE REPE Operation It Performs while (CX != 0) /* repeat while equal */ serviceInterrupts(); execute( instruction ); /* decrement counter */ CX = CX - 1; if (ZF == 0) /* not equal */ break; Flag Settings After Instruction Instruction prefixes do not affect the flags.
  • Page 235 REPE REPE Examples This example compares one string of bytes in memory with another string in the same segment until it finds a mismatch or all bytes are compared. The microcontroller copies the bytes, one by one, from first to last. If the strings are different, the following instructions save the segment and offset of the first mismatch.
  • Page 236 REPE REPE Tips To determine the appropriate course of action after a repeated string comparison instruction, use JCXZ to test CX, and use JZ and JNZ to test ZF. To repeat a block of instructions, use LOOPE or another looping construct. Related Instructions If you want to Process string components from lower to higher addresses...
  • Page 237: Repne Repeat While Not Equal

    REPNE Repeat While Not Equal REPNE REPNZ Repeat While Not Zero Clocks Form Prefix Opcode Description Am186 Am188 REPNE CMPS m8,m8 5+22 n 5+22 n Find matching bytes in ES:DI and segment:[SI] REPNE CMPS m16,m16 F2 Find matching words in ES:DI and segment:[SI] 5+22 n 9+22 n REPNZ CMPS m8,m8...
  • Page 238 REPNE REPNE Operation It Performs while (CX != 0) /* repeat while not equal */ serviceInterrupts(); execute( instruction ); /* decrement counter */ CX = CX - 1; if (ZF == 1) /* equal */ break; Flag Settings After Instruction Instruction prefixes do not affect the flags.
  • Page 239 REPNE REPNE Examples This example scans a string of 16-bit integers in memory until it finds a particular integer or the entire string is scanned. The microcontroller scans the words, one by one, from first to last. If the string contains the integer, the following instructions save the segment and offset of the integer.
  • Page 240 REPNE REPNE Tips To determine the appropriate course of action after a repeated string comparison instruction, use JCXZ to test CX, and use JZ and JNZ to test ZF. To repeat a block of instructions, use LOOPNE or another looping construct. Related Instructions If you want to Process string components from lower to higher addresses...
  • Page 241: Repz Repeat While Zero

    REPZ Repeat While Zero REPZ Clocks Form Prefix Opcode Description Am186 Am188 REPZ CMPS m8,m8 Find nonmatching bytes in ES:DI and segment:[SI] 5+22 n 5+22 n REPZ CMPS m16,m16 F3 Find nonmatching words in ES:DI and segment:[SI] 5+22 n 9+22 n REPZ SCAS m8 5+15 n 5+15 n...
  • Page 242: Ret Return From Procedure

    Return from Procedure Clocks Form Opcode Description Am186 Am188 Return near to calling procedure Return far to calling procedure RET imm16 C2 iw Return near; pop imm16 parameters RET imm16 CA iw Return far; pop imm16 parameters What It Does Used at the end of a called procedure, RET restores the Instruction Pointer (IP) register and the Code Segment (CS) register (if necessary) and releases any input parameters from the stack before resuming the calling procedure.
  • Page 243 Operation It Performs /* copy return offset from stack */ IP = SS:[SP]; /* remove storage from stack */ SP = SP + 2; /* If far return */ if opcode==CB or opcode==CA /* copy return segment from stack */ CS = SS:[SP];...
  • Page 244 Examples This example writes a zero-terminated string to the serial port in polled mode. The full address (segment:offset) of the string is passed as an input parameter on the stack. ; initialize and program serial port for transmit ; write zero-terminated string to serial port in polled mode ;...
  • Page 245: Rol Rotate Left

    ROL* Rotate Left Clocks Form Opcode Description Am186 Am188 ROL r/m8 ,1 D0 /0 Rotate 8 bits of r/m byte left once 2/15 2/15 ROL r/m8 ,CL D2 /0 Rotate 8 bits of r/m byte left CL times 5+ n /17+ n 5+ n /17+ n ROL r/m8,imm8 C0 /0 ib...
  • Page 246 Flag Settings After Instruction If count =0, flags are unaffected. Otherwise, flags are affected as shown below: OF DF IF TF SF ZF Processor Status reserved – – – – – res – res – res Flags Register ? = undefined; – = unchanged Undefined unless single-bit rotation, then: CF=value of top bit copied into it OF=1 if result larger than destination operand...
  • Page 247: Ror Rotate Right

    ROR* Rotate Right Clocks Form Opcode Description Am186 Am188 ROR r/m8 ,1 D0 /1 Rotate 8 bits of r/m byte right once 2/15 2/15 ROR r/m8 ,CL D2 /1 Rotate 8 bits of r/m byte right CL times 5+ n /17+ n 5+ n /17+ n ROR r/m8,imm8 C0 /1 ib...
  • Page 248 Flag Settings After Instruction If count =0, flags are unaffected. Otherwise, flags are affected as shown below: OF DF IF TF SF ZF Processor Status reserved – – – – – res – res – res Flags Register ? = undefined; – = unchanged Undefined unless single-bit rotation, then: CF=value of top bit copied into it OF=1 if result larger than destination operand...
  • Page 249: Sahf Store Ah In Flags

    SAHF Store AH in Flags SAHF Clocks Form Opcode Description Am186 Am188 SAHF Store AH in low byte of the Processor Status Flags register What It Does SAHF copies AH to the low byte of the Processor Status Flags (FLAGS) register. Syntax SAHF Description...
  • Page 250 SAHF SAHF This example prevents an intervening instruction from modifying the Carry Flag (CF), which is used to indicate the status of a hardware device. UMINUEND 6726 ; 1A46h USUBTRAHEND 48531 ; BD93h ; check to see if device is on or off ;...
  • Page 251: Sal Shift Arithmetic Left

    SAL* Shift Arithmetic Left Shift Left Clocks Form Opcode Description Am186 Am188 SAL r/m8 ,1 D0 /4 Multiply r/m byte by 2, once 2/15 2/15 SAL r/m8 ,CL D2 /4 Multiply r/m byte by 2, CL times 5+ n /17+ n 5+ n /17+ n SAL r/m8,imm8 C0 /4 ib...
  • Page 252 Operation It Performs while (i = count ; i != 0; i--) /* perform shifts */ /* store highest bit in carry flag */ CF = mostSignificantBit( component ); /* shift left and fill vacancy with 0 */ component = component << 1; if (count == 1) /* single shift */ if (mostSignificantBit( component ) != CF)
  • Page 253 This example extracts the middle byte of a word so it can be used by another instruction. SETTINGS 1234h ; extract middle byte of AX and place in AH AX,SETTINGS ; AX = 1234h AX,0FF0h ; mask middle byte: AX = 0230h AX,4 ;...
  • Page 254: Sar Shift Arithmetic Right

    SAR* Shift Arithmetic Right Clocks Form Opcode Description Am186 Am188 SAR r/m8 ,1 D0 /7 Perform a signed division of r/m byte by 2, once 2/15 2/15 SAR r/m8 ,CL D2 /7 Perform a signed division of r/m byte by 2, CL times 5+ n /17+ n 5+ n /17+ n SAR r/m8,imm8...
  • Page 255 Flag Settings After Instruction If count =0, flags are unaffected. Otherwise, flags are affected as shown below: OF DF IF TF SF ZF Processor Status reserved – – – res ? res res 0 Flags Register ? = undefined; – = unchanged CF=0 unless shift lengths are less than or Undefined unless single-bit shift, then: equal to the size of the shifted operand,...
  • Page 256: Sbb Subtract Numbers With Borrow

    Subtract Numbers with Borrow Clocks Form Opcode Description Am186 Am188 SBB AL, imm8 1C ib Subtract immediate byte from AL with borrow SBB AX, imm16 1D iw Subtract immediate word from AX with borrow SBB r/m8,imm8 80 /3 ib Subtract immediate byte from r/m byte with borrow 4/16 4/16 SBB r/m16,imm16...
  • Page 257 Flag Settings After Instruction OF DF IF TF SF ZF Processor Status – – – reserved Flags Register ? = undefined; – = unchanged OF=1 if result larger than destination operand CF=1 for carry or borrow to high-order bit OF=0 otherwise CF=0 otherwise SF=1 if result is 0 or positive PF=1 if low byte of result has even number of set bits...
  • Page 258 This example subtracts one 32-bit integer in a register (the subtrahend) from another 32- bit integer in memory (the minuend). This is accomplished by subtracting one word at a time. The first subtraction uses SUB, and the subsequent subtraction uses SBB in case a borrow was generated by the previous subtraction.
  • Page 259: Scas Scan String For Component

    SCAS Scan String for Component SCAS SCASB Scan String for Byte SCASW Scan String for Word Clocks Form Opcode Description Am186 Am188 SCAS m8 Compare byte AL to ES:[DI]; update DI SCAS m16 Compare word AX to ES:[DI]; update DI SCASB Compare byte AL to ES:[DI];...
  • Page 260 SCAS SCAS Operation It Performs if (size( destination ) == 8) /* compare bytes */ temp = AL - ES:[DI]; if (DF == 0) /* forward */ increment = 1; else /* backward */ increment = -1; if (size( destination ) == 16) /* compare words */ temp = AX - ES:[DI];...
  • Page 261 SCAS SCAS Examples This example scans a list of words in memory until it finds a value that is different or all words are compared. The microcontroller scans the words, one by one, from first to last. ; defined in SEG_L LIST 32 DUP (?) FILL...
  • Page 262 SCAS SCAS This example scans a string in memory until it finds a character or the entire string is scanned. The microcontroller scans the bytes, one by one, from first to last. If the string contains the character, the microcontroller sets the Carry Flag (CF) to 1; otherwise, it clears CF to 0.
  • Page 263 SCAS SCAS Tips Before using SCAS, always be sure to: set up DI with the offset of the string, set up CX with the length of the string, and use CLD (forward) or STD (backward) to establish the direction for string processing. To scan a string for a value that is different from a given value, use the REPE (or REPZ) prefix to execute SCAS repeatedly.
  • Page 264: Shl Shift Left

    SHL* Shift Left Clocks Form Opcode Description Am186 Am188 SHL r/m8 ,1 D0 /4 Multiply r/m byte by 2, once 2/15 2/15 SHL r/m8 ,CL D2 /4 Multiply r/m byte by 2, CL times 5+ n /17+ n 5+ n /17+ n SHL r/m8,imm8 C0 /4 ib 5+ n /17+ n...
  • Page 265: Shr Shift Right

    SHR* Shift Right Clocks Form Opcode Description Am186 Am188 SHR r/m8 ,1 D0 /5 Divide unsigned r/m byte by 2, once 2/15 2/15 SHR r/m8 ,CL D2 /5 Divide unsigned r/m byte by 2, CL times 5+ n /17+ n 5+ n /17+ n SHR r/m8,imm8 C0 /5 ib...
  • Page 266 Flag Settings After Instruction If count =0, flags are unaffected. Otherwise, flags are affected as shown below: OF DF IF TF SF ZF Processor Status reserved – – – res ? res res 0 Flags Register ? = undefined; – = unchanged CF=0 unless shift lengths are less than or Undefined unless single-bit shift, then: equal to the size of the shifted operand,...
  • Page 267 Tips Use SHR to isolate part of a component. If the dividend will fit in a 16-bit register and you don’t need the remainder, use SHR to divide unsigned numbers by powers of 2. When dividing an unsigned number by a power of 2, it is faster to use SHR than DIV.
  • Page 268: Stc Set Carry Flag

    Set Carry Flag Clocks Form Opcode Description Am186 Am188 Set the Carry Flag to 1 What It Does STC sets the Carry Flag (CF) to 1. Syntax Description STC sets CF. Operation It Performs /* set carry flag */ CF = 1; Flag Settings After Instruction OF DF IF TF SF ZF...
  • Page 269 This example scans a string in memory until it finds a character or the entire string is scanned. The microcontroller scans the bytes, one by one, from first to last. If the string contains the character, the microcontroller sets the Carry Flag (CF) to 1; otherwise, it clears CF to 0.
  • Page 270 Tips You can use CF to indicate the outcome of a procedure, such as when searching a string for a character. For instance, if the character is found, you can use STC to set CF to 1; if the character is not found, you can use CLC to clear CF to 0. Then, subsequent instructions that do not affect CF can use its value to determine the appropriate course of action.
  • Page 271: Std Set Direction Flag

    Set Direction Flag Clocks Form Opcode Description Am186 Am188 Set the Direction Flag so the Source Index (SI) and/or the Destination Index (DI) registers will decrement during string instructions What It Does STD sets the Direction Flag (DF) to 1, causing subsequent string instructions to process the components of a string from a higher address to a lower address.
  • Page 272 Examples This example fills a workspace in memory with multiple copies of a string of ASCII characters (a pattern) in the same segment. The characters are copied, one by one, from last to first. ; defined in SEG_T segment WORKSPACE 100h DUP (?) ;...
  • Page 273 This example copies a string of 16-bit integers in one segment of memory to a string in another segment. The words are copied, one by one, from last to first. ; defined in SEG_A STRING1 -30000,10250,31450,21540,-16180 S1_LENGTH ; defined in SEG_B STRING2 S1_LENGTH DUP (?) S2_END_ADDR...
  • Page 274 Tips Before using one of the string instructions (CMPS, INS, LODS, MOVS, OUTS, SCAS, or STOS), always set up CX with the length of the string, and use CLD (forward) or STD (backward) to establish the direction for string processing. The string instructions always advance SI and/or DI, regardless of the use of the REP prefix.
  • Page 275: Sti Set Interrupt-Enable Flag

    Set Interrupt-Enable Flag Clocks Form Opcode Description Am186 Am188 Enable maskable interrupts after the next instruction What It Does STI sets the Interrupt-Enable Flag (IF), enabling all maskable interrupts that are not masked by their interrupt control registers. Syntax Description STI sets the Interrupt-Enable Flag (IF).
  • Page 276 Examples This example of an interrupt-service routine: enables interrupts so that interrupt nesting can occur, resets a device, disables interrupts until the interrupted procedure is resumed, and then clears the in-service bits in the In-Service (INSERV) register by writing to the End- Of-Interrupt (EOI) register.
  • Page 277: Stos Store String Component

    STOS Store String Component STOS STOSB Store String Byte STOSW Store String Word Clocks Form Opcode Description Am186 Am188 STOS m8 Store AL in byte ES:[DI]; update DI STOS m16 Store AX in word ES:[DI]; update DI STOSB Store AL in byte ES:[DI]; update DI STOSW Store AX in word ES:[DI];...
  • Page 278 STOS STOS Operation It Performs if (size( destination ) == 8) /* store bytes */ ES:[DI] = AL; if (DF == 0) /* forward */ increment = 1; else /* backward */ increment = -1; if (size( destination ) == 16) /* store words */ ES:[DI] = AX;...
  • Page 279 STOS STOS Tips Before using STOS, always be sure to: set up DI with the offset of the string, set up CX with the length of the string, and use CLD (forward) or STD (backward) to establish the direction for string processing. To fill a string with a given value, use the REP prefix to execute STOS repeatedly.
  • Page 280: Sub Subtract Numbers

    Subtract Numbers Clocks Form Opcode Description Am186 Am188 SUB AL, imm8 2C ib Subtract immediate byte from AL SUB AX, imm16 2D iw Subtract immediate word from AX SUB r/m8,imm8 80 /5 ib Subtract immediate byte from r/m byte 4/16 4/16 SUB r/m16,imm16 81 /5 iw...
  • Page 281 Flag Settings After Instruction OF DF IF TF SF ZF Processor Status – – – reserved Flags Register ? = undefined; – = unchanged OF=1 if result larger than destination operand CF=1 for carry or borrow to high-order bit OF=0 otherwise CF=0 otherwise SF=1 if result is 0 or positive PF=1 if low byte of result has even number of set bits...
  • Page 282 Tips To subtract an integer or an unsigned number located in memory from another number of the same type that is also located in memory, copy one of them to a register before using SUB. SUB requires both operands to be the same size. Before subtracting an 8-bit integer from a 16-bit integer, convert the 8-bit integer to its 16-bit equivalent using CBW.
  • Page 283: Test Logical Compare

    TEST Logical Compare TEST Clocks Form Opcode Description Am186 Am188 TEST AL, imm8 A8 ib AND immediate byte with AL TEST AX, imm16 A9 iw AND immediate word with AX TEST r/m8,imm8 F6 /0 ib AND immediate byte with r/m byte 4/10 4/10 TEST r/m16,imm16...
  • Page 284 TEST TEST Examples This example tests the value of a bit that a particular device sets to 1 when an error occurs. If the tested bit is 1, the microcontroller jumps to an instruction sequence designed to reset the device. Otherwise, the microcontroller continues with the following instruction. DEVICE5 00100000b ;...
  • Page 285: Wait Wait For Coprocessor

    WAIT* Wait for Coprocessor WAIT Clocks Form Opcode Description Am186 Am188 WAIT Performs a NOP. What It Does WAIT is unimplemented and performs a NOP. Syntax WAIT Description Members of the Am186 and Am188 family of microcontrollers do not have a TEST pin, and executing WAIT is the same as performing a NOP.
  • Page 286: Xchg Exchange Components

    XCHG Exchange Components XCHG Clocks Form Opcode Description Am186 Am188 XCHG AX, r16 90+ rw Exchange word register with AX XCHG r16 ,AX 90+ rw Exchange AX with word register XCHG r/m8 , r8 86 /r Exchange byte register with r/m byte 4/17 4/17 XCHG r8 , r/m8...
  • Page 287 XCHG XCHG This example performs a bubble sort on a list of unsigned numbers in memory. The microcontroller rearranges the list from smallest to largest. LIST 3,5,2,9,7 L_LENGTH ; sort unsigned numbers SI,0 ; set up list index DX,L_LENGTH - 1 ;...
  • Page 288: Xlat Translate Table Index To Component

    XLAT Translate Table Index to Component XLAT XLATB Translate Table Index to Byte Clocks Form Opcode Description Am186 Am188 XLAT m8 Set AL to memory byte segment:[BX+unsigned AL] XLATB Set AL to memory byte DS:[BX+unsigned AL] What It Does XLAT translates the offset index of a byte stored in memory to the value of that byte. Syntax Use this form to override the default source segment XLAT base...
  • Page 289 XLAT XLAT Examples This example translates a string of ASCII numbers in memory to unpacked decimal digits. The microcontroller translates the numbers, one by one, from first to last. ; defined in SEG_D segment TABLE 0,1,2,3,4,5,6,7,8,9 STRING ”0123456789” ; notify assembler: DS and ES specify the ;...
  • Page 290 XLAT XLAT Tips Use XLAT to translate bytes from one code system to another (e.g., from unpacked decimal numbers to ASCII numbers or from ASCII characters to EBCDIC characters). Related Instructions If you want to Load the offset of a table in memory into BX 4-250 Instruction Set...
  • Page 291: Xor Logical Exclusive Or

    Logical Exclusive OR Clocks Form Opcode Description Am186 Am188 XOR AL, imm8 34 ib XOR immediate byte with AL XOR AX, imm16 35 iw XOR immediate word with AX XOR r/m8,imm8 80 /6 ib XOR immediate byte with r/m byte 4/16 4/16 XOR r/m16,imm16...
  • Page 292 Examples This example turns on Timer 2 by setting the Enable (EN) and Inhibit (INH) bits in the Timer 2 Mode and Control (T2CON) register. TMR2_CNT_ON 0C000h ; mask for enable & inhibit bits ; turn on Timer 2 DX,TMR2_CTL_ADDR ;...
  • Page 293 APPENDIX INSTRUCTION SET SUMMARY This appendix provides several tables that summarize the instructions for the Am186 and Am188 family of microcontrollers: Table A-2, “Instruction Set Summary by Mnemonic,” on page A-3 Table A-3, “Instruction Set Summary by Opcode,” on page A-10 Table A-4, “Instruction Set Summary by Partial Opcode,”...
  • Page 294 Table A-1 Variables Used In Instruction Set Summary Tables Variable Function Values Description Specifies direction. to r/m to reg data-8 Specifies a non-address constant data used by the data-low instruction. The "8" indicates an 8-bit constant; "low", data-high the low-order byte of a 16-bit constant; "high", the data-SX high order byte of a 16-bit constant;...
  • Page 295 Table A-2 Instruction Set Summary by Mnemonic More Instruction Opcode Info., Page AAA = ASCII adjust AL after add 0 0 1 1 0 1 1 1 AAD = ASCII adjust AX before divide 1 1 0 1 0 1 0 1 0 0 0 0 1 0 1 0 AAM = ASCII adjust AL after multiply 1 1 0 1 0 1 0 0...
  • Page 296 Table A-2 Instruction Set Summary by Mnemonic More Instruction Opcode Info., Page CMP = Compare: 4-34 Reg/memory and register to either 0 0 1 1 1 0 d w mod reg r/m Immediate with register/memory 1 0 0 0 0 0 s w mod 111 r/m data-8/data-low data-high if sw=01...
  • Page 297 Table A-2 Instruction Set Summary by Mnemonic More Instruction Opcode Info., Page INTO = Interrupt on overflow 1 1 0 0 1 1 1 0 4-73 IRET = Interrupt return 1 1 0 0 1 1 1 1 4-76 JA/JNBE = Jump on: above/not below 0 1 1 1 0 1 1 1 disp-8 4-78...
  • Page 298 Table A-2 Instruction Set Summary by Mnemonic More Instruction Opcode Info., Page LEAVE = Leave procedure* 1 1 0 0 1 0 0 1 4-135 (mod ≠ 11) LES = Load pointer to ES 1 1 0 0 0 1 0 0 mod reg r/m 4-138 LOCK = Bus lock prefix***...
  • Page 299 Table A-2 Instruction Set Summary by Mnemonic More Instruction Opcode Info., Page POP = Pop: 4-175 Memory 1 0 0 0 1 1 1 1 mod 000 r/m Register 0 1 0 1 1 reg (sreg ≠01) Segment register 0 0 0 sreg 1 1 1 POPA = Pop All* 0 1 1 0 0 0 0 1 4-178...
  • Page 300 Table A-2 Instruction Set Summary by Mnemonic More Instruction Opcode Info., Page RET = Return from CALL: 4-202 Within segment 1 1 0 0 0 0 1 1 Within seg adding immed. to SP 1 1 0 0 0 0 1 0 data-low data-high Intersegment...
  • Page 301 Table A-2 Instruction Set Summary by Mnemonic More Instruction Opcode Info., Page STD = Set direction flag 1 1 1 1 1 1 0 1 4-231 STI = Set interrupt-enable flag 1 1 1 1 1 0 1 1 4-235 STOS/STOSB/STOSW = Store string 1 0 1 0 1 0 1 w 4-237...
  • Page 302 Table A-3 Instruction Set Summary by Opcode Opcode Instruction Format Byte 1 Byte 2 Bytes 3–6 Binary 0000 0000 mod reg r/m (disp-low),(disp-high) ADD r/m8,r8 0000 0001 mod reg r/m (disp-low),(disp-high) ADD r/m16,r16 0000 0010 mod reg r/m (disp-low),(disp-high) ADD r8,r/m8 0000 0011 mod reg r/m (disp-low),(disp-high)
  • Page 303 Table A-3 Instruction Set Summary by Opcode Opcode Instruction Format Byte 1 Byte 2 Bytes 3–6 Binary 0010 1010 mod reg r/m (disp-low),(disp-high) SUB r8,r/m8 0010 1011 mod reg r/m (disp-low),(disp-high) SUB r16,r/m16 0010 1100 data-8 SUB AL,imm8 0010 1101 data-low data-high SUB AX,imm16...
  • Page 304 Table A-3 Instruction Set Summary by Opcode Opcode Instruction Format Byte 1 Byte 2 Bytes 3–6 Binary 0101 0011 PUSH BX 0101 0100 PUSH SP 0101 0101 PUSH BP 0101 0110 PUSH SI 0101 0111 PUSH DI 0101 1000 POP AX 0101 1001 POP CX 0101 1010...
  • Page 305 Table A-3 Instruction Set Summary by Opcode Opcode Instruction Format Byte 1 Byte 2 Bytes 3–6 Binary 0111 0101 disp-8 JNE rel8 JNZ rel8 0111 0110 disp-8 JBE rel8 JNA rel8 0111 0111 disp-8 JA rel8 JNBE rel8 0111 1000 disp-8 JS rel8 0111 1001...
  • Page 306 Table A-3 Instruction Set Summary by Opcode Opcode Instruction Format Byte 1 Byte 2 Bytes 3–6 Binary 1000 0100 mod reg r/m (disp-low),(disp-high) TEST r/m8,r8 1000 0101 mod reg r/m (disp-low),(disp-high) TEST r/m16,r16 1000 0110 mod reg r/m (disp-low),(disp-high) XCHG r/m8,r8 XCHG r8,r/m8 1000 0111 mod reg r/m...
  • Page 307 Table A-3 Instruction Set Summary by Opcode Opcode Instruction Format Byte 1 Byte 2 Bytes 3–6 Binary 1010 0101 MOVS m16,m16 MOVSW 1010 0110 CMPS m8,m8 CMPSB 1010 0111 CMPS m16,m16 CMPSW 1010 1000 data-8 TEST AL,imm8 1010 1001 data-low data-high TEST AX,imm16 1010 1010...
  • Page 308 Table A-3 Instruction Set Summary by Opcode Opcode Instruction Format Byte 1 Byte 2 Bytes 3–6 Binary 1100 0001 mod 000 r/m (disp-low),(disp-high),data-8 ROL r/m16,imm8 mod 001 r/m (disp-low),(disp-high),data-8 ROR r/m16,imm8 mod 010 r/m (disp-low),(disp-high),data-8 RCL r/m16,imm8 mod 011 r/m (disp-low),(disp-high),data-8 RCR r/m16,imm8 mod 100 r/m...
  • Page 309 Table A-3 Instruction Set Summary by Opcode Opcode Instruction Format Byte 1 Byte 2 Bytes 3–6 Binary 1101 0010 mod 000 r/m (disp-low),(disp-high) ROL r/m8,CL mod 001 r/m (disp-low),(disp-high) ROR r/m8,CL mod 010 r/m (disp-low),(disp-high) RCL r/m8,CL mod 011 r/m (disp-low),(disp-high) RCR r/m8,CL mod 100 r/m...
  • Page 310 Table A-3 Instruction Set Summary by Opcode Opcode Instruction Format Byte 1 Byte 2 Bytes 3–6 Binary 1110 1011 disp-8 JMP rel8 1110 1100 IN AL,DX 1110 1101 IN AX,DX 1110 1110 OUT DX,AL 1110 1111 OUT DX,AX 1111 0000 LOCK (prefix) 1111 0001 reserved...
  • Page 311 Table A-3 Instruction Set Summary by Opcode Opcode Instruction Format Byte 1 Byte 2 Bytes 3–6 Binary 1111 0111 mod 000 r/m (disp-low),(disp-high),data-low, data-high TEST r/m16,imm16 mod 001 r/m reserved mod 010 r/m (disp-low),(disp-high) NOT r/m16 mod 011 r/m (disp-low),(disp-high) NEG r/m16 mod 100 r/m (disp-low),(disp-high)
  • Page 312 Table A-4 Instruction Set Summary by Partial Opcode PUSH r/m8,r8 r/m16,r16 r8,r/m8 r16,r/m16 AL,imm8 AX,imm16 PUSH r/m8,r8 r/m16,r16 r8,r/m8 r16,r/m16 AL,imm8 AX,imm16 (ES seg. reg. override r/m8,r8 r/m16,r16 r8,r/m8 r16,r/m16 AL,imm8 AX,imm16 prefix) (SS seg. reg. override r/m8,r8 r/m16,r16 r8,r/m8 r16,r/m16 AL,imm8 AX,imm16...
  • Page 313 Table A-4 Instruction Set Summary by Partial Opcode (continued) PUSH (reserved) r/m8,r8 r/m16,r16 r8,r/m8 r16,r/m16 AL,imm8 AX,imm16 PUSH r/m8,r8 r/m16,r16 r8,r/m8 r16,r/m16 AL,imm8 AX,imm16 (CS seg. reg. override r/m8,r8 r/m16,r16 r8,r/m8 r16,r/m16 AL,imm8 AX,imm16 prefix) (DS seg. reg. override r/m8,r8 r/m16,r16 r8,r/m8 r16,r/m16...
  • Page 314 Table A-5 Abbreviations for Table A-4 Instruction Group Immed Shift Instr1 Instr2 Instr3 Byte 2 mod 000 r/m TEST INC r/m16 mod 001 r/m (reserved) DEC r/m16 mod 010 r/m (reserved) CALL r/m16 mod 011 r/m (reserved) CALL m16:16 mod 100 r/m SAL/SHL (reserved) JMP r/m16...
  • Page 315: Index

    INDEX SAL (Shift Arithmetic Left) instruction, 4-211 SAR (Shift Arithmetic Right) instruction, 4-214 AAA (ASCII Adjust AL after Addition) instruction, 4-2 SBB (Subtract Numbers with Borrow) instruction, 4-216 AAD (ASCII Adjust AX before Division) instruction, 4-4 SHL (Shift Left) instruction, 4-211, 4-224 AAM (ASCII Adjust AL after Multiplication) instruction, SHR (Shift Right) instruction, 4-225 SUB (Subtract Numbers) instruction, 4-240...
  • Page 316 INT (Generate Interrupt) instruction, 4-73 LAHF (Load AH with Flags) instruction, 4-129 INTO (Generate Interrupt If Overflow) instruction, 4-73 list of, 3-5 IRET (Interrupt Return) instruction, 4-76 LODS (Load String Component) instruction, 4-141 JA (Jump If Above) instruction, 4-78 LODSB (Load String Byte) instruction, 4-141 JAE (Jump If Above or Equal) instruction, 4-80 LODSW (Load String Word) instruction, 4-141 JB (Jump If Below) instruction, 4-82...
  • Page 317 DIV (Divide Unsigned Numbers) instruction, 4-50 4-173 documentation OUTSB (Output String Byte to Port) instruction, 4-173 AMD E86 Family publications, iv OUTSW (Output String Word to Port) instruction, 4-173 INS (Input String Component from Port) instruction, 4-71 INSB (Input String Byte from Port) instruction, 4-71...
  • Page 318 JNL (Jump If Not Less) instruction, 4-93 JNLE (Jump If Not Less or Equal) instruction, 4-91 memory addressing modes JNO (Jump If Not Overflow) instruction, 4-113 based indexed mode, 1-7 based indexed mode with displacement, 1-7 JNP (Jump If Not Parity) instruction, 4-124 based mode, 1-7 JNS (Jump If Not Sign) instruction, 4-116 direct mode, 1-7...
  • Page 319 POPA (Pop All 16-Bit General Registers from Stack) extra segment (ES), 1-5 instruction, 4-178 segment register selection rules, 1-5 stack segment (SS), 1-5 POPF (Pop Flags from Stack) instruction, 4-180 SHL (Shift Left) instruction, 4-211, 4-224 processor control instructions ESC (Escape) instruction, 4-56 SHR (Shift Right) instruction, 4-225 HLT (Halt) instruction, 4-57 stack pointer register, 1-1...
  • Page 320 summary tables abbreviations for partial opcode table, A-22 instruction set summary by mnemonic, A-3–, A-9 instruction set summary by opcode, A-10–, A-19 instruction set summary by partial opcode, A-20–, A-21 variables used in instruction set, A-2 TEST (Logical Compare) instruction, 4-243 using this manual, 2-4 description, 2-6 examples, 2-7...

This manual is also suitable for:

Am188 series

Table of Contents