Você está na página 1de 13

ELET 3105

Microprocessor Architecture Laboratory

College of Technology University of Houston

UNIVERSITY OF HOUSTON
COLLEGE of TECHNOLOGY ELET 3405 Microprocessor Architecture
Experiment 6:
JUMP AND LOOP INSTRUCTIONS

Submitted by THUAN NGUYEN Group Members Bao Nguyen Marco Burgos Thuan Nguyen

Date Submitted: Date Performed: Lab Section: Course Instructor: Lab TA:

Monday, November 1st, 2010 Monday, October 25th, 2010 15 Xiaojing Yuan Anilkumar Maringanti

ELET 3105

Microprocessor Architecture Laboratory Experiment

College of Technology University of Houston

Introduction The purpose of a jump instruction is to alter the execution path of instructions in the program. The code segment register and instruction pointer keep track of the next instruction to be fetched for execution. So a jump involves altering the contents of the register. In this way an execution continues at an address other than the next sequential instruction. No return linkage is saved when the jump takes place. The LOOP instruction is a combination of a decrement of CX and a conditional jump. In the 8086, LOOP decrements CX and if CX is not equal to zero, it jumps to the address indicated by the label. If CX becomes a 0, the next sequential instruction executes. PURPOSE: In this experiment you will learn how to use unconditional and conditional jump instructions as well as the looping instruction. The instructions used include JMP, various conditional jumps and the LOOP. Procedure I: Unconditional and Conditional Jumps The unconditional jump is performed with JMP displacement, where displacement is one of (a) a short, 8-bit signed displacement, (2) a near, 16-bit signed displacement or (3) a far, new code segment and IP location. Conditional jumps are either short or near only. NOTE: The Debug assembler requires an offset as the argument of the jump instruction and then it converts the offset to a signed displacement. Remember also that the IP always points to the next instruction to be executed. Objective: The procedure will demonstrate several varieties of unconditional and conditional jumps. You will also learn how the conditional jump can be used to perform repeated operations. A. Unconditional short jump. 1. First use Assemble (A) to enter the following instructions into memory. Enter the first group starting at offset 0100h and the second group starting at offset 0140h. Record the offsets of each instruction as they are entered.

ELET 3105

Microprocessor Architecture Laboratory Experiment

College of Technology University of Houston

Offset 0100h 0102h 0104h 0107h 0109h


010Bh

Instruction MOV AL,FF MOV AH,EE ADD AX,00 MOV BH,CC JMP 0140 Instruction MOV CL,FF MOV CH,EE MOV DL,DD MOV DH,CC JMP XXXX

Offset 0140h 0142h 0144h 0146h 0148h

;enter the offset of ADD AX,00

2. Use Unassembled (U) to view the code starting at 0100 to view the actual hex entries of the instructions.

ELET 3105

Microprocessor Architecture Laboratory Experiment

College of Technology University of Houston

3. From the machine language code of the instruction, what is the actual displacement for the JMP 0140 instruction?

35h 4. What is the offset of the instruction following the JMP 0140?

ELET 3105

Microprocessor Architecture Laboratory Experiment

College of Technology University of Houston

010Bh Show that when the displacement recorded above is added to this offset you get 0140. 010Bh+0035h = 0140h 5. Use the U 140 command to view the hex code and offsets again. What is the displacement of the last instruction? BAh What is this displacement as a negative number? - 46h Show that when this displacement is subtracted from the IP the result points to the ADD AX,00 instruction. 014Ah 46 = 0104h = offset of ADD AX, 00 6. Now single step through the instructions and note how execution is transferred back and forth between the two groups as the single step is repeatedly used. When we single step through the instructions, the IP jumps from 0109h to 0140h when the JMP 0140 instruction is executed. The IP jumps to 0104 when the JMP 0104 instruction is executed. B. Unconditional Near Jump The near jump can move 32K from the location of the jump. We can try this using the same code as before but now we will place the second group at offset 30F0h. 1. First use Assemble (A) to enter the following instructions into memory. As noted, enter the first group starting at offset 0100h and the second group starting at offset 30F0h. Record the offsets of each instruction. Offset 0100h 0102h 0104h 0107h 0109h 010Ch Offset 30F0h 30F2h 30F4h 30F8h 30FAh
30FDh

Instruction MOV AL,FF MOV AH,EE ADD AX,0100 MOV BH,CC JMP 30F0

Instruction MOV CL,FF MOV CH,EE SUB CX,0FFF MOV DH,CC JMP XXXX

;use the offset of ADD AX,0100

ELET 3105

Microprocessor Architecture Laboratory Experiment

College of Technology University of Houston

2. Use unassemble to determine the displacement corresponding to the 3040 offset in the jump 2FE4h . Show that this will combine with the IP to provide the 3040 offset. 2FE4 + 010C = 30F0h

3. Single step through the instructions and confirm that execution is transferred to 30F0h when the jump is executed. After the JMP 30F0 instruction is executed the IP = 30F0.

ELET 3105

Microprocessor Architecture Laboratory Experiment

College of Technology University of Houston

4. Use unassembled to examine and record what the displacement is corresponding to the XXXX: D007h Show that this displacement will result in transfer back to the ADD AX,0100 instruction when combined with the IP. D007h = -2FF9h. So 30FDh-2FF9h = 0104h

5. Now single step through the instructions and note how execution is transferred back and forth between the two groups as the single step is repeatedly used. The IP point to 0104 after the JMP 0104 instruction is executed. C. Conditional Jumps Conditional jumps represent a branching decision in a program, represented in flowcharts for example by the diamond symbol. The flowchart below shows that if X is less than Y then X should be subtracted from Y otherwise Y is subtracted from X. Then the result is multiplied times Y. Assume X and Y are signed numbers.
X< Y no yes X=Y-X

1. The following code will implement this flowchart. We define X to be in AX and Y to be in BX. The CMP AX, BX

X=X-Y

Z=X*Y

ELET 3105

Microprocessor Architecture Laboratory Experiment

College of Technology University of Houston

essentially sets flags as if AX BX was computed. The flags are then used in a jump if less than (JL) instruction. Notice the use of an unconditional jump also. 2. Enter this code using Assemble (A) and record the address offset of each instruction. Note that we dont know the offsets for the jumps yet so dummy place holders of 0100 are inserted. From the recorded offsets determine what to use for the first and second dummy offsets, 0100. Use A or E to insert the correct offsets.

Offset 0100 0103h 0106h 0108h 010Ah 010Ch 010Eh 0110h 0112h 0114h 0116h

Instruction MOV AX,35 MOV BX,50 CMP AX,BX JL 010E SUB AX,BX JMP 0116 MOV CX,BX SUB BX,AX MOV AX,BX MOV BX,CX IMUL BX

Comment ;AX is X ;BX is Y ;Evaluate X Y ;If X < Y jump to MOV CX,BX, 0100 is a dummy offset :Otherwise X = X Y ;Then jump to multiply, 0100 is a dummy offset ;Save value of Y ;Form Y X into BX ;Move result into AX ;Restore original Y ;Multiply X * Y

3. Single step through this code and verify that the result is correct for these base-10 inputs: (a) X =40=28h and Y=66=42h (b) X =544=220h and Y=244=F4h Product expected= 1716=6B4h Program result: AX=06B4 Product expected= 73200=11DF0 Program result: AX = 1DF0 DX = 0001 DX:AX = 11DF0

(c) X =-1200=B50 and Y=455=1C7h Product expected= 455 (-1200) = 753025=B7D81h Program result: DX:AX = 000B7D81 Procedure II LOOP Instruction The LOOP displacement instruction automatically executes a group of instructions a specific number of times. The number of times to execute is contained in the CX register. CX is automatically decremented each time the group of instructions is executed. Displacement is a signed number of memory locations to move forward or backward.

ELET 3105

Microprocessor Architecture Laboratory Experiment

College of Technology University of Houston

Lets use this instruction to implement an elementary method of multiplication. When we multiply a number by an integer multiplier it is equivalent to adding the number to itself the integer number of times, i.e., 5*X = X + X + X + X + X. So we can load the number into a register, say AX

and the multiplier into CX and then LOOP a group of instructions that adds X to another register CX times. The following code will implement this process: Offset 0100 0103h 0106h 0109h 010Bh 010Dh 010Fh 0111 Instruction MOV AX,XXXX MOV CX,YYYY MOV DX,0 CMP CX,DX JZ 0111 ADD BX,AX LOOP 0109h MOV AX,BX ;XXXX is the number ;YYYY is the multiplier integer ;DX will hold the sum ;If CX = 0 the answer is zero ; so jump by displacement 0100 (dummy) ;Here is where we accumulate the sum ;Now we loop until CX = 0, 0100 = dummy offset ;We put the answer into AX

1. Enter this code using A 100 and record the offsets of each instruction. Note that we use a dummy for the LOOP because we didnt know the offset yet. Now change the LOOP target to be the offset of the ADD DX,AX. Also change the dummy 0100 of the JZ to be the offset of the last instruction. 2. Using the unassemble command determine what the machine language program is using for the two displacements. Show that these, when combined with the IP do jump to the desired offset.

3. Now enter 5 for CX and 35 for AX. What do you expect for the answer of CX*AX = 5h * 35h =00AFh (I assumed that we are using HEX values)

ELET 3105

Microprocessor Architecture Laboratory Experiment

College of Technology University of Houston

ELET 3105

Microprocessor Architecture Laboratory Experiment

College of Technology University of Houston

4. Single step through your program until you reach and execute the last instruction. What is the content of AX? 00AF Is this the correct answer for the product? Yes, however I made changes to the code because it would have been a never ending loop. If you are comparing CX, to DX, to exit the loop when CX becomes 0000, then we can not be changing the value of DX. Also if we LOOP back to ADD DX, AX, then we will never exit since we are not

ELET 3105

Microprocessor Architecture Laboratory Experiment

College of Technology University of Houston

comparing on each loop sequence and therefore will never CMP CX, DX and be able to exit the program. 5. Show that your program gives the correct answer for the products: (a) 14h*140h = 1900h or 1410 *14010 = 196010 = 7A8h (b) 37010*17710 = 6549010 = FFD2h 6. What is the largest product that this program can form? FFFFh = 6553510 Conclusion The idea for this lab was to understand the uses for unconditional and conditional jump and looping instruction. In the first procedure we learned the differences between the unconditional and conditional jumps and learned how they can be used to perform duplicate operations. The command JMP is a displacement of either a short (8-bit), near (16-bit) or far (new code and IP location). We also saw how conditional jumps are either short or near only. In the second procedure we observed the operation of the loop displacement. Using the command LOOP we learned that the code automatically executes a group of instructions a certain amount of times. The number of times it is performed is determined by the value contained in the register CX. CX is then automatically decremented each time the instruction is executed. Displacement is then a signed number of memory locations that moves forward and backwards; and this is the instruction used in basic multiplication.

ELET 3105

Microprocessor Architecture Laboratory Experiment

College of Technology University of Houston

Você também pode gostar