Professional Documents
Culture Documents
First 4 Experiment MP
First 4 Experiment MP
Aim: To Use of programming tools (Tasm 8086) to perform basic assembly language
program to accept and display “hello world” on screen using DOS / BIOS.
2. Objectives:
● To emphasize on use of Assembly language program
● To prepare students for advanced subjects like embedded system and IOT.
Loader
• Part of the OS that brings an executable file residing on disk into memory and starts it running
• Steps
– Read executable file’s header to determine the size of text and data segments
– Create a new address space for the program
– Copies instructions and data into address space
– Copies arguments passed to the program on the stack
– Initializes the machine registers including the stack ptr
– Jumps to a startup routine that copies the program’s arguments from the stack to registers and
calls the program’s main routine
An assembler is a program that converts source-code programs written in assembly language into
object files in machine language. Popular assemblers have emerged over the years for the Intel
family of processors. These include MASM (Macro Assembler from Microsoft), TASM (Turbo
Assembler from Borland), NASM (Netwide Assembler for both Windows and Linux), and GNU
assembler distributed by the free software foundation. We will use MASM 6.15 and TASM.
• Masm.exe creates an .obj file from an .asm file. Linker A linker is a program that combines
your program's object file created by the assembler with other object files and link libraries, and
produces a single executable program. You need a linker utility to produce executable files.
• Link.exe creates an .exe file from an .obj file.
• Use make16.bat to assemble and link a 16-bit format assembly program.
• Use make32.bat to assemble and link a 32-bit format assembly program. Debugger A debugger
is a program that allows you to trace the execution of a program and examine the content of
registers and memory. For 16-bit programs, MASM supplies a 16-bit debugger named
CodeView
.∙ CodeView can be used to debug only 16-bit programs and is already provided with the MASM
6.15 distribution. Editor You need a text editor to create assembly language source files.
MASM6.15 has its own editor or you can use for example Notepad++.
To make programs in assembly language, you must know some information about the 8086
microprocessor. The 8086 contains 14 registers. Each register is 16 bits long. See Figure (1)
General-Purpose Registers: Named storage locations inside the CPU, optimized for speed. To
Access Parts of Registers we can Use 8-bit name, 16-bit name, or 32-bit name; this is applied to
EAX, EBX, ECX, and EDX. Each register has different usage as shown in Table (1) below. The
general purpose registers can be "split". AH contains the high byte of AX and AL contains the
low byte. You also have: BH, BL, CH, CL, DL, DH. So if for example, DX contains the value
1234h DH would be 12h and DL would be 34h.
Table(1): Registers of 8086 microprocessor and their purposes
And a 16-bit FLAG Register. The FLAGS Register consists of 9 status bits. These bits are also
called flags, because they can either be SET (1) or NOT SET (0). All these flags have a name
and purpose
Control Flags: Control flags control the CPU’s operation. For example, they can cause the CPU
to break after every instruction executes, interrupt when arithmetic overflow is detected.
Programs can set individual bits in the EFLAGS register to control the CPU’s operation.
Examples are the Direction, Trap and Interrupt flags. Status Flags: The Status flags reflect the
outcomes of arithmetic and logical operations performed by the CPU. They are the Overflow,
Sign, Zero, Auxiliary Carry, Parity, and Carry flags.
Instruction Forms: Assembly instructions are made up of an operation code (op-code) and set
operands. The op-code identifies the action to be taken. The operands identify the source and
destination of the data. The operands identify CPU registers, memory locations, or I/O ports. The
complete form of an instruction is:
op-code destination operand, source operand
Segments: Code, Data, Stack and Extra; within the 1 MB of memory space the 8086 defines
four 64 Kbyte memory blocks called the code segment, data segment, stack segment, and the
extra segment
Hello Program on TASM assembler
Assembling, Linking, Running a .asm File on TASM:
1-Extract the file TASM Files Run then write cmd and click OK.⎝
2- Click Start
3- Go to directory C:\Tasm\Bin
4- Type the command C:\Tasm\Bin\edit hello.asm
6- Write C:\Tasm\Bin\tasm hello.asm to create the file hello.obj. This file is the machine
language for the program.
7- Write C:\Tasm\Bin\ tlink hello.obj to create the file hello.exe. This file is executable program.
8- Finally, write C:\Tasm\Bin\hello.exe. You will show the message on DOS screen.
6. Conclusion: We learn assembling, linking, running a .asm File on TASM. At this point
we are also able to execute a sample hello program on screen.
8. References:
Experiment No. 2
1. Aim: Write an assembly language program to implement basic arithmetic operations on
two 8 / 16 bit numbers
2. Objectives:
● To understand the basic arithmetic operation in Microprocessor
● To understand techniques for faster execution of instructions and improve speed of
operation and performance of microprocessors
3. Outcomes: The learner will be able to
Example 1234 H
: H
BX = + 0100
0100 H
H
1334
H
SUB Subtract two numbers
DIV Unsigned
divide
Syntax: Div op8
Div op16
IDIV Signed
divide
Syntax: Idiv op8
Idiv op16
If operand is op16, signed AX = DX::AX / op16 and DX = DX::AX % op16 Flags Affected:
OF=?, SF=?, ZF=?, AF=?, PF=?, CF=?
Algorithm :
1. Initialize the data segment.
2. Get the first number in AX register.
3. Get the second number in BX register.
4. Perform arithmetic operation on two numbers.
5. Display the AX/DX result.
6. Stop.
Flow Chart:
6. Conclusion: We have used the arithmetic instructions like Add, Sub, Mul and Div in
assembly language.
● What is an interrupt?
● What are different types of interrupt in 8086?
● How many segment registers are there in 8086?
● What is data segment?
8. References:
Microprocessor
Experiment No. : 3
Write an assembly language program to
transfer data block using string
instructions and without using string
instructions
Experiment No. 3
1. Aim: Write an assembly language program to transfer data block using string instructions
and without using string instructions
2. Objectives:
● To understand the string instruction in Microprocessor
● To understand techniques for faster execution of instructions and improve speed of
operation and performance of microprocessors
5. Theory: Consider that a block of data of N bytes is present at source location. Now this
block of N bytes is to be moved from source location to a destination location.
We know that source address is in the SI register and destination address is in the DI register.
Using the string instruction move the data from source location to the destination location. It is
assumed that data is moved within the same segment. Hence the DS and ES are initialized to the
same segment value.
Algorithm :
1. Initialize the data in the source memory and destination memory.
2. Initialize SI and DI with source and destination address.
3. Initialize CX register with the count.
4. Initialize the direction flag to zero.
5. Transfer the data block byte by byte to destination.
6. Decrement CX.
7. Check for count in CX, if not zero go tostep 5 else to step 8.
8. Stop.
Flowchart :
6. Conclusion: Using the string instruction the data move from source location to the
destination location, data is moved within the same segment. Hence the DS and ES are initialized
to the same segment value.
7. Viva Questions:
● What is the use of string instruction?
● Explain use of DS and ES
8. References:
1. Microprocessor and Interfacing: Douglas Hall, Tata McGraw Hill
Microprocessor
Experiment No. : 4
Write an assembly language program to find
the factorial of a number using procedure.
Experiment No. 4
1. Aim: Write an assembly language program to find the factorial of a number using
procedure
2. Objectives:
● To understand the procedure operation in Microprocessor
● To understand techniques for faster execution of instructions and improve speed of
operation and performance of microprocessors
5. Theory: To compute the factorial of a number means to multiply a number n with (n-1)
(n-2) …× 2 × 1.
Example : to compute 5! = 5×4×3×2×1=120.
We will initialize AX=1 and load the number whose factorial is to be computed in BX. Call
procedure fact, which will calculate the factorial of the number.
Algorithm :
1. Initialize the Data Segment.
2. Initialize AX = 1.
7. AX = AX × BX.
8. Decrement BX.
11. Stop.
Flowchart :
No
No Yes
6. Conclusion : We have use the procedure in 8086 microprocessor to find the factorial.
7. Viva Questions:
● What is procedure in 8086 microprocessor?
● Explain the instructions used in finding factorial.
8. References:
2. Microcomputer Systems: 8086/8088 family Architecture, Programming and Design: Liu &
Gibson, PHI Publication