Download mpmc lab_expt1-introduction-to-tasm

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
1. INTRODUCTION TO TASM
Introduction:
The aim of this experiment is to introduce the student to assembly language programming
and the use of the tools that he will need throughout the lab experiments. This first
experiment let the student use the Dos Debugger and the Microsoft Turbo Assembler
(TASM). Editing, Assembling,Linking, Execute up can be done using TASM software
Objectives:
1. Introduction to Microsoft Turbo Assembler (TASM)
2. General structure of an assembly language program
3. Use of the Dos Debugger program
Overview:
In general, programming of microprocessor usually takes several iterations before the right
sequence of machine code instruction is written. The process, however is facilitated using a
special program called an “Assembler”. The Assembler allows the user to write alphanumeric
instructions. The Assembler, in turn, generates the desired machine instructions from the
assembly language instructions.
Assembly language programming consists of following steps:
S.No.
1
2
3
4
STEP
Editing
Assembling
linking
Debugging
PRODUCES
Source file
Object file
Executable file
Results
Assembling the program:
The assembler is used to convert the assembly language instructions to machine code. It is
used immediately after writing the Assembly language program. The assembler starts by
checking the syntax or validity of the structure of each instruction in the source file .if any
errors are found, the assemblers displays a report on these errors along with brief explanation
of their nature. However If the program does contain any errors , the assembler produces an
object file that has the same name as the original file but with the “obj” extension
Linking the program:
The Linker is used convert the object file to an executable file. The executable file is the final
set of machine code instructions that can directly be executed by the microprocessor. It is the
different than the object file in the sense that it is self-contained and re-locatable. An object
file may represent one segment of a long program. This segment can not operate by itself, and
must be integrated with other object files representing the rest of the program ,in order to
produce the final self-contained executable file
Executing the program
The executable contains the machine language code .it can be loaded in the RAM and
executed by the microprocessor simply by typing, from the DOS prompt ,the name of the file
followed by the carriage Return Key (Enter Key). If the program produces an output on the
screen or sequence of control signals to control a piece of hard ware, the effect should be
noticed almost immediately. However, if the program manipulates data in memory, nothing
would seem to have happened as a result of executing the program.
Procedure to enter a program using TASM software
Start
↓
Run
↓
Type CMD
↓
Ok
Display shows
↓
C :\> D:(drive name where your folder created)
(Change to D(your) drive because TASM is in D(your) drive)
↓
Press ENTER
↓
D :\> CD TASM
↓
Press ENTER
↓
D: \TASM> EDIT FILENAME.ASM
Example edit add16.asm
↓
Press ENTER
↓
Then the display shows editor
↓
Type the asm program
↓
Then the save the program (Use Alt+F keys to appear the option window)
↓
Exit from editor Using Alt+F keys
↓
Then Display shows D: \TASM>
↓
Enter the name TASM FILENAME.ASM
Example
↓
D: \TASM> TASM add16.asm
Then Display shows Errors,(0)Warnings(0)
If there is errors correct them
↓
Enter the name Tlink FILENAME.OBJ
Example
↓
D: \TASM> TLINK add16.obj
↓
Then the display shows
Turbo Link Version 3.0
↓
Enter the name TD FILENAME.EXE
Example
↓
D: \TASM> TD add16.exe
↓
Then the display shows
Program has no symbol table
Choose OK
↓
RUN the Program using F7 key for step wise execution or F9 Key for at a time
executionor Select the RUN Option
↓
See the data in Registers
↓
See the data in Data segment Using Alt+F -_View-_Dump
Procedure to enter the data into memory location.
Sample program
Assume cs: code, ds: data
Data segment
Input equ 3000h
Result equ 4000h
Data ends
Code segment
Start:Mov ax,data
Mov ds,ax
Mov si,input
Mov al,[si]
Inc si
Mov bl,si
Add al,bl
Mov [di],al
Int 03h
Code ends
End start
For the above sample program we have to enter the data into memory locations.
For that the procedure is given below
Step1: Type the sample program by using the above procedure.
Follow the steps up to Enter the name TD FILENAME.EXE
Example ↓
D: \TASM> TD add16.EXE
Then the (display shows the program has no symbol table)
Step2: Choose OK & using single step execution move specified address to index registers
(Press F8 key for single step execution)
Step3: Display shows C:windows\system32\cmd.td filename.exe
Select the view option using right arrow and choose the dump
Step4: Right click on the address to enter the address position
Step5: Enter the specified address and give data in data location
Step6: Run the program using F9 Key or Select the RUN Option location
Step7: See the result in specified memory
Address data
Ex: 4000 08h
Assembler Directives of 8086
Assembler directives give instruction to the assembler where as other instructions discussed
in the above section give instruction to the 8086 microprocessor. Assembler directives are
specific for a particular assembler. However all the popular assemblers like the Intel 8086
macro assembler, the turbo assembler and the IBM macro assembler use common assembler
directives.
The most common assembler diretives are as follows:
 ORG
