Home Random Page


CATEGORIES:

BiologyChemistryConstructionCultureEcologyEconomyElectronicsFinanceGeographyHistoryInformaticsLawMathematicsMechanicsMedicineOtherPedagogyPhilosophyPhysicsPolicyPsychologySociologySportTourism






Types of instructions.

 

Contents

 

3.4.1 Data movement

3.4.2 Logic and arithmetic operations

3.4.3 Jumps, loops and procedures

 

 

3.4.1 Data movement

 

In any program it is necessary to move the data in the memory and in the CPU registers; there are several ways to do this: it can copy data in the memory to some register, from register to register, from a register to a stack, from a stack to a register, to transmit data to external devices as well as vice versa.

 

This movement of data is subject to rules and restrictions. The following are some of them:

 

*It is not possible to move data from a memory locality to another directly; it is necessary to first move the data of the origin locality to a register and then from the register to the destiny locality.

 

*It is not possible to move a constant directly to a segment register; it first must be moved to a register in the CPU.

 

It is possible to move data blocks by means of the movs instructions, which copies a chain of bytes or words; movsb which copies n bytes from a locality to another; and movsw copies n words from a locality to another. The last two instructions take the values from the defined addresses by DS:SI as a group of data to move and ES:DI as the new localization of the data.

 

To move data there are also structures called batteries, where the data is introduced with the push instruction and are extracted with the pop instruction. In a stack the first data to be introduced is the last one we can take, this is, if in our program we use these instructions:

 

PUSH AX

PUSH BX

PUSH CX

 

To return the correct values to each register at the moment of taking them from the stack it is necessary to do it in the following order:

 

 

POP CX

POP BX

POP AX

 

For the communication with external devices the out command is used to send information to a port and the in command to read the information received from a port.

 

The syntax of the out command is:

 

OUT DX,AX

 

Where DX contains the value of the port which will be used for the communication and AX contains the information which will be sent.

 

The syntax of the in command is:

 

IN AX,DX

 

Where AX is the register where the incoming information will be kept and DX contains the address of the port by which the information will arrive.

 

3.4.2 Logic and arithmetic operations

 

The instructions of the logic operations are: and, not, or and xor. These work on the bits of their operators. To verify the result of the operations we turn to the cmp and test instructions. The instructions used for the algebraic operations are: to add, to subtract sub, to multiply mul and to divide div.

 

Almost all the comparison instructions are based on the information contained in the flag register. Normally the flags of this register which can be directly handled by the programmer are the data direction flag DF, used to define the operations about chains.



 

Another one which can also be handled is the IF flag by means of the sti and cli instructions, to activate and deactivate the interruptions.

 

3.4.3 Jumps, loops and procedures

 

The unconditional jumps in a written program in assembler language are given by the jmp instruction; a jump is to moves the flow of the execution of a program by sending the control to the indicated address.

 

A loop, known also as iteration, is the repetition of a process a certain number of times until a condition is fulfilled. These loops are used (broken sentence).

 

 


Date: 2014-12-22; view: 931


<== previous page | next page ==>
Assembler programming | Assembler language Instructions
doclecture.net - lectures - 2014-2024 year. Copyright infringement or personal data (0.006 sec.)