Top Banner
Chapter 6 - 8086 instruction description and assembler directives from Microprocessors and Interfacing by Douglas Hall
34
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • Chapter 6 - 8086 instruction description and assembler directives

    from Microprocessors and Interfacing by Douglas Hall

  • OutlineInstruction DescriptionAssembler Directives

  • Instruction Description(contd.)AAA ASCII Adjust for Addition8086 allows you to add ASCII codes for two decimal digits without masking of the 3 in upper nibble of each.After the addition, the AAA instruction is used to make sure that the result is the correct unpacked BCD.The AAA instruction works only on AL register.AAD BCD to binary convert before DivisionConverts two unpacked BCD digits in AH and AL to the equivalent binary number in AL.After the Division the AL will contain the unpacked BCD quotient and AH will contain the unpacked BCD remainder.

  • Instruction Description(contd.)AAM BCD Adjust for MultiplyAfter the two BCD digits are multiplied the AAM instruction is used to adjust the product to two unpacked BCD digits in AX.Works only on an operand in AL.Updates PF, SF and ZF.AAS ASCII Adjust for Subtraction8086 allows you to subtract ASCII codes for two decimal digits without masking of the 3 in upper nibble of each.After the subtraction, the AAA instruction is used to make sure that the result is the correct unpacked BCD.The AAS instruction leaves the correct unpacked BCD result in the low nibble of AL.

  • Instruction Description(contd.)ADC Add with Carry, ADD AdditionADC source, destination: adds the number from source to the number in destination and then stores the result in destination and the carry in CF.ADD source, destination: Does similar things as the ADC but do not store the carry in CF. Rather it discards the carry.ANDAND destination, source: ANDs each bit in the source byte or word with each bit in the destination byte or word.The result is put into specified destination register/location, the contents of the source does not change.

  • Instruction Description(contd.)CALL Call a procedureUsed to transfer the execution to another subprogram or procedure. There are two basic types:NEAR: a call to a procedure which is in the same code segment as the CALL instruction.FAR: a call to a procedure which is in different segment then the CALL instruction.CBW Convert signed Byte to signed WordCopies the sign of a byte in AL to all the bits in the AH.AH is then said to be the sign extension of the AL.The CBW must be done before a signed byte in AL can be divided by another signed byte with the IDIV instruction.

  • Instruction Description(contd.)CLC, CLD, CLI, CMCCLC: Instruction resets the carry flag to 0.CLD: resets the direction flag to 0.CLI: resets the interrupt flag to 0.CMC: complement the carry flag i.e. from 01 and from 10.CMP Compare byte or wordCMP destination, source: this instruction compares the byte from the source to the byte in the destination or a word from the specified source to the word from the specified destination.Flags AF, OF, SF, ZF, PF and CF flags are updated to show the result of the comparison.

  • Instruction Description(contd.)CMPS/CMPSB/CMPSW Compare String Bytes or String WordsUsed to compare a byte in one string with the byte in another string or a word in one string with the word in another string.SI is used to hold offset of source string and DI is used for the destination string.CWD Convert signed Word to signed Double WordCopies the sign bit of a word in AX to all the bits in the DX register.It must be done before the signed word in AX is divisible by another signed word with the IDIV instruction.It affects no flags.DAA, DASDAA: used to make sure the result of adding two BCD number is a BCD number.DAS: used after subtracting two BCD numbers to make sure the result is correct packed BCD.

  • Instruction Description(contd.)DEC Decrement Destination register or memoryDEC destination: subtracts one from the destination word or byte.AF, OF, PF, SF and ZF flags are updated.DIV Unsigned DivideUsed to divide unsigned word by a byte or to divide an unsigned double word by a word.The word must be present in AX register and divisor must be in register or memory location.After division AL contains the 8-bit result (quotient) and AH will contain the 8-bit remainder.

  • Instruction Description(contd.)ESC EscapeUsed to pass instructions to the coprocessor such as 8087 math processor shares the address and data bus with an 8086.HLT Halt processingIt causes 8086 to stop fetching and executing instructions.Processor will be in the halt state. The only way it can be resume is by generating interrupt at the INTR pin.IDIV Divide by signed byte or wordIDIV source: the instruction is used to divide a signed word by a signed byte, or to divide signed double word by a word.The operand must be in AX the divisor may be in register or memory location.The final quotient is stored in AL and remainder will be stored in AH.

  • Instruction Description(contd.)IMUL Multiply signed numbersIMUL source: multiplies a signed byte from some source times a signed byte in AL or a signed word from some source times a signed word in AX.CF and OF flags are updated.IN copy data from a portIN Accumulator, port: copy data from a port to the AL or AX register.If 8-bit port is read then the data will be read into AL else if 16-bit port is read the data will go into AX.INC IncrementINC Destination: it adds one to the source word or byte specified in the destination.AF, OF, PF, SF and ZF are affected.

  • Instruction Description(contd.)INT Interrupt program executionINT Type: type refers to any number between 0 to 255.When 8086 executes the INT instruction it does following:Decrement the stack pointer by 2 and PUSH the flags onto the stack.Decrement the stack pointer by 2 and PUSH the contents of CS onto the stack.Decrement the stack pointer by 2 and PUSH the offset of the next instruction after INT into the stack.Get a new value for IP from an absolute memory address of 4 times the type specified in the instruction.Get a new value for CS from an absolute memory address of 4 times the type specified in the instruction plus 2.Reset both IF and TF.

  • Instruction Description(contd.)INTO Interrupt on overflowDecrement the stack pointer by 2 and PUSH the flags onto the stack.Decrement the stack pointer by 2 and PUSH the contents of CS onto the stack.Decrement the stack pointer by 2 and PUSH the offset of the next instruction after INTO onto the stack.Reset TF and IF.IRET Interrupt ReturnUse at the end of the interrupt service procedure to return execution to the interrupted program.It reloads the contents of the stack and changes the IP value.

  • Instruction Description(contd.)JA/JNBE Jump if Above/Jump in Not Below or EqualAfter compare or some other instruction the instruction will cause the execution to jump to a label given in the instruction.No flags are affected.JAE/JNB/JNC Jump if Above or Equal/Jump if Not Below/Jump in No CarryIf after a compare or some other instruction the CF is 0 this instruction will cause the execution to jump on the specified label.If CF is 1 the instruction will have no effect.JB/JC/JNAE Jump if Below/Jump if Carry/Jump if Not Above or EqualIf after a compare or some other instruction the CF is 1 this instruction will cause the execution to jump on the specified label.If CF is 0 the instruction will have no effect.

  • Instruction Description(contd.)JBE/JNA Jump if Below or Equal/Jump if Not AboveIf after a compare or some other instruction the CF is 1 this instruction will cause the execution to jump on the specified label.If CF and ZF both are 0 the instruction will have no effect.JCXZ Jump if the CX register is 0JE/JZ Jump if Equal/Jump if ZeroJG/JNLE Jump if Greater/Jump if Not Less than or EqualAfter compare the instruction will cause a jump if ZF is 0 and CF is same as the OF.The destination must be in the range of -128 bytes to +127 bytes.JL/JNGE Jump if Less than/Jump if Not Greater than or EqualAfter compare instruction it will cause the jump if SF is not equal to OF.The destination must be in the range of -128 bytes to +127 bytes.

  • Instruction Description(contd.)JLE/JNG Jump if Less than or Equal/Jump if Not GreaterAfter compare instruction it will cause the jump if ZF is set or SF is not equal to OF.The destination must be in the range of -128 bytes to +127 bytes.JMP Unconditional Jump to the Specified LocationIt will always force the 8086 to jump to the specified location.The more similar instructions are JNE Jump if Not equal, JNZ Jump if Not Zero, JNO Jump if No Overflow, JNP Jump if No Parity, JPO Jump if Odd Parity, JNS Jump if Not Signed, JO Jump if Overflow, JP Jump if Parity, JPE Jump if Parity Even, JS Jump if Signed etc.

  • Instruction Description(contd.)LAHF Copy low byte of Flag register to AHLower byte of the 8086 is same as the flag bytes of the 8085.Thus it copies the flag bytes of the 8085 to the AH register.LDS Load register and DS with the word from memoryLDS Register, memory address of first word: it copies the word from two memory locations into the register specified in the instruction.It then copies the word from the next two memory location into DS register.LEA Load Effective AddressLEA register, source: determines offset of the variable or memory location named source and puts it into 16-bit register.

  • Instruction Description(contd.)LES Load register and ES with the word from memoryThis instruction loads new values into the specified register and ES register from four successive memory locations.The word from the first two memory location will be copied to the specified register and the word from the next two locations will be copied in to the ES register.LOCK Assert Bus lock SignalAllows microprocessors to ensure that the other processor cant take control of the system bus while it is in critical instruction which uses the system bus.

  • Instruction Description(contd.)LODS/LODSB/LODSW Load String word or byte into ALCopies the byte from a string location pointed to by SI to AL or a word to AX.LOOP Jump to specified Label if CX! =0 After Auto decrementUsed to repeat a series of instruction a number of times.The number of time the sequence is repeated is stored in CX registerVariants are LOOPE, LOOPZ, LOOPNE and LOOPNZ.MOV Copy a word or byteMOV destination, source: copies a word or byte from the source byte to the destination byte.The variants are MOVS/MOVSB/MOVSW move string, byte or move string word.

  • Instruction Description(contd.)MUL Multiply unsigned bytes or wordsMUL source: multiplies the unsigned byte from source times an unsigned byte in the AL register or word in the AX register.NEG Forms 2s complementNEG Destination: replaces the number in destination with the 2s complement of that numberNOP NO OperationIt simply uses the 3 clock cycles and increments the instruction pointer to point to the next instruction.OR Logically OROR Destination, Source: ORs each bit in source byte or word with the bit in destination byte or word.The result is put in the specified destination.

  • Instruction Description(contd.)OUT Output a Byte or word to a portOUT Port, Accumulator: the Out instruction copies a byte from AL or a word from AX to the specified port.Two types of ports: Fixed and Variable portPOPPOP destination: copies the word from the stack top location to the destination specified.The stack pointer is automatically incremented by 2.PUSHPUSH Source: decrements the stack pointer by 2 and copies the word specified in the source to the location pointed by the stack pointer.PUSHF: push the flag register onto the stack.

  • Instruction Description(contd.)RCL Rotate operand around to the left through CLRotates all the bits in the specified byte or word to some bits in left.It is circular because the MSB of the operand is stored in to the CF and then CF is stored in to the LSB of the operand.Similarly RCR: rotates the operand through right using CF.REP/REPE/REPNE/REPZ/REPNZ Repeat String Instruction until specified condition existsREP is the prefix which will cause the CX register to be decremented and the string to be repeated until CX=0.REPE is repeat is equal, REPZ is repeat if zero causes the string to be repeated as long as the words are equal and ZF=1 respectively.RET Return Execution from the procedure callReturn execution from the procedure to the next instruction after the CALL instruction.It do this by restoring the stack contents to the registers and setting IP to point to the next instruction after the CALL instruction.

  • Instruction Description(contd.)ROL rotate Left, ROR Rotate RightROL Destination, count: rotate the bits specified in destination to count no of bit positions.Similarly ROR do the same thin but it rotates towards right.SAHF- Copy AH register to low byte of Flag registerThe lower byte of the 8086 flag register exactly corresponds to the 8085 flag register.This instruction replaces this 8085 flag register with the byte from AH register.SAL/SHL Shift operand bit in left, put zero in LSBs, SAR shift rightSAL/SHL Destination, count: shifts each bits in the specified destination to some number of bits specified by the count value towards left.SAR destination, count: shifts in right.

  • Instruction Description(contd.)SBB Subtract with Borrow, SUB - subtractSUB Destination, source: subtracts the number in source from the number in destination and the final result is stored in destination. It ignores borrow.SBB: it does the same thing but do not ignore borrow.SCAS/SCASB/SCASW Scans a String or Byte or WordCompares a byte in AL or a word in AH with a byte or word pointed to by DI in ES.Therefore the string to be compared must be in extra segment and the DI must contain the offset of the byte or word.STC/STD/STI set carry flag, set direction flag, set interrupt flag to 1.STOS/STOSB/STOSW Stores byte or word in stringCopies a byte from AL or a word from AX to the memory location in extra segment pointed by DI.After copy DI is automatically incremented or decremented to point to the next string element in memory.

  • Instruction Description(contd.)TEST AND operands to UpdateANDs the contents of the source byte with the contents of the destination byte. Flags are updated but neither operand is changed.WAIT Wait for test signal or interrupt signal8086 enters in idle condition and does no processing. It will stay in the idle position until 8086 TEST input pin is made low or interrupt signal is received on INTR or NMI pins.XCHGXCHG destination, source: changes the contents of destination with contents of source and vice versa.Destination and Source both must be either byte or word. It can be register or memory location.

  • Instruction DescriptionXLAT/XLATB Translate a byte in ALUsed to translate a byte from one code to another code.Replaces the byte in AL register with the byte pointed to by BX in a lookup table in the memory. The lookup table must be in the memory before execution of XLAT.XOR eXclusive ORXOR Destination, Source: instruction exclusive ORs each bit in the source byte or word with the bit in the destination byte or word.The result will follow the truth table of XOR. The answer will be stored in the destination.

  • Assembler Directives(contd.)AssumeUsed to tell the assembler the name of the logical segment it should use for a specified segment.You must tell the assembler that what to assume for any segment you use in the program.Example, ASSUME: CODE tells the assembler that the instructions for the program are in segment named CODE.DB Defined ByteUsed to declare a byte type variable or to set aside one or more locations of type byte in memory.Example, PRICES DB 49H, 98H, 29H: Declare array of 3 bytes named PRICES and initialize 3 bytes as shown.

  • Assembler Directives(contd.)DD Define Double WordUsed to declare a variable of type doubleword or to reserve a memory location which can be accessed as doubleword.DQ Define QuadwordUsed to tell the assembler to declare the variable as 4 words of storage in memory.DT Define Ten bytesUsed to tell the assembler to declare the variable which is 10 bytes in length or reserve 10 bytes of storage in memory.DW Define WordUsed to tell the assembler to define a variable type as word or reserve word in memory.

  • Assembler Directives(contd.)END End the programTo tell the assembler to stop fetching the instruction and end the program execution.ENDP it is used to end the procedure.ENDS used to end the segment.EQU EquateUsed to give name to some value or symbol.EVEN Align on Even memory addressTells the assembler to increment the location counter to the next even address if it is not already at an even address.

  • Assembler Directives(contd.)EXTRNUsed to tell the assembler that the name or labels following the directive are in some other assembly module.GLOBAL Declares symbols as PUBLIC or EXTRNUsed to make the symbol available to other modules.It can be used in place of EXTRN or PUBLIC keyword.GROUP Group related segmentUsed to tell the assembler to group the logical segments named after the directive into one logical segment.This allows the content of all the segments to be accessed from the same group.

  • Assembler Directives(contd.)INCLUDE include source code from fileUsed to tell the assembler to insert a block of source code from the named file into the current source module. This shortens the source code.LABELUsed to give the name to the current value in the location counter.The LABEL directive must be followed by a term which specifies the type you want associated with that name.LENGTHUsed to determine the number of items in some data such as string or array.

  • Assembler Directives(contd.)NAMEUsed to give a specific name to a module when the programs consisting of several modules.OFFSETIt is an operator which tells the assembler to determine the offset or displacement of named data item or procedure from the start of the segment which contains it.ORG OriginateTells the assembler to set the location counter value.Example, ORG 7000H sets the location counter value to point to 7000H location in memory.$ is often used to symbolically represent the value of the location counter. It is used with ORG to tell the assembler to change the location according to the current value in the location counter. E.g. ORG $+100.

  • Assembler Directives(contd.)PROC ProcedureUsed to identify the start of the procedure.PTR PointerUsed to assign a specific type to a variable or a label.It is necessary to do this in any instruction where the type of the operand is not clear.PublicIt is used to tell the assembler that the specified label or variable is accessible by other modules.This is useful in large programs which are generally written in modules.

  • Assembler DirectivesSEGMENTUsed to indicate that the start of a logical segment.Preceding the segment directive is the name you want to give to the segment.SHORTUsed to tell the assembler that only a 1-byte displacement is needed to code a jump instruction.If the jump destination is after the jump instruction in the program, the assembler will automatically reserve 2 bytes for the displacement.TYPETells the assembler to determine the type of a specified variable.The TYPE operator can be used in instruction such as ADD BX, TYPE WORD_ARRAY, where we want to increment BX to point to the next word in an array of words.