: Originate
 ASSUME
 DB
: Define Byte
 DD
: Define Double Word
 DQ
: Define Quad Word
 DT
: Define Ten Bytes
 DW
: Define Word
 END
: Ends Program
 END
: End Segment
 ENDP
: End Procedure
 EQU
: Equate
 INCLUDE
ORG
It is the location in memory where you want the binary program to be loaded to, if any.
ASSUME Directive
The ASSUME directive tell the assembler the name of the logical segment it should use for a
specified segment. The 8086 works directly with only 4 physical segments: a Code segment,
a data segment, a stack segment, and an extra segment.
Examples:
ASUME CS: CODE
This tells the assembler that the logical segment named CODE contains the instruction
statements for the program and should be treated as a code segment.
ASUME DS: DATA
This tells the assembler that for any instruction which refers to a data in the data segment,
data will found in the logical segment DATA.
DB
The DB directive is used to declare a byte-type variable or to set aside one or more storage
locations of type byte in memory
Examples:
1. PRICE DB 49h, 98h, 29h
Declare an array of 3 bytes, named as PRICE and initialize.
2. NAME DB ‘ABCDEF’
Declare an array of 6 bytes and initialize with ASCII code for letters
3. TEMP DB 100 DUP(?)
Set 100 bytes of storage in memory and give it the name as TEMP, but leave the 100 bytes
uninitialized. Program instructions will load values into these locations.
DD
The DD directive is used to declare a variable of type doubleword or to reserve memory
locations which can be accessed as type doubleword
Example:
MULTIPLIER DW 437Ah
This declares a variable of type word and named it as MULTIPLIER. This variable is
initialized with the value 437Ah when it is loaded into memory to run.
EXP1 DW 1234h, 3456h, 5678h
This declares an array of 3 words and initialized with specified values.
STOR1 DW 100 DUP(0)
Reserve an array of 100 words of memory and initialize all words with 0000.Array is named
as STOR1
DQ
The DQ directive is used to tell the assembler to declare a variable 4 words in length or to
reverse 4 words of storage in memory
END
The ENDS directive is used with the name of a segment to indicate the end of that logical
segment. It is aced after the last statement of a program to tell the assembler that this is the
end of the program module. The assembler will ignore any statement after an END directive.
Carriage return is required after the END directive.
ENDS
This ENDS directive is used with name of the segment to indicate the end of that logic
segment.
Example:
CODE SEGMENT
Hear it Start the logic; segment containing code. Some instructions to perform the logical
operation.
CODE ENDS
End of segment named as CODE
ENDP
ENDP directive is used along with the name of the procedure to indicate the end of a
procedure to the assembler
Example:
SQUARE_NUM PROCE
It start the procedure ; Some steps to find the square root of a number
SQUARE_NUM ENDP
Here it is the End for the procedure .
EQU
The EQU is used to give a name to some value or symbol. Each time the assembler finds
the name in the program, it will replace the name with the value or symbol you given to that
name.
Example:
FACTOR EQU 03H
this statement is written at the starting of program and later in the program it can be used
anywhere.
ADD AL, FACTOR
When assembler finds this instruction the assembler will code it as ADDAL, 03H
The advantage of using EQU in this manner is, if FACTOR is used many no of times in a
program and you want to change the value, all you had to do is change the EQU statement at
beginning, it will changes the rest of all.
INCLUDE
-This INCLUDE directive is used to insert a block of source code from the named file into
the current source module.
DOS Function Calls
AH 00H
: Terminate a Program
AH 01H
: Read the Keyboard
AH 02H
: Write to a Standard Output Device
AH 08H
: Read a Standard Input without Echo
AH 09H
: Display a Character String
AH 0AH
: Buffered keyboard Input
INT 21H
: Call DOS Function