COAL Lab 1
COAL Lab 1
guage
Lab Manual (Lab 1)
Course Instructor:
Lab Instructor:
Introduction of assembler.
Assembly Language
An assembly language is a low-level programming language for computers, microprocessors,
Microcontrollers, and other integrated circuits. It implements a symbolic representation of the
binary machine codes and other constants needed to program a given CPU architecture. This
representation is usually defined by the hardware manufacturer, and is based on mnemonics that
symbolize processing steps (instructions), processor registers, memory locations, and other
language features. An assembly language is thus specific to certain physical (or virtual) computer
architecture.
Machine Language
Machine language is a pattern of bits that represent the OPCODE and operands, directly
executable by the CPU. The following is a short machine language program or the IBM PC.
Assembler
It is a system program which converts the assembly language program instructions into
machine executable instructions. For example: Microsoft Macro Assembler (MASM), Borland
Turbo Assembler (TASM), Open Source Netwide Assembler (NASM) etc.
MASM
The Microsoft Macro Assembler (MASM) is an x86 assembler for MS-DOS and Microsoft
Windows. It supports a wide variety of macro facilities and structured programming idioms,
Including high-level functions for looping and procedures. Later versions added the capability of
producing programs for Windows.
TASM
Turbo Assembler (TASM) is an x86 assembler package developed by Borland. It is used with
Borland's high-level language compilers, such as Turbo Pascal, Turbo Basic and Turbo C. The
Turbo Assembler package is bundled with the linker, Turbo Linker, and is interoperable with the
Turbo Debugger.
NASM
The Net wide Assembler (NASM) is an assembler and disassemble for the Intel x86 architecture.
It can be used to write 16-bit, 32-bit (IA-32) and 64-bit (x86-64) programs. NASM is considered
to be one of the most popular assemblers for Linux and is the second most popular assembler
overall, behind MASM.
NASM was originally written by Simon Tatham with assistance from Julian Hall, and is
currently maintained by a small team led by H. Peter Anvin.
Emulators
Emulator allows computer program to run on a platform (computer architecture and/or operating
system ) other than for which they were originally developed unlike the simulation which only
attempts to reproduce a program's behavior ,emulation attempts to model to various degrees the
state of device being emulated.
EMU8086 is emulator which emulates the behavior of 8086 machine.Emu8086 IDE contains
built in assembler which is compatible with syntax of MASAM, TASAM and few other
assemblers.
It also contains debugger which can be used to debug executable program. In emu8086 one can
emulate each instruction of program one by one and can views the value of registers, flags and
variable changed by instruction.
Linker
Linker or link editor is a program that takes one or more objects generated by a compiler and
combines them into a single executable program. When a program comprises multiple object
files, the linker combines these files into a unified executable program.
Linkers can take objects from a collection called a library. Some linkers do not include the whole
library in the output; they only include its symbols that are referenced from other object files or
libraries.
TURBO ASSEMBLER
The basic steps required to create, assemble, link and debug programs using MS
Notepad and the Borland Turbo C tools TASM, TLINK and TDEBUG, respectively. Each step
requires certain command parameters and programs to be run in order to accomplish on-line
debugging.
1 Step
Creating an Assembly Language Program
An assembly language program should be entered with any text editor and have the extension
filename.asm.
2 Step
Assembling a Program
Once you have entered this program you need to assemble it. This is done using the following
TASM command line syntax.
TASM Filename.asm
The .asm extension is assumed for the file. The files generated by this command will be;
Step 3
Linking a program
As a final step you need to run the Turbo linker (TLINK) to create an EXE (executable) file by
the name of filename.exe. This is done by entering the following command.
TLINK Filename.obj
The .obj extension is assumed for the file. The files generated by this command will be;
Step 4
Running DEBUG
TD Filename.exe
Step 5
Execution of Program
The execution of program is done by entering the following command.
Filename.exe
First program in Assembly
The following program displays the string "this is my first program in 8086 assembly" on screen.
.model small
data_Seg ends
mov ax,data_Seg
mov ds,ax
mov ah,9
INT 21h
MOV AH,4CH
INT 21h
MAIN endp
stack_Seg ends
end main
Basic Steps to install and run DosBox, TASM and Compile
x86 Assembly Program in Windows 7 64 bit Version
Step 1:
1. Go to Start, and My Computer. Click on (C:) Local Disk C (or any desired location
you want).
Step 2:
2. On the directory, create a folder and name it TASM ( or any name you want).
Step 3:
Step 4:
5. Copy the extracted files to the folder TASM (or to the folder you've made awhile ago). Also,
don't forget to extract the DEBUG125.zip to the same folder.
Step 6:
8. After installing the DOSBox, run it and type the following lines:
MOUNT E C:\TASM
E:
MOUNT E X:\TASM
E:
Step 8:
9. Put your assembly code (e.g <your filename>.asm) in the same directory where you installed
TASM and TLINK and run it by typing:
TASM <yourfilename>
TLINK <yourfilename>
Step 9:
10. The executable file is located in the folder TASM or your chosen directory. You can run it as
it is or via CMD by typing <yourfilename>.exe
Step 10:
Extra (Optional):
11. The debug command was deleted in Windows 7 64 bit machines. The file that you've
downloaded and installed has the 'debug' executable files. Now, you can run it via DOSBox by
typing in DEBUG or DEBUG <your+executable+file>.exe.
Step 11:
Lab Task
Task # 1:
Copy the above code in notepad and save the file in c:\temp folder or c:\turbo assembler
folder with extension .asm i.e. First_program.asm
Then go to the command prompt by writing cmd or go to the Dosbox
Execute the .asm file saved above by writing the instruction tasm ,tlink
Observe the output