You are on page 1of 24

1.

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.

3. Outcomes: The learner will be able to


● Use appropriate instructions to program microprocessor to perform various task
● Familiar with 8086 instruction set.
4. Hardware/Software Required : TASM 5.0
5. Theory:

Assembly Language Assembly Language is a programming language that is very similar to


machine language, but uses symbols instead of binary numbers. It is converted by the assembler
(e.g. Tasm and Masm) into executable machine-language programs. Assembly language is
machine-dependent; an assembly program can only be executed on a particular machine.

Introduction to Assembly Language Tools


Software tools are used for editing, assembling, linking, and debugging assembly language
programming. You will need an assembler, a linker, a debugger, and an editor.

Steps for developing an Assembly Language Program


Assembler – Converts assembly language programs into object files
• Object files contain a combination of machine instructions, data, and information needed to
place instructions properly in memory Assemblers
• Assemblers need to – translate assembly instructions and pseudo-instructions into machine
instructions – Convert decimal numbers, etc. specified by programmer into binary
• Typically, assemblers make two passes over the assembly file – First pass: reads each line and
records labels in a symbol table – Second pass: use info in symbol table to produce actual
machine code for each line 3 Object file format
• Object file header describes the size and position of the other pieces of the file
• Text segment contains the machine instructions • Data segment contains binary representation
of data in assembly file
• Relocation info identifies instructions and data that depend on absolute addresses
• Symbol table associates addresses with external labels and lists unresolved references
• Debugging info

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

A debugger is a computer program used by programmers to test and debug a target


program.Debuggers may use instruction-set simulators, rather than running a program directly on
the processor to achieve a higher level of control over its execution.
Linker
• Tool that merges the object files produced by separate compilation or assembly and creates an
executable file
• Three tasks
– Searches the program to find library routines used by program, e.g. printf(), math routines.
– Determines the memory locations that code from each module will occupy and relocates its
instructions by adjusting absolute references
– Resolves references among files

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

For example: INC AX ; one operand (add 1 to register AX)


MOV AX, 100 ; two operands (store 100 in register AX)

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

5- Write your code then save and exit.

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.

      7. Viva Questions:


● What is Effective address.
● What is the use of mov ah,4ch
● What are segment registers.

      8. References:

1. Microprocessor and Interfacing: Douglas Hall, Tata McGraw Hill

2. Microcomputer Systems: 8086/8088 family Architecture, Programming and Design: Liu


&  Gibson, PHI Publication
Microprocessor
Experiment No. : 2

Write a program using DOS interrupts to


accept input from keyboard and display it
on screen. If 0 key is pressed program is
terminated.
Microprocessor
Experiment No. : 2
Write an assembly language program to
implement basic arithmetic operations on
two 8 / 16 bit numbers

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

● Familiar with 8086 arithmetic operations instruction


● Understand, identify, analyze the problem ,implement and validate the solution including
both hardware and software

4. Hardware/Software Required : TASM 5.0


5. Theory: Following instruction may be used for implementation and its formats are as
follows

Add two numbers


          ADD
Syntax: Add dest, src
dest: register or memory
src: register, memory, or immediate
Action: dest = dest + src
Flags Affected: OF, SF, ZF, AF, PF, CF
Notes: Works for both signed and unsigned numbers.
For AX = 1234

Example 1234 H
: H
BX = + 0100
0100 H
H

1334
H
           SUB Subtract two numbers

Syntax: Sub dest, src


dest: regsiter or memory
src: register, memory, or immediate
Action: dest = dest – src
Flags Affected: OF, SF, ZF, AF, PF, CF
Notes: Works for both signed and unsigned numbers.
           MUL Unsigned multiply

Syntax: Mul op8


mul op16 op8: 8-bit register or memory

op16: 16-bit register or memory


Action: If operand is op8, unsigned AX = AL * op8

If operand is op16, unsigned DX::AX = AX * op16 Flags Affected:


OF, SF=?, ZF=?, AF=?, PF=?, CF

DIV Unsigned
divide
Syntax: Div op8
Div op16

op8: 8-bit register or memory op16: 16-bit


register or memory

Action: If operand is op8, unsigned AL = AX / op8 and AH = AX % op8


If operand is op16, unsigned AX = DX::AX / op16 and DX = DX::AX %
op16
Flags Affected: OF=?, SF=?, ZF=?, AF=?, PF=?, CF=?
Notes: Performs both division and modulus operations in one instruction.

IDIV Signed
divide
Syntax: Idiv op8
Idiv op16

op8: 8-bit register or memory op16: 16-bit


register or memory

Action: If operand is op8, signed AL = AX / op8 and AH = AX % op8

If operand is op16, signed AX = DX::AX / op16 and DX = DX::AX % op16 Flags Affected:
OF=?, SF=?, ZF=?, AF=?, PF=?, CF=?

Notes: Performs both division and modulus operations in one instruction.


IMUL Signed
multiply
Syntax: Imul op8
Imul op16

op8: 8-bit register or memory op16: 16-bit


register or memory

Action: If operand is op8, signed AX = AL * op8

If operand is op16, signed DX::AX = 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.

7. QUIZ / Viva Questions:

● 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:

1. Microprocessor and Interfacing: Douglas Hall, Tata McGraw Hill

2. Microcomputer Systems: 8086/8088 family Architecture, Programming and Design:


Liu &  Gibson, PHI Publication

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

3. Outcomes: The learner will be able to


● Work with 8086 string instruction operation.
● apply knowledge of computing, applied mathematics, and fundamental engineering
concepts appropriate to the discipline.
4. Hardware/Software Required : TASM 5.0

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.

Let the number of bytes N = 10.

We will have to initialize this as count in the CX register.

We know that source address is in the SI register and destination address is in the DI register.

Clear the direction flag.

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

2. Microcomputer Systems: 8086/8088 family Architecture, Programming and Design: Liu


&  Gibson, PHI Publication

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

3. Outcomes: The learner will be able to


● Work with 8086 procedure operation.
● Identify,formulate,and solve engineering problems
4. Hardware/Software Required : TASM 5.0

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.

3. Load the number in BX.

4. Call procedure fact.

5. Compare BX with 1, if not go to step 7.

6. AX = 1 and return back to the calling program.

7. AX = AX × BX.

8. Decrement BX.

9. Compare BX with 1, if not go to step 7.

10. Return back to calling program.

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:

1. Microprocessor and Interfacing: Douglas Hall, Tata McGraw Hill

2. Microcomputer Systems: 8086/8088 family Architecture, Programming and Design: Liu &
Gibson, PHI Publication

You might also like