Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
8086 Programming Addition Instruction The table illustrates the addressing modes available to the ADD instruction. These addressing modes include almost all addressing modes. The only types of addition not allowed are memory-to-memory and segment register. The segment registers can only be moved, pushed, or popped. Assembly Language Operation ADD AL,BL ADD CX,DI ADD CL,44H AL CX CL AL + BL CX + Dl CL + 44H ADD BX,245FH BX BX + 245FH ADD [BX],AL ADD CL,[BP] [DS:BX] [DS:BX] + AL CL CL + [SS:BP] ADD BX,[SI + 2] BX ADD CL,TEMP ADD BX, TEMP[DI] CL BX ADD [BX + DI],DL ADD BYTE PTR [DI],3 BX + [DS:(SI + 3:SI + 2)] CL + [DS:TEMP] BX +[DS:(TEMP+DI + 1: TEMP+DI)] [BX + DI] [BX + DI] + DL [DI] [DI] + 3 1 Increment Instruction Increment instruction (INC) adds 1 to a register or a memory location. The INC can add 1 to any register or memory location, except a segment register. With indirect memory increments, the size of the data must be described by using the BYTE PTR or WORD PTR directives. The reason is that the assembler program cannot determine if, for example, the INC [DI] instruction is a byte-, or word -sized increment. The INC BYTE PTR [DI] instruction clearly indicates byte-sized memory data; the INC WORD PTR [DI] instruction indicates a word-sized memory data Assembly Language INC BL INC SP INC BYTE PTR [BX] INC WORD PTR [SI] INC DATA1 Operation BL BL + 1 SP SP + 1 [DS:BX] [DS:BX] + 1 [DS:SI+1:SI] [DS:SI+1:SI] + 1 [DS:DATA1] [DS:DATA1] + 1 Increment instructions affect the flag bits except the carry flag bit. Carry doesn't change because we often use increments in programs that depend upon the contents of the carry flag. Note that increment is used to point to the next memory element in a byte-sized array of data only. If word-sized data are addressed. it is better to use an ADD DI,2 instruction to modify the DI pointer in place of two INC DI instructions. In some cases, the carry flag must be preserved which may mean that two INC instructions might appear in a program to modify a pointer. 2 Addition-with-Carry An addition-with-carry instruction (ADC) adds the bit in the carry flag (C) to the operand data. This instruction mainly appears in software that adds numbers that are wider than 16 bits in the 8086. Assembly Language ADC AL,AH ADC CX,BX ADC DH,[BX] ADC BX,[BP + 2] Operation AL CX DH BX + carry AL + AH + carry CX + BX + carry DH + [DS:BX] + carry BX + [SS:(BP + 3:BP + 2) 3 Subtraction Many forms of subtraction (SUB) appear in the instruction set. The only types of subtraction not allowed are memory-to-memory and segment register subtractions. Like other arithmetic instructions, the subtract instruction affects the flag bits. Assembly Language Operation SUB SUB SUB SUB SUB SUB SUB dest dest,source AX,SP CH,6FH AX,OCCCCH [DI],CH CH,[BP] AH, TEMP dest-source Decrement Instruction (DEC) DEC instructionsubtracts a 1 from a register or the contents of a memory location. The decrement indirect memory data instructions require BYTE PTR, or WORD PTR. DEC dest DEC CX DEC BYTE PTR [DI] DEC WORD PTR[BP] dest dest - 1 Subtract-with-Borrow A subtraction-with-borrow (SBB) instruction functions as a regular subtraction, except that the carry flag (C), which holds the borrow, also subtracts from the difference. The most common use for this instruction is for subtractions that are wider than 16 bits in the 8086. Wide subtractions require that borrows propagate through the subtraction, just as wide additions propagate the carry. Like the SUB instruction, SBB affects the flags. Notice that the immediate subtract from memory instruction in 4 this table requires a BYTE PTR , or WORD PTR directive. Assembly Language Operation SBB dest,source dest SBB CL,2 CL SBB BYTE PTR[DI],3 dest – source - carry CL – 2 - carry SBB [DI],AL SBB DI,[BP + 2] 5 Comparison The comparison instruction (CMP) is a subtraction that changes only the flag bits; the destination operand never changes. A comparison is useful for checking the entire contents of a register or a memory location against another value. A CMP is normally followed by a conditional jump instruction, which tests the condition of the flag bits. The only disallowed forms of compare are memory-to-memory and segment register compares. Assembly Language dest – sourse; update flags CMP dest,source CMP CL,BL CMP AX,SP CMP AX,2000H CMP [DI],CH CMP CL,[BP] EXAMPLE CMP JAE Operation AL,10H SUBER ;compare with 10H ;if 10H or above 6