You are on page 1of 13

Computer Organization and Assembly

Language
Lab Manual (Lab 01)

Topic: To study assembler, MASM, NASM, TASM, Emulator, Linker, Turbo


Assembler

Lab Instructor: Maham Saleem

Session: Fall 2021

School of Systems and Technology


UMT Lahore Pakistan
Objectives:

Introduction of assembler.

Some concepts and assembler setting snapshot:

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.

Assembly Language Machine Language Operations


MOV AX,A 10100001 00000000 00000000 Fetch the contents of memory word
0 and put it in register AX.
ADD AX,4 00000101 0000100 00000000 Add 4 to AX
MOV A,AX 10100011 0000000 00000000 Store the contents of AX in memory
word 0.

Introduction to Assembler, Linker and Debugger

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.
Step 1
Creating an Assembly Language Program
An assembly language program should be entered with any text editor and have the extension
filename.asm.
Step 2

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;

Filename.asm the source file


Filename.obj generated by TASM
Filename.lst the list file

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;

Filename.exe the Executable file

Step 4

Running DEBUG

TD, the Turbo Debugger, is run with the following command.

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 segment 'data'
; Add your Data here
st1 db "this is my first program in 8086 assembly",13,10,'$'
data_Seg ends
Code_Seg segment 'code'
assume cs:code_Seg, ds:data_Seg, ss:stack_seg
main proc far
; Set Segment Registers
mov ax,data_Seg
mov ds,ax
; Add Your Code Here
mov ah,9
mov dx,offset st1 ;string display
INT 21h
;exit to operating system
MOV AH,4CH
INT 21h
MAIN endp
code_seg ends ; set entry point and stop the assembler
stack_Seg segment stack
db 100h dup (?)
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:

3. Download this file.

Step 4:

5. Extract the contents of the .zip file.

Step 5:
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:

7. Download DOSBOX here.

Step 7:
8. After installing the DOSBox, run it and type the following lines:

MOUNT E C:\TASM    
E:

If you chose a while ago a custom drive besides the directory of C:

LET X be your drive letter:

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

You might also like