ยŦยк
Üyelik tarihi: Jan 2007
Mesajlar: 11.262
| Table of Symbols
Each one of the parts on code line in assembler is known as token, for example on the code line:
MOV AX,Var
we have three tokens, the MOV instruction, the AX operator, and the VAR operator. What the assembler does to generate the OBJ code is to read each one of the tokens and look for it on an internal "*****alence" chart known as the reserved words chart, which is where all the mnemonic meanings we use as instructions are found.
Following this process, the assembler reads MOV, looks for it on its chart and identifies it as a processor instruction. Likewise it reads AX and recognizes it as a register of the processor, but when it looks for the Var token on the reserved words chart, it does not find it, so then it looks for it on the symbols chart which is a table where the names of the variables, constants and labels used in the program where their addresses on memory are included and the sort of data it contains, are found.
Sometimes the assembler comes on a token which is not defined on the program, therefore what it does in these cased is to pass a second time by the source program to verify all references to that symbol and place it on the symbols chart.There are symbols which the assembler will not find since they do not belong to that segment and the program does not know in what part of the memory it will find that segment, and at this time the linker comes into action, which will create the structure necessary for the loader so that the segment and the token be defined when the program is loaded and before it is executed.
More assembler programs
Another example
First step
use any editor program to create the source file. Type the following lines:
;example11
.model small
.stack
.code
mov ah,2h ;moves the value 2h to register ah
mov dl,2ah ;moves de value 2ah to register dl
;(Its the asterisk value in ASCII format)
int 21h ;21h interruption
mov ah,4ch ;4ch function, goes to operating system
int 21h ;21h interruption
end ;finishes the program code
Second step
Save the file with the following name: exam2.asm Don't forget to save this in ASCII format.
Third step
Use the TASM program to build the object program.
C:\>tasm exam2.asm
Turbo Assembler Version 2.0 Copyright (c) 1988, 1990 Borland
International
Assembling file: exam2.asm
Error messages: None
Warning messages: None
Passes: 1
Remaining memory: 471k
Fourth step
Use the TLINK program to build the executable program
C:\>tlink exam2.obj
Turbo Link Version 3.0 Copyright (c) 1987, 1990 Borland
International
C:\>
Fifth step
Execute the executable program
C:\>ejem11[enter]
*
C:\>
This assembler program shows the asterisk character on the computer screen
Types of instructions.
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 EShttp://www.supermp3.org/images/smilies/biggrin.gifI 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.
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.
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.
Assembler language instructions
• Transfer instructions
o MOV INSTRUCTION
o MOVS (MOVSB) (MOVSW) Instruction
• Loading instructions
o LODS (LODSB) (LODSW)
o LAHF
o LDS
o LEA
o LES
• Stack instructions
o POP
o POPF
o PUSH
o PUSHF
• Logic instructions
o AND
o NEG
o NOT
o OR
o TEST
o XOR
• Arithmetic instructions
o ADC
o ADD
o DIV
o IDIV
o MUL
o IMUL
o SBB
o SUB
• Jump instructions
• Instructions for cycles ( loops )
o LOOP
o LOOPE
o LOOPNE
• Counting Instructions
o DEC
o INC
• Comparison Instructions
o CMP
o CMPS (CMPSB) (CMPSW)
• Flag Instructions
________________________________________
Transfer instructions
They are used to move the contents of the operators. Each instruction can be used with different modes of addressing.
MOV INSTRUCTION
Purpose: Data transfer between memory cells, registers and the accumulator.
Syntax:
MOV Destiny, Source
Where Destiny is the place where the data will be moved and Source is the place where the data is.
The different movements of data allowed for this instruction are:
*Destiny: memory. Source: accumulator
*Destiny: accumulator. Source: memory
*Destiny: segment register. Source: memory/register
*Destiny: memory/register. Source: segment register
*Destiny: register. Source: register
*Destiny: register. Source: memory
*Destiny: memory. Source: register
*Destiny: register. Source: immediate data
*Destiny: memory. Source: immediate data
Example:
MOV AX,0006h
MOV BX,AX
MOV AX,4C00h
INT 21H
This small program moves the value of 0006H to the AX register, then it moves the content of AX (0006h) to the BX register, and lastly it moves the 4C00h value to the AX register to end the execution with the 4C option of the 21h interruption.
MOVS (MOVSB) (MOVSW) Instruction
Purpose: To move byte or word chains from the source, addressed by SI, to the destiny addressed by DI.
Syntax:
MOVS
This command does not need parameters since it takes as source address the content of the SI register and as destination the content of DI. The following sequence of instructions illustrates this:
MOV SI, OFFSET VAR1
MOV DI, OFFSET VAR2
MOVS
First we initialize the values of SI and DI with the addresses of the VAR1
and VAR2 variables respectively, then after executing MOVS the content of
VAR1 is copied onto VAR2.
The MOVSB and MOVSW are used in the same way as MOVS, the first one moves one byte and the second one moves a word.
Loading instructions
They are specific register instructions. They are used to load bytes or chains of bytes onto a register.
LODS (LODSB) (LODSW) INSTRUCTION
Purpose: To load chains of a byte or a word into the accumulator. |