Microprocessors Chapter 7



Yüklə 0,78 Mb.
tarix07.11.2018
ölçüsü0,78 Mb.
#78721


Microprocessors


Chapter Overview

  • The Jump Group

  • Unconditional Jump (JMP)

  • Conditional Jumps and Conditional Sets

  • Loop

  • Procedures

  • CALL

  • RET



The Jump Group

  • The main program control instruction, jump (JMP), allows the programmer to skip sections of a program and branch to any part of the memory for the next instruction.

  • A conditional jump instruction allows the programmer to make decisions based upon numerical tests.

  • The results of numerical tests are held in the flag bits, which are then tested by conditional jump instructions.



Unconditional Jump (JMP)

  • Three types of unconditional jump instructions are available to the micro­processor: short jump, near jump, and far jump.

  • The short jump is a two-byte instruction that al­lows jumps or branches to memory locations within +127 and -128 bytes from the address following the jump.

  • The three-byte near jump allows a branch or jump within ±32K bytes from the instruction in the current code segment.

  • Finally, the five-byte far jump allows a jump to any memory location within the real memory system. The short and near jumps are often called intrasegment jumps, and the far jumps are often called intersegment jumps.



Short Jump:

  • Short jumps are called relative jumps because they can be moved, along with their related software, to any location in the current code segment without a change.



Near Jump:

  • The near jump is similar to the short jump, except that the distance is farther.

  • A near jump passes control to an instruction in the current code segment located within ±32K bytes from the near jump instruction. The distance is ±2G in the 80386 and above when operated in protected mode.



Far Jump:

  • A far jump instruction obtains a new segment and offset address to accomplish the jump.



Conditional Jumps and Conditional Sets

  • Conditional jumps are always short jumps in the 8087-80286 microprocessors. This limits the range of the jump to within +127 bytes and -128 bytes from the location following the conditional jump.

  • In the 80386/80486 conditional jumps are either short or near jumps.



A procedure that searches a table of 100 bytes for a 0AH

  • SCAN PROC NEAR

  • MOV SI, OFFSET TABLE ;address TABLE

  • MOV CX,100 ;load count

  • MOV AL,OAH ;load search data

  • CLD

  • REPNE SCASB

  • JCXZ NOT_FOUND

  • RET

  • SCAN ENDP



Loop

  • The LOOP instruction is a combination of a decrement CX and a conditional jump.

  • LOOP decrements CX and if CX <> 0, it jumps to the address indicated by the label.

  • If CX becomes a 0, the next sequential instruction executes.



A procedure that adds word in BLOCK1 and BLOCK2

  • ADDS PROC NEAR

  • MOV CX,100 ;load count

  • MOV SI,OFFSET BLOCK1 ;address BLOCK1

  • MOV DI,OFFSET BLOCK2 ;address BLOCK2

  • AGAIN:

  • LODSW ;get BLOCK1 data

  • ADD AX,ES:[DI] ;add BLOCK2 data

  • STOSW ;store in BLOCK2

  • LOOP AGAIN ;repeat 100 times RET

  • ADDS ENDP



Procedures

  • The procedure or subroutine is an important part of any computer system’s architecture.

  • A procedure is a group of instructions that usually performs one task.

  • A procedure is a reusable section of the software that is stored in memory once, but used as often as necessary.

  • This saves memory space and makes it easier to develop software.

  • The only disadvantage of a procedure is that it takes the computer a small amount of time to link to the procedure and return from it.



CALL

  • The CALL instruction transfers the flow of the program to the procedure.

  • The CALL instruction differs from the jump instruction because a CALL saves a return address on the stack.

  • The return address returns control to the instruction that follows the CALL in a program when a RET instruction executes.



RET

  • The return instruction (RET) removes either a 17-bit number (near return) from the stack and places it into IP or a 32-bit number (far return) and places it into IP and CS.

  • The near and far return instructions are both defined in the procedure's PROC directive. This automatically selects the proper return instruction.



Chapter 7 Questions and Answers



Which type of JMP instruction (short, near, or far) assembles for the following: (a) if the distance is 0210H bytes (b) if the distance is 0020H bytes (c) if the distance is 10000H bytes

  • (a) near

  • (b) short

  • (c) far



Explain what the JMP AX instruction accomplishes. Also identify it as a near or a far jump instruction.

  • The JMP AX instruction is a near jump to the offset address loaded in AX.



Contrast the operation of a JMP [DI] with a JMP FAR PTR [DI].

  • The JMP [DI] instruction is a near jump that obtain the jump address from the data segment memory location addressed by DI. The other jump is a far jump.



(Develop a short sequence of instructions that stores a 00H into 150H bytes of memory, beginning at extra segment memory location DATA. You must use the LOOP instruction to help perform this task.

  • MOV DI, OFFEST DATA

  • CLD

  • MOV CX, 150H

  • MOV AL, 0

  • AGAIN:

  • STOSB

  • LOOP AGAIN



Develop a sequence of instructions that searches through a block of 100H bytes of memory. This program must count all the unsigned numbers that are above 42H and all that are below 42H. Byte-sized data segment memory location UP must contain the count of numbers above 42H, and data segment location DOWN must contain the count of numbers below 42H.

  • UP DB 0

  • DOWN DB 0 MOV DI, OFFSET BLOCK ;address data MOV CX, 100 ;load counter MOV AL, 42H ;put 66 IN AL

  • AGAIN: CMP AL, [DI] ;search JA L1 INC DOWN JMP L2

  • L1: INC UP

  • L2: DEC DI LOOP AGAIN



Develop a sequence of instructions that shows how data in one block of memory (BLOCK1) adds to data in a second block (BLOCK2) using LOOP to control how many numbers add. Store the result over top of data in BLOCK2

  • ;procedure that adds word in BLOCK1 and BLOCK2

  • ADDS PROC NEAR

  • MOV CX,100 ;load count

  • MOV SI, OFFSET BLOCK1

  • MOV DI, OFFSET BLOCK2

  • AGAIN: LODSW ;get BLOCK1 data

  • ADD AX,ES:[DI] ;add BLOCK2 data

  • STOSW ;store in BLOCK2

  • LOOP AGAIN ;repeat 100 times

  • RET

  • ADDS ENDP



Write a program to fill 1000H-byte block of memory in the extra segment beginning at address BLOCK with the data byte 20H (ASCII space).

  • MOV CX,1000H ;load count

  • MOV DI, OFFSET BLOCK ;address BLOCK

  • MOV AL, 20H

  • CLD

  • REP STOSB



Yüklə 0,78 Mb.

Dostları ilə paylaş:




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə