Computer & Interfacing Chapter 3 - new PDF
Document Details
Uploaded by Deleted User
Infolink University College
Getahun N.
Tags
Summary
This document is a chapter on microprocessor and assembly language programming, focusing on Intel 8086 processor instruction sets and addressing modes. It provides an outline of the chapter, introductions and examples.
Full Transcript
OUTLINE OF THE CHAPTER INFOLINK UNIVERSITY COLLEGE DEPARTMENT OF COMPUTER SCIENCE MICROPROCESSOR AND ASSEMBLY LANGUAGE PROGRAMMING CHAPTER THREE Intel 8086 PROCESSOR PROGRAMING & INSTRUCTION SETS BY GETAHUN N. INTR...
OUTLINE OF THE CHAPTER INFOLINK UNIVERSITY COLLEGE DEPARTMENT OF COMPUTER SCIENCE MICROPROCESSOR AND ASSEMBLY LANGUAGE PROGRAMMING CHAPTER THREE Intel 8086 PROCESSOR PROGRAMING & INSTRUCTION SETS BY GETAHUN N. INTRODUCTION The 8086 has about 117 different instructions with about 300 opcodes. The 8086 instruction sets can contain no operand, single operand, and two operand instructions. The 8086 instructions do not permit memory to memory operations except for string instructions which involve array operations. The processor can access memory in different ways that are collectively called addressing mode. The addressing modes describe the types of operands and the way they are accessed for executing an instruction. The number of addressing modes is determined when the microprocessor is designed and cannot be changed. 8086 ADDRESSING MODES The 8086 provides a total of seven distinct addressing modes: 1. Register addressing modes 2. Immediate addressing modes 3. Direct addressing modes 4. Register indirect addressing modes 5. Based relative addressing modes 6. Indexed relative addressing modes 7. Based indexed relative addressing modes MOV instructions are used to explain addressing modes. 8086 ADDRESSING MODES (CONT..) A) REGISTER ADDRESSING MODE: MOV REG1, REG2; The register addressing mode involves the use of registers to hold the data to be manipulated. Examples: MOV BX, DX ; copy the contents of DX into BX MOV ES, AX ; copy the contents of AX into ES ADD AL, BH ; add the contents of BH to Contents of AL. The size of reg1 and reg2 must be the same. MOV CL, AX is illegal for instance. 8086 ADDRESSING MODES (CONT..) B) IMMEDIATE ADDRESSING MODE:- MOV REG, CONSTANT In the immediate addressing mode, the source operand is a constant. It can be used to load info into any of the registers except the segment registers and flag register. Examples: MOV AX, 2550H ; move 2550H into AX MOV CX, 625 ; load the decimal value 625 into CX MOV BL, 40H ; load 40H into BL MOV DS, 0123H; is illegal! Instead we can use: MOV AX, 0123H MOV DS, AX 8086 ADDRESSING MODES (CONT..) C) DIRECT ADDRESSING MODE: MOV reg, [constant] or MOV [constant], reg Here constant is not operand but it is an offset or EA in memory of operand. In the direct addressing mode the data is in some memory location(s) and the address of the data in memory comes immediately after the instruction. This address is the offset address and one can calculate the physical address by shifting left the DS register and adding it to the offset as follows: Example: MOV DL, [2400H] ; move contents of DS: 2400H into DL 8086 ADDRESSING MODES (CONT..) D) REGISTER INDIRECT ADDRESSING MODE: MOV REG1, [REG2] or MOV [REG2], REG1; Here the address of the memory location where the operand resides is held by a register, REG2. REG1 can be any general purpose register and REG2 can be either of SI, DI, or BX and they must be combined with DS in order to generate the 20-bit physical address. Example: MOV AL, [BX] ; move contents of DS:BX into AL MOV CL, [SI] ; move contents of DS:SI into CL MOV [DI], AH ; move contents of AH into DS:DI MOV DX, [BX] ; move contents of DS:BX into DL and ; contents of DS:BX+1 into DH 8086 ADDRESSING MODES (CONT..) Exercise: Assume that DS = 1120H, SI = 2498H, and AX = 17FEH. Show the contents of memory locations and its contents after the execution of MOV [SI], AX Solution: The contents of AX are moved into memory locations with logical address DS: SI and DS: SI + 1; Therefore, the physical address starts at: PA = DS (shifted left) + SI = 13698H. According to the little endian convention, low address 13698H contains FEH, the low byte, and high address 13699H will contain 17H, the high byte. 8086 ADDRESSING MODES (CONT..) E) BASED RELATIVE ADDRESSING MODE: MOV REG1, [REG2] + CONST or MOV [REG2] + CONST, REG1; CONST is an 8-bit displacement value. REG1 can be any general purpose register and REG2 can only be either of BP or BX In the based relative addressing mode, base registers BX and BP, as well as a displacement value, are used to calculate what is called the effective address. The default segments used for the calculation of the physical address (PA) are DS for BX and SS for BP. PA = DS*10H + BX + const ; EA = BX + const PA = SS*10H + BP + const ; EA = BP + const 8086 ADDRESSING MODES (CONT..) F) INDEXED RELATIVE ADDRESSING MODE: MOV REG1, [REG2] + CONST OR MOV [REG2] + CONST, REG1; The indexed relative addressing mode works the same as the based relative addressing mode, except that registers DI and SI hold the offset address. Const is an 8-bit displacement value. REG1 can be any general purpose register and REG2 can only be either of DI or SI PA = DS*10H + DI + const ; EA=DI + const or PA = DS*10H + SI + const ; EA= SI + const Examples: MOV DX, [SI]+5 ; PA = DS (shifted left) + SI + 5 MOV CL, [DI]+20 ; PA = DS (shifted left) + DI + 20 SUMMARY OF ADDRESSING MODES The following table, summarizes the possible offset registers for various segments. INTRODUCTION TO ASSEMBLY LANGUAGE PROGRAMMING Program execution in any microprocessor system consists of fetching binary information from memory and decoding that information to determine the instruction represented. The source file is converted into an object file, containing the actual binary information the machine will understand, by a special program called an assembler. An Assembly language program is a series of statements, or lines which is, either Assembly language instructions, or Pseudo- instruction called directives. INTRODUCTION TO ASSEMBLY LANGUAGE PROGRAMMING Directives (pseudo-instructions) give directions to the assembler about how it should translate the Assembly language instructions into machine code. Assembly language instructions consist of four fields: [label:] mnemonic [operands] [;comment] Brackets indicate that the field is optional, do not type in the brackets. The comment field begins with a ";" and may be at the end of a line. Comments are optional, but highly recommended to make it easier to read and understand the program. The assembler ignores comments. DIRECTIVES AND A SAMPLE PROGRAM The label field allows the program to refer to a line of code by name. The label field can be any character and cannot exceed 31 characters. A label must end with a colon when it refers to an opcode and, end without colon when it refer to directives. The mnemonic (instruction) and operand fields together accomplish the tasks for which the program was written. The mnemonic opcodes are ADD and MOV, and "AL, BL" and "AX, 6764" are the operands. Instead of a mnemonic and operand, these fields could contain assembler pseudo-instructions, or directives. Directives do not generate machine code and are used only by the assembler as opposed to instructions. DIRECTIVES AND A SAMPLE PROGRAM Examples of directives are DB, PROC, END, and ENDP. MODEL DEFINITION After the first two comments is the MODEL directive. This directive selects the size of the memory model. SEGMENT DEFINITION Every line of an Assembly language program must correspond to one of an x86 CPU segment register. CS (code segment); DS (data segment). SS (stack segment); ES (extra segment). The simplified segment definition format uses three simple directives: ".CODE" ".DATA" ".STACK“, which correspond to the CS, DS, and SS registers. STACK SEGMENT This directive reserves 64 bytes of memory for the stack: DATA SEGMENT The data segment defines three data items: DATA1, DATA2, and SUM. DATA SEGMENT The DB directive is used by the assembler to allocate memory in byte-sized chunks. Each is defined as DB (define byte). Memory can be allocated in different sizes. Data items defined in the data segment will be accessed in the code segment by their labels. DATA1 and DATA2 are given initial values in the data section. SUM is not given an initial value, but storage is set aside for it. CODE SEGMENT DEFINITION The first line of the segment after the.CODE directive is the PROC directive. CODE SEGMENT DEFINITION A procedure is a group of instructions designed to accomplish a specific function. A code segment is organized into several small procedures to make the program more structured. Every procedure must have a name defined by the PROC directive, followed by the assembly language instructions, and closed by the ENDP directive. The PROC and ENDP statements must have the same label. The PROC directive may have the option FAR or NEAR. The OS requires the entry point to the user program to be a FAR procedure. CODE SEGMENT DEFINITION Before the OS passes control to the program so it may execute, it assigns segment registers values. When the program begins executing, only CS and SS have the proper values. DS (and ES) values are initialized by the program. CODE SEGMENT DEFINITION The last instructions, "MOV AH, 4CH" & "INT 21H“ return control to the operating system. CODE SEGMENT DEFINITION The last two lines end the procedure & program, and The label for ENDP(MAIN) matches the label for PROC. CODE SEGMENT DEFINITION It is handy to keep a sample shell & fill it in with the instructions and data for your program. ASSEMBLE, LINK, AND RUN A PROGRAM MASM & LINK are the assembler & linker programs. Many editors or word processors can be used to create and/or edit the program, and produce an ASCII file. The steps to create an executable Assembly language program are as follows: Introduction to Assembly Language Programming Introduction to Assembly Language Programming The source file must end in ".asm“. The ".asm" file is assembled by an assembler, like MASM. The assembler will produce an object file and a list file, along with other files useful to the programmer. The ".lst" file, which is optional, is very useful to the programmer because it lists all the opcodes and offset addresses as well as errors that MASM detected. The extension for the object file must be ".obj". Before feeding the ".obj" file into LINK, all syntax errors must be corrected. This object file is input to the LINK program, to produce the executable program that ends in ".exe". The ".exe" file can be run (executed) by the microprocessor. DATA TYPES AND DATA DEFINITION The 8088/86 processor supports many data types. Data types can be 8- or 16-bit, positive or negative. A number less than 8 bits wide must be coded as an 8-bit register with the higher digits as zero. A number is less than 16 bits wide must use all 16 bits. ORG is used to indicate the beginning of the offset address. The number after ORG can be either in hex or in decimal. If the number is not followed by H, it is decimal and the assembler will convert it to hex. DATA TYPES AND DATA DEFINITION DB Define Byte: One of the most widely used data directives, it allows allocation of memory in byte-sized chunks. This is the smallest allocation unit permitted. DB can define numbers in decimal, binary, hex, & ASCII. D after the decimal number is optional. B (binary) and H (hexadecimal) is required. To indicate ASCII, place the string in single quotation marks. DB is the only directive that can be used to define ASCII strings larger than two characters. It should be used for all ASCII data definitions. DATA TYPES AND DATA DEFINITION Some examples: DATA TYPES AND DATA DEFINITION DUP duplicate: DUP will duplicate a given number of characters. Two methods of filling six memory locations with FFH. DATA TYPES AND DATA DEFINITION EQU equate (Equal): EQU associates a constant value with a data label. When the label appears in the program, its constant value will be substituted for the label. When EQU is used for the counter constant: COUNT EQU 25, and when executing the instructions "MOV CX, COUNT", the register CX will be loaded with the value 25, it will be in the immediate addressing mode. DATA TYPES AND DATA DEFINITION EQU can also be used in the data segment: Assume a constant (a fixed value) used in many different places in the data and code segments. By use of EQU, one can change it once and the assembler will change all of them. DEBUG program instruction set DEBUG is a program included in the MS-DOS and PC-DOS operating systems that allows the programmer to monitor a program’s execution closely for debugging purposes. Specifically, it can be used: To examine and alter the contents of memory, To enter and run programs, and To stop programs at certain points in order to check or even change data. You will learn: How to enter and exit DEBUG, How to enter, run, and debug programs, How to examine and alter the contents of registers and memory. DEBUG program instruction set Debug instructions List of commands A: Assemble [address] you can type in code this way D: [range] ; DUMP E: address [list] ; G: Go [=address] addresses runs the program R: Show & change registers Appears to show the same thing as T, but doesn't cause any code to be executed. T: start address Trace either from the starting address or current location. U: start address UnAssemble DEBUG program instruction set 1. Entering and exiting debug: To enter the DEBUG program, simply type its name : A>DEBUG filename To exit the DEBUG program, the quit command, Q, may be typed: -Q 2. R The register command: Allows you to examine and/or alter the contents of the internal registers of the CPU. -R will display all registers -R only the register named will be display. DEBUG program instruction set 3. A, the assemble command: The assemble command is used to enter Assembly language instructions into memory. Syntax: A The starting address may be given as an offset number, in which case it is assumed to be an offset into the code segment, or the segment register can be specified explicitly. In other words, “-A 0100" and “-A CS:0100" will achieve the same results. be aware that one important difference between DEBUG programming and Assembly language programming is that DEBUG assumes that all numbers are in hex, whereas most assemblers assume that numbers are in decimal unless they are followed by "H“. DEBUG program instruction set 4. U, the unassembled command: looking at machine code. The unassembled command displays the machine code in memory along with their equivalent Assembly language instructions. The command can be given in either format shown below. -U -U < L number of bytes> The assemble instruction takes Assembly language instructions from the keyboard and converts them to machine code, which it stores in memory, The unassembled instruction does the opposite. Unassembled takes machine code stored in memory and converts it back to Assembly language instructions to be displayed on the monitor. DEBUG program instruction set 4. G, the go command: The go command instructs DEBUG to execute the instructions found between the two given addresses. Its format is: G < = starting address> DEBUG program instruction set 5. T, the trace command: a powerful debugging tool The trace command allows you to trace through the execution of your programs one or more instructions at a time to verify the effect of the programs on registers and/or data. Syntax: T The difference between this command and the go command is that trace will display the register contents after each instruction, whereas the go command does not display them until after termination of the program. Another difference is that the last field of the go command is the stop address, whereas the last field of the trace command is the number of instructions to execute. DEBUG INSTRUCTION SET 6. F, the fill command: filling memory with data The fill command is used to fill an area of memory with a data item. The syntax of the F command is as follows: F F < L number of bytes > This command is useful for filling a block of memory with data, for example to initialize an area of memory with zeros. DEBUG INSTRUCTION SET 7. D, the dump command: examining the contents of memory The dump command is used to examine the contents of memory. The syntax of the D command is as follows: D D < L number of bytes> The D command can be entered with a starting and ending address, in which case it will display all the bytes between those locations. It can also be entered with a starting address and a number of bytes (in hex), in which case it will display from the starting address for that number of bytes. If the address is an offset, DS is assumed. DEBUG INSTRUCTION SET 8. E, the enter command: entering data into memory. The fill command was used to fill a block with the same data item. The enter command can be used to enter a list of data into a certain portion of memory. The syntax of the E command is as follows: E E The E command has another powerful feature: the ability to examine and alter memory byte by byte. If the E command is entered with a specific address and no data list, DEBUG assumes that you wish to examine that byte of memory and possibly alter it. EXAMINING THE STACK IN DEBUG PUSHING ONTO THE STACK Notice that the stack grows "upward" from higher memory locations toward lower memory locations. After each push, the stack pointer is decremented by 2. POPPING THE STACK As the stack is popped, it shrinks "downward" toward the higher memory addresses. After each pop, the stack pointer is incremented by 2. Quiz 2 [5%] 1. What is meant by DUP duplication in assembly language programming and mention the advantage and disadvantage of it. 2. What is the difference between the trace command and Go command 47 INSTRUCTION SET OF 8086 The instruction set of the 8086 microprocessor is divided into seven different groups: A. Data transfer instruction B. Strings instruction C. Loops and jumps instruction D. Arithmetic instruction E. Bit manipulation instruction F. Subroutine and interrupt instruction G. Processor control instruction The instructional groups are organized in such a way that the more commonly used instructions are presented first, followed by less frequently used instructions. DATA TRANSFER INSTRUCTIONS: This group of instructions makes it possible to move (copy) data around inside the processor and between the processor and its memory. A. MOV DESTINATION, SOURCE: Transfer can be from register to register, register to memory or from memory to register but not from memory to memory. The source and destination must be of same type i.e. either both must be byte or word. MOV instruction does not affect any flags. DATA TRANSFER INSTRUCTIONS: EXAMPLE: MOV AL, 30H MOV AX, 30H In the first instruction, the 30H is coded as a byte value because it is being MOVed into AL. In the second instruction, the 30H is coded as a word value because it is being MOVed into AX. DATA TRANSFER INSTRUCTIONS: Some times, For example, in MOV [SI], 0 the processor does not know if the operand should be coded as a byte value, or as word value. For cases like this, we use BYTE PTR and WORD PTR directives to indicate the size of data. If you wish to MOV a byte value into memory, use: MOV BYTE PTR [SI], 0 MOV WORD PTR [SI], 0 The byte ptr, and word ptr assembler directives stand for "byte pointer," and "word pointer." DATA TRANSFER INSTRUCTIONS(cont..) PUSH and POP instructions The stack is a collection of memory locations pointed to by the stack pointer register and the stack segment register(SS:SP). PUSH and POP instructions are used to load to or receive data from the stack memory. Storing a CPU register in the stack is called a push. Loading the contents of the stack into the CPU register is called a pop. The SP points at the current memory location used as the top of the stack. No flags are affected by this instruction(PUSH and POP). DATA TRANSFER INSTRUCTIONS(cont..) PUSH SOURCE When we wish to write data into the stack area, we use the PUSH instruction. The source of the word can be a general-purpose register, a segment register, or memory. As data is pushed onto the stack it is decremented by 2. As data is popped off the stack into the CPU, it is incremented by 2. When an instruction pushes or pops a general purpose register, it must be the entire 16-bit register. One must code "PUSH AX". There are no instructions such as "PUSH AL" or "PUSH AH". DATA TRANSFER INSTRUCTIONS(cont..) As each PUSH is executed, the register contents are saved on the stack and SP is decremented by 2. EXAMPLES: PUSH BX ; Decrement SP by 2, copy BX to stack PUSH DS ; Decrement SP by 2, copy DS to stack PUSH table [BX] ; Decrement SP by 2, copy word from ; memory in DS at EA = table + [BX] ; to stack PUSH AL ; Illegal, must push a word DATA TRANSFER INSTRUCTIONS(cont..) EXAMPLES:- The stack segment register has been loaded with 4000H and the stack pointer register with FFFFH. If register CX contains 1234H and AX contains 4455H, what is the result of : PUSH AX PUSH CX Solution: The stack pointer points to a location referred to as the top of the stack. Whenever we push an item onto the stack, the SP is decremented by 2. This is necessary because all pushes involve 2 bytes of data Figure 3-3 shows the new contents of memory after PUSH AX and PUSH CX have executed. Instruction Set of 8086 DATA TRANSFER INSTRUCTIONS(cont..) The data contained in memory locations 4FFFEH and 4FFFDH is replaced by the contents of register AX and data contained in memory locations 4FFFCH and 4FFFBH is replaced by the contents of register CX. Notice that the new stack pointer value is 4FFFBH. Remember that the stack builds toward 0. Also notice that the contents of registers CX and AX remain unchanged. When the SP register is pushed, the value written to the stack is the value of SP before the push. DATA TRANSFER INSTRUCTIONS(cont..) PUSHA ; Save all 16-bit registers onto the stack in the following order: AX, CX, DX, BX, SP, BP, SI, DI. The value of the SP is that before the PUSHA instruction. PUSHF; copies the contents of the flag register to the stack. DATA TRANSFER INSTRUCTIONS(cont..) POP DESTINATION: The POP instruction is used to perform the reverse of a PUSH. Copies a word from the stack location pointed to by the stack pointer to a destination specified in the Instruction. The destination can be : A general-purpose register, A segment register except CS and IP A memory location. The data in the stack is not changed. DATA TRANSFER INSTRUCTIONS(cont..) POPA Destination (Pop All Registers). All general purpose registers are popped from the stack in the order indicated in Table below. Note that the contents of the SP are not loaded with the data popped off the stack. This is necessary to prevent the stack from changing locations halfway through the execution. DATA TRANSFER INSTRUCTIONS(cont..) IN ACCUMULATOR, PORT Input byte or word from port to accumulator register(AL or AX). Data read from an input port always ends up in the accumulator. IN: COPY DATA FROM A PORT TO ACCUMULATOR. The input port is actually a hardware device connected to the processor's data bus. When executing the IN instruction, the processor will output the address of the input port on the address bus. The selected input port will then place its data onto the data bus to be read by the processor. The processor allows two different forms of the IN instruction: Direct and Indirect. DATA TRANSFER INSTRUCTIONS(cont..) Direct: If the port number is between 00 and FFH, we would use: IN AL,80H or IN AX,80H. Using AL in the operand field causes 8 bits of data to be read. Two bytes can be input by using AX in the operand field. Example: IN AL, 0F8H ; Copy a byte from port 0F8H to AL IN AX, 95H ; Copy a word from port 95H to AX. Example: What is the result of IN AL, 80H if the data at input port 80H is 22H? Solution: The byte value 22H is copied into register AL(AL = 22H) DATA TRANSFER INSTRUCTIONS(cont..) Indirect: If a full 16-bit port address must be specified, the port address is loaded(MOVED) into register DX, and IN AL, DX ; To copy a byte from 8-bits port DX to AL. IN AX, DX ; To copy a Word from 16-bits port DX to Ax. Example: MOV DX, 30F8H ; Load 16-bit address of the port in DX. IN AL, DX ; Copy a byte from 8bit port 30F8H to AL. IN AX, DX ; Copy a word from 16-bit port 30F8H to AX. DATA TRANSFER INSTRUCTIONS(cont..) OUT PORT, ACCUMULATOR Output byte or word from accumulator to port. If the output port is 16-bit, then this port address loaded to DX and , OUT DX, AL or OUT DX, AX Example: MOV DX, 30F8H ; Load 16-bit address of the port in DX. OUT DX, AL ; Copy the contents of AL to port 30F8H OUT DX, AX ; Copy the contents of AX to port 30F8H. When the port address is in range of 00H to FFH, then: OUT 80H, AL or OUT 80H, AX. Examples: OUT 0F8H, AL ; Copy content of AL to 8 bit port 0F8H. OUT 0F8H, AX ; Copy contents of AX to 16-bit port 0F8H. DATA TRANSFER INSTRUCTIONS(cont..) LEA DESTINATION, SOURCE (Load effective address): This instruction is used to load the offset of the source memory operand into one of the processor's registers. The memory operand may be specified by any number of addressing modes. The destination may not be a segment register. Determines the offset of the variable or memory location named as the source and loads this address in the specified 16-bit register. Flags are not affected by LEA instruction. DATA TRANSFER INSTRUCTIONS(cont..) Example: What is the difference between: MOV AX, [40H] and LEA AX, [40H]? Solution: In MOV AX, [40H] ; Places 2 bytes of data from locations 40H ; and 41H into register AX. In LEA AX, [40H] ; Places 40H into register AX. DATA TRANSFER INSTRUCTIONS(cont..) XCHG DESTINATION, SOURCE (Exchange data): Used to swap the contents of two 8-, or 16-bit operands. One operand must be a processor register (excluding the segment registers). The other operand may be a register or a memory location. Example: Registers AL and BL contain 30H and 40H, respectively. What is the result of XCHG AL, BL? Solution: After execution, AL = BL = 40H and BL =AL = 30H. LOOPS AND JUMPS INSTRUCTION When there is a need to change the path of program execution by forcing the processor to fetch its next instruction from a new location, we can use Jump instructions. When there is a need to execute some portion of the program more than one times we can use loop instructions. A jump alters the contents of the processor's instruction pointer. Remember that the CS and IP registers are combined to determine the address of the next instruction fetch. Jump instructions are classified as Unconditional Jump (JMP) Conditional Jump (J cond) UNCONDITIONAL JUMPS JMP Target Unconditional jump to Specified Destination(Target) This instruction will always cause the 8086 to fetch its next instruction from the location specified in the instruction without any precondition. If control is transferred to a memory location within the current code segment, it is NEAR jump. This is sometimes called intra-segment jump (within segment). If control is transferred outside the current code segment, it is a FAR or intersegment jump(between segments). Since the CS:IP registers always point to the address of the next instruction to be executed, they must be updated when a control transfer instruction is executed. UNCONDITIONAL JUMPS INSTRUCTIONS The Unconditional Jump Can Take The Following Forms: A. SHORT JUMP: Which is specified by: "JMP SHORT label". This is a jump in which the address of the target location is within -128 to +127 bytes of memory relative to the address of the current IP. B. FAR JUMP: Which has the format "JMP FAR PTR label". This is a jump out of the current code segment, meaning that not only the IP but also the CS is replaced with new values. C. NEAR JUMP: Which is the default, has the format "JMP label". This is a near jump (within the current code segment) CONDITIONAL JUMP INSTRUCTIONS Conditional jumps are always short jumps in the 8086. These instructions will cause a jump to a label given in the instruction if the desired conditions occurs in the program. If the jump is not taken (jump condition is not fulfilled), execution simply go to the next instruction. In the conditional jump, control is transferred to a new location if a certain condition is met. The flag register is the one that indicates the current condition. For example, with "JNZ label", the processor looks at the zero flag. If ZF = 0, it will jump to label to fetch the instruction. If ZF = 1, it will not jump but will execute the next instruction below the JNZ. 8086 CONDITIONAL JUMP INSTRUCTIONS CONDITIONAL JUMP INSTRUCTIONS When signed numbers are compared, use the JG, JL, JGE, JLE, JE, and JNE instructions. The terms greater than and less than refer to signed numbers. When unsigned numbers are compared, use the JA, JB, JAB, JBE, JE instructions. The terms above and below refer to unsigned numbers. CONDITIONAL JUMP INSTRUCTIONS EXAMPLE: Write an assembly language program that adds two numbers from memory in data segment at offsets of 1100H and 1101H and stores the result at an offset of (1102H if it is positive, 1103H if it is negative and 1104H if it is zero. LOOP INSTRUCTIONS LOOP Short-Label (Loop). This instruction is used to repeat a series of instruction for specified number of times. The number is specified in the CX register. The CX register is automatically decremented by one, each time after execution of LOOP instruction. Until CX = 0, execution will jump to a destination specified by a label in the instructions. Example: write a program to add five words and save the result in SUM memory location, using LOOP instruction. Solution: see the following program. LOOP INSTRUCTIONS. LOOPE/LOOPZ LOOPE/LOOPZ Short-Label (Loop if Equal, Loop if Zero). This instruction is similar to LOOP except for a secondary condition that must be met for the jump to take place. In addition to decrementing CX, LOOPZ also examines the state of the zero flag. If the zero flag is set and CX does not equal 0, LOOPZ will jump to the target. If CX equals 0, or if the zero flag gets cleared within the loop, the loop will terminate. As always, when a conditional instruction does not have the correct flag condition, execution continues with the next instruction. LOOPE is an alternate name for this instruction. LOOPE/LOOPZ LOOPNE/LOOPNZ Short-Label (Loop if not Equal, Loop if not Zero). LOOPNZ is the opposite of LOOPZ. The zero flag must be cleared to allow further looping. LOOPNE has the same function. For LOOPE/LOOPZ and LOOPNE/LOOPNZ instructions there is one more condition for exit from loop, which is given below. STRING INSTRUCTIONS A particularly nice feature of the 8086 is its ability to handle strings. A string is a collection of bytes, or words that can be up to 64KB in length. An example of a string might be a sequence of ASCII character codes that constitute a password, or the ASCII codes for “Good Morning!.“ They are capable of performing operations on a series of operands located in consecutive memory locations. For example, while the CMP instruction can compare only 2 bytes (or words) of data, the CMPS (compare string) instruction is capable of comparing two arrays of data located in memory locations pointed at by the SI and DI registers. The common operations that we can perform on any string are copying, comparing and scanning.