Instructions of Control Break. Types of jumps. Direct short jump



Yüklə 43 Kb.
tarix07.11.2018
ölçüsü43 Kb.
#78709
növüInstructions

Lecture № 10
Jumps.



  1. Classification Instructions of Control Break. Types of jumps. Direct short jump.

  2. Direct near (internal) jump.

  3. Direct far (intersegment) jump.

  4. Indirect near jump. Indirect far jump.


Literature.

  1. Jurov V. Assembler, – SPb.: Piter, 2001. – 624 p.

  2. Pustovarov V. I. Assembler. Programming and analysis of machinery programs correctness, - Kiev: “Irina”, 2000. - 476

  3. Tanenbaum, A.S. Structured Computer Organization, 4th ed. - Upper Saddle River, NJ : Prentice Hall, 2002.


Classification Instructions of Control Break.

According the microprocessor’s principle of action the instructions, which provide an organization of branches in a program, may be divided into three groups:



  1. Instructions of unconditional Control Break:

  • instructions of unconditional jumps;

  • calls of subroutines and returns from them;

  • calls of program interrupts and returns from them.

  1. Instructions of conditional Control Break:

  • instructions of jumps according results of comparison instructions;

  • instructions of jumps according the state of flag;

  • instructions of jumps according constants of register CX.




  1. Instructions of loop control:

  • instruction of loop organization with the counter CX;

  • instruction of loop organization with the counter CX with a possibility of pre-term (досрочный) exit from the loop according additional condition.

The point, in which the control is passed, is marked by labels (label is a symbolic name, which designates a certain memory cell, intended for using it as an operand in instructions of control break ).

The assembly translator assigns to every label 3 attributes:



  • name of segment’s code, where this label is placed;

  • offset – the distance (in bytes) from the beginning of the segment’s code, in which the label has been described;

  • the type of the label (the attribute of the distance; this attribute may be of two kinds ).

A label may be determined with help of:

  • operator : (colon);

  • directive label.

The syntax of the first one (i.e. “:”) is shown below:

Symbolic name

Instruction






The second type of label determination looks like:


Symbolic name

label

Type of label

For example:



.code

………


met1:

lea DI,str_8

……..



met2 label near

mov DS,[BX]

………………..



Types of jumps.

As it’s known, the microprocessor executes instructions consequently in accordance with the order, in which they are placed in the program. But some times it may be necessary to change the order of execution, or pass the control to the other program. All these operations are fulfilled with help of jumps (branchings) instructions. Jumps instructions may be divided into: unconditional branches (the jump in the given point of the program without checking any conditions) and conditional branches (change of the sequence of program’s instruction executing depending upon a result of checking of certain condition). Unconditional branches are divided into: (proper) jumps (without return in the point, in which the sequence of program’s instructions has been interrupted) and calls of subroutines (with a return in the point, in which the sequence of program’s instructions has been interrupted, after the subroutines completing).

Operations of branches and programs calls touch upon the microprocessor’s architecture – segment memory addressing.

Unconditional jumps are realized with help of instruction jmp, which has 5 varieties:


  • the direct short (within the limits – 128 … +127 bytes);

  • the direct near (within the limits of the current code segment);

  • the direct far (in the other segment);

  • the indirect near (within the current instructions segment through the cell with an address of the jump);

  • the indirect far (in the other segment through the cell with an address of the jump).

Direct short jump.

Direct jump is such jump, in the instruction of which it is pointed in a direct form a label, on which it is necessary to jump. For the short jump the label must be placed in the same segment at the distance not more than 127 bytes (after the jump instruction) and not less than -128 bytes (before the jump instruction). Machinery code of this instruction is equal only 2 bytes (one byte for OC “EBh”, and one byte for the offset to the point of jump).

The syntax of unconditional direct jump instruction:



jmp [modifier] address_of_ jump
Example:

……………..


metka_1:

…………….


…………….

…………….; - 128 bytes (approximately 35-40 instructions)

jmp short ptr metka_1 ; OC “EBh”, offset (displacement) dd
or

……………..


jmp short ptr metka_2

…………….


…………….

…………….; 127 bytes (approximately 35-40 instructions)

metka_2:

……………..


If a program is translated by TASM, and in the command line it has been pointed that two passes are to be performed, i.e.

tasm /m2 prg.asm, , ,

then the modifier short may be omitted, but for MASM the using of this modifier is compulsory.


Direct Near(Internal) Jump.

This type of jump distinguishes from the previous one (i.e. direct short) by the size of offset (displacement) to the point of jump, which is equal to a whole word in this type of jump. It gives a possibility to execute a jump within the limits of the segment.

With help of instruction of direct near jump (instruction jmp without any modifier) it is possible to jump on any point of the given code segment.

Example of using this instruction:

…………………

code segment



………………..

jmp kuku ; Machinery code “E9h dddd”, dddd is a

; displacement (offset)

……………..


……………..

……………..


kuku:

……………..


code ends

The label (in the example it is designated kuku) may be placed in anywhere inside the code segment . For calculation an address of the jump point the displacement (dddd) should be considered as unsigned integer, but take into account the so called phenomenon as converting, the essence of which it is possible to characterize by the following relations:



FFFFh + 0001h = 0000h

0000h – 0001h = FFFFh

Here FFFFh is the upper possible limit of displacement (offset) inside the segment.


Direct Far (Intersegment) Jump.
This type of jumps allows to hand over control in any point of any code segment of the program (it is supposed, that the program complex includes several code segments). The OC of direct far jump instruction is “EAh”, the length of the instruction is equal to 5 bytes (it includes the full address of point of jump, i.e. segment address + offset, and for this purpose it is necessary: 1 byte for OC + 4 bytes for the full address). In this case the instruction must include a modifier far ptr. For example:
…………..

code_1 segment

assume CS: code_1

………


jmp far ptr metka; Machinery code “EA dddd ssss”

……….


code_1 ends

code_2 segment

…………

metka:


…………

code_2 ends



………..

Problems.




  1. What do we mean under the “direct short jump”? Where must be located the label for this type of jump?

  2. What do we mean under the “direct near jump”? Where must be located the label for this type of jump ?

  3. What do we mean under the “direct far jump”? Where must be located the label for this type of jump ?

  4. What do we mean under the “indirect near jump”? Where must be located the label for this type of jump? When it is possible to use base-index addressing in organization of near indirect jumps?

  5. What do we mean under the “indirect far jump”? Where must be located the label for this type of jump ?

Yüklə 43 Kb.

Dostları ilə paylaş:




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

    Ana səhifə