8086/8088MP INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI Ex: Write an ALP to find the sum of the following series: Sum= 11 + 22 + 33 + 44 + 55 + 66 Ans. MOV BX , 0000H MOV SI , 0001H XOR DI , DI NEXT: CALL SUBR ADD BX , AX ADC DI , 0000H INC SI CMP SI , 0007H JNZ NEXT HLT ; Subroutine finds the power SUBR: MOV CX ,SI MOV AX , 0001H AGAIN: MUL SI DEC CX JNZ AGAIN RET 49 8086/8088MP INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI Input / Output (IN / OUT) Instructions The IN instruction copies data from a port to the AL or AX register. If an 8bit is read, the data will go to AL. If a 16-bit is read, the data will go to AX. The IN instruction does not change any flag. The general form is : IN AL / AX , (input port) The OUT instruction copies a byte from AL or a word from AX to the specified port. The OUT instruction does not affect any flag. The general form is : OUT (output port) , AL / AX The IN / OUT instructions has two possible formats: Fixed (Direct) Port : the 8-bit address of a port is specified directly in the instruction. With this form 256 possible ports can be addressed. IN AL , 98H ; Input a byte from port 0C8H to AL OUT 34H , AX ; Output a word from AX to 34H port Variable (Indirect) Port : the port address is loaded into the DX register before the IN / OUT instructions is executed. Since DX is a 16-bit register, the port address can be any number between 0000H and FFFFH. Therefore, up to 65,536 ports are addressable in this mode. MOV DX , 8F78H ; Initialize DX with a port address IN AX , DX ; Input a word from the port 0FF78H to AX OUT DX , AL ; Output a byte from AL to the port 0FF78H Note : The variable-port in IN / OUT instructions has advantage that the port address can be computed or dynamically determined in the program. Suppose, for example, that an 8086-based computer needs to input data from 10 terminals (ports), each having its own port address. Instead of having a separate procedure to input data from each port, you can write one generalized input procedure and simply pass the address of the desired port to the procedure in DX. 58 8086/8088MP INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI Ex: Write a piece of code to send 55H to output port device which its address is F300H. MOV AL , 55H MOV DX , F300H OUT DX , AL Ex: Write a piece of code to input the contents of the byte-wide input port at A000H of the I/O address space into BL. MOV DX, 0A000H IN AL, DX MOV BL, AL Ex: Write a piece of code to read data from two byte-wide input ports at addresses AAH and A9H and output the data as a word to the word-wide output port at address B000H. IN AL, 0AAH MOV AH, AL IN AL, 0A9H MOV DX, 0B000H OUT DX, AX Ex: An array of size 1 Kbyte is stored at addresses starting at 72000H, write an ALP to send even parity bytes to port address 378H and odd parity bytes to port 478H. MOV AX , 7000H MOV DS , AX MOV CX , 400H XOR BX , BX AGAIN: MOV AL , [BX + 2000H] OR AL , 00H JP EVEN MOV DX , 478H OUT DX , AL JMP NEXT EVEN: MOV DX , 378H OUT DX , AL NEXT: INC BX DEC CX JNZ AGAIN HLT 51 8086/8088MP INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI Miscellaneous Instructions HLT (HALT PROCESSING) The HLT instruction causes the 8086 to stop fetching and executing instructions. The 8086 will enter a halt state. The different ways to get the processor out of the halt state are with an interrupt signal on the INTR pin, an interrupt signal on the NMI pin, or a reset signal on the RESET input. NOP (PERFORM NO OPERATION) This instruction simply takes three clock cycles (3T) and increments the instruction pointer to point to the next instruction. The NOP instruction can be used to increase the delay of a delay loop. A NOP can also be used to hold a place in a program for an instruction that will be added later. NOP does not affect any flag. ESC (ESCAPE) This instruction is used to pass instructions to a coprocessor, such as the 8087 Math coprocessor, which shares the address and data bus with 8086. Instructions for the coprocessor are represented by a 6-bit code embedded in the ESC instruction. As the 8086 fetches instruction bytes, the coprocessor also fetches these bytes from the data bus and puts them in its queue. However, the coprocessor treats all the normal 8086 instructions as NOPs. When 8086 fetches an ESC instruction, the coprocessor decodes the instruction and carries out the action specified by the 6-bit code specified in the instruction. In most cases, the 8086 treats the ESC instruction as a NOP. INT – INT TYPE The term TYPE in the instruction format refers to a number between 0 and 255, which identify the interrupt. When an 8086 executes an INT instruction, it will 1. Decrement the stack pointer by 2 and push the flags on to the stack. 2. Decrement the stack pointer by 2 and push the content of CS onto the stack. 3. Decrement the stack pointer by 2 and push the offset of the next instruction after the INT number instruction on the stack. 52 8086/8088MP INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI 4. Get a new value for IP from an absolute memory address of 4 times the type specified in the instruction. For an INT 8 instruction, for example, the new IP will be read from address 00020H. 5. Get a new for value for CS from an absolute memory address of 4 times the type specified in the instruction plus 2, for an INT 8 instruction, for example, the new value of CS will be read from address 00022H. 6. Reset both IF and TF. Other flags are not affected. WAIT – WAIT FOR SIGNAL OR INTERRUPT SIGNAL When this instruction is executed, the 8086 enters an idle state and is doing no processing. The 8086 will stay in this idle state until the 8086 TEST input pin is made low(TEST=0) or until an interrupt signal is received on the INTR or the NMI interrupt input pins. WAIT does not affect any flag. The WAIT instruction is used to synchronize the 8086 with external hardware such as the 8087 Math coprocessor. 53 8086/8088MP INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI Converting Assembly Language Instructions to Machine Code The general instruction format for machine code is shown below : BYTE 1 Specification OPCODE field (6-bits) : Specifies the operation to be performed such as MOV , ADD , SUB …..etc. Register direction bit (D-bit): D = 1 : the register operand specified by REG in byte 2 is a destination operand. D = 0 : the register operand specified by REG in byte 2 is a source operand Data size bit (W-bit): Specifies whether the operation will be performed on 8-bit or 16-bit data. W = 1 : 16-bit data size W = 0 : 8-bit data size BYTE 2 Specification: byte 2 has three fields: Mode (MOD) field (2-bits) : Indicates whether the operand is in register or memory. MOD 00 01 10 11 Explanation Memory Mode no displacement Memory Mode 8-bit displacement Memory Mode 16-bit displacement Register Mode (no displacement) Register (REG) field (3-bit) : Identifies the register for the first operand Register/Memory (R/M) field (3-bit): Together with MOD field to specify the second operand. 54 8086/8088MP INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI REG 000 001 010 011 100 101 110 111 W=0 AL CL DL BL AH CH DH BH W=1 AX CX DX BX SP BP SI DI MOD = 11 Effective Address Calculation Reg. W=0 W=1 R/M MOD=00 MOD=01 MOD=10 000 AL AX 000 (BX)+(SI) (BX)+(SI)+D8 (BX)+(SI)+D16 001 CL CX 001 (BX)+(DI) (BX)+(DI)+D8 (BX)+(DI)+D16 010 DL DX 010 (BP)+(SI) (BP)+(SI)+D8 (BP)+(SI)+D16 011 BL BX 011 (BP)+(DI) (BP)+(DI)+D8 (BP)+(DI)+D16 100 AH SP 100 (SI) (SI)+D8 (SI)+D16 101 CH BP 101 (DI) (DI)+D8 (DI)+D16 110 DH SI 110 Direct Address (BP)+D8 (BP)+D16 111 BH DI 111 (BX) (BX)+D8 (BX)+D16 Ex : Encode the following instruction in machine code. Assume that the OPCODE for MOV instruction is 1000102. MOV BL , AL Ans. OPCODE = 100010 (for MOV), D = 0 (source), W = 0 (8-bit) this leads to : BYTE 1 = 100010002 = 8816 In byte 2 the source operand, specified by REG is AL , then: REG = 000, MOD = 11, R/M = 011 Therefore: BYTE 2 = 110000112 = C316 The machine code for the instruction is: MOV BL , AL = 88C3H Ex : Encode the following instruction in machine code. Assume that the OPCODE for ADD instruction is 0000002. ADD AX , [SI] Ans. OPCODE = 000000 (for ADD), D = 1 (destination), W = 1 (16-bit) this leads to BYTE 1 = 000000112 = 0316 55 8086/8088MP INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI In byte 2 the destination operand, specified by REG is AX , then: REG = 000, MOD = 00, R/M = 100 Therefore: BYTE 2 = 000001002 = 0416 The machine code for the instruction is: ADD AX, [SI] = 030416 Ex: Encode the following instruction in machine code. Assume that the OPCODE for XOR instruction is 0011002. XOR CL , [1234H] Ans. OPCODE = 001100 (for XOR), D = 1 (destination), W = 0 (8-bit) this leads to: BYTE 1 = 001100102 = 3216 In byte 2 the destination operand, specified by REG is CL , then: REG = 001 , MOD = 00, R/M = 110 Therefore: BYTE 2 = 000011102 = 0E16 BYTE 3 = 3416 and BYTE 4 = 1216 The machine code for the instruction is: XOR CL , [1234H] = 320E341216 Ex: Encode the following instruction in machine code. Assume that the OPCODE for ADD instruction is 0000002. ADD [BX+DI+1234H] , AX Ans. OPCODE = 000000 (for ADD) , D = 0 (source), W = 1 (16-bit) This leads to : BYTE 1 = 000000012 = 0116 In byte 2 the destination operand, specified by REG is AX, then : REG = 000 , MOD = 10 , R/M = 001 Therefore : BYTE 2 = 100000012 = 8116 BYTE 3 = 3416 and BYTE 4 = 1216 The machine code for the instruction is: ADD [BX+DI+1234H] , AX = 0181341216 Ex: Encode the following instruction in machine code MOV [BP+DI+1234H] , 0ABCDH Ans. This example does not follow the general format. The OPCODE of MOV (immediate to memory) is 1100011W, and W = 1 for word-size data, then: 56
© Copyright 2026 Paperzz