You are on page 1of 43

NASM

PROGRAMMING

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 1


LAB # 01

OBJECT: Introduction to 8086/8088 microprocessor

8086 MICROPROCESSOR:

[description of 8086 microprocessor]

REGISTER SET

a. General Purpose Registers:

b. Special Purpose Registers:

c. Instruction Pointer:

d. FLAG Register:

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 2


a. General Purpose Registers:

b. Special Purpose Registers:

c. Instruction Pointer:

d. FLAG Register:

iAPX88 ARCHITECTURE:

a. Description:

b. Offset/Logical Address (16-bit):

c. Base Address (16-bit):

d. Formation of Physical Address (20-bit):

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 3


LAB # 02

OBJECT: To become familiar with basic tools used for assembling,


debugging and executing assembly programs

TOOLS: Desktop System, NASM, AFD and Windows Xp.

INTRODUCTION:

To run an assembly program, we need editor, assembler and debugger.


Different assemblers are available such MASM, TASM and NASM etc. To
detect and get detailed information about a particular program, a software
tool debugger is needed.

NOTEPAD AS AN EDITOR:

[place here description and snapshots of editor and saving


method.]

NASM:

[place here description]

AFD:

[place here description and snapshots of debugger.]

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 4


LAB # 03

OBJECT: To become familiar with the Instruction groups and assembly


instructions and MNEMONICS.

THEORY:

INSTRUCTION EXECUTION CYCLE


Fetch/Decode/Execute cycle is like a program:
1. Fetch instruction from primary memory
2. Increment Program Counter
3. Decode
4. Fetch operands from memory (if required)
5. Execute instruction
6. Write results to memory (if required)
7. Until Halt

e.g. ADD Instruction


1. Fetch operand1, store in register X
2. Fetch operand2, store in register Y
3. Tell ALU to add X and Y
4. Put result in ACC

MICROCODE (SEE FIG. BELOW)


1. Lowest level of software
2. Flexible: can be updated by designers
3. Controls the digital logic of the CPU
4. Implements the machine code instructions

INSTRUCTIONS
1. Each type of CPU has it s own Instruction Set
2. The set of instructions that can be decoded and executed
3. Each instruction has a number
4. Usually written as a "mnemonic"
5. 8086 instruction set (79 basic instructions)
AAA AAD AAM AAS
ADC ADD AND CALL
CBW CLC CLD CLI

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 5


CMC CMP CMPS CMPXCHG
CWD DAA DAS DEC
DIV ESC HLT IDIV
IMUL IN INC INT
INTO IRET/IRETD Jxx JCXZ/JECXZ
JMP LAHF LDS LEA
LES LOCK LODS LOOP
MOV MOVS LOOPE/LOOPZ LOOPNZ/LOOPNE
MUL NEG NOP NOT
OR OUT POP POPF/POPFD
PUSH RCL RCR PUSHF/PUSHFD
REP REPE/REPZ RET/RETF REPNE/REPNZ
ROL ROR SAHF SAL/SHL
SAR SBB SCAS SHL
SHR STC STD STI
STOS SUB TEST WAIT/FWAIT
XCHG XLAT/XLATB XOR

INSTRUCTION GROUPS

Data Movement Instructions

These instructions are used to move data from one place to another. Some
examples are:
mov ax, bx
lda 1234 (load accumulator with 1234)
Arithmetic and Logic Instructions

Arithmetic instructions like addition, subtraction, multiplication, division


and Logical instructions like XOR, OR
and ax, 1234
add bx, 0534
add bx, [1200]

Program Control Instructions


These are instructions that control the program execution and flow by
playing with the instruction pointer and altering its normal behavior to point
to the next instruction Some examples are:

cmp ax, 0
jne 1234

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 6


Special Instructions
Another group called special instructions works like the special services
agents. Some examples are:
cli
sti

INSTRUCTION ENCODING
1. Instruction defined by Opcode and Operands
2. Decoded by examining bit patterns
3. If operands used, must specify addresses

Examples:

Zero-address instruction: Opcode

One-address instruction:
Opcode Address

Two-address instruction: Opcode Address1 Address2

Instruction Length may be shorter than/ same as / longer than a machine


word

TASK(S):

Write down the opcodes of following instructions

INSTRUCTION OPCODE

a. ADD:
b. JNZ
c. MOV
d. JNE
e. SUB
f. CMP

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 7


LAB # 04

OBJECT: To become familiar with addressing mode.

THEORY:
ADDRESSING: The iAPX88 processor supports seven modes of memory
access. Remember that immediate is not an addressing mode but an operand
type. Operands can be immediate, register, or memory. If the operand is
memory one of the seven addressing modes will be used to access it

Addressing Modes

1.Offset Addressing (Default Segment=DS)


2.Base Addressing (Default Segment=DS or SS)
3. Index Addressing (Default Segement = DS)
4. Base+Offset Addressing (Default Segment=DS or SS)
5.Index+Offset Addressing (Default Segement = DS)
6.Base + Offset Addressing (Default Segment=DS or SS)
7.Base+Index+Offset Addressing (Default Segment=DS or SS)

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 8


DIAGRAM:

CONCLUSION: Generic form can be used to understand the entire


addressing
modes. We shall drop the particular addressing mode technique from the last
and
larger addressing mode which is Base+Index+Offset Addressing as shown
below:

[ Base + Index + Offset ]


By dropping Base we get:
[ Index + Offset ]
By dropping Base plus Index we get:
[ Offset ]
By dropping Index we get:
[ Base + Offset ]

TASK(S):
Note: Use a separate sheet to answer the following questions:

1. Write some words on segmented memory model of IAPX88 Architecture

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 9


2. What is an Offset Address?

3. What is a Segment Address?

4. Relate Base Address with Datum point Concept

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 10


LAB # 05

OBJECT: Writing, Assembling and Debugging a program in Assembly

language using immediate addressing mode.

TOOLS: Desktop System, NASM, AFD and Windows Xp

THEORY:

ASSEMBLER: An Assembler is a tool to convert our low level program


(Source Program) into Machine Code (Object Code). Assembly uses
MNEMONICS to write instructions. Mnemonics are short-abbreviations for
whole instructions. In other words, we can say it’s a coding language for
larger English Language Sentences.
For Example:

MOVE 5 TO AX
MOVE 10 TO BX
ADD BX TO AX
MOVE 15 TO BX

Above English language sentences can be converted into assembly language


conveniently by keeping some points as discussed where necessary.

AFD DEBUGGER: Advanced Fullscreen Debugger (AFD) is used to execute


assembly program. It is a useful tool to understand the internal behavior of
registers, memory and flags etc.

Conversion
Note: the general format of instructions is operation destination, source
MOV AX,5
MOV BX,10
ADD AX,BX
MOV BX,15

Writing and assembling program in NASM by assuming that AFD debugger is


in NASM folder which is copied in C:\

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 11


PROCEDURE:
STEP.1: Open notepad and write following program.

;a program to add three numbers using registers


[org 0x0100] ; originate program at 0100 address
mov ax, 5 ; load first number in ax
mov bx, 10 ; load second number in bx
add ax, bx ; accumulate sum in ax
mov bx, 15 ; load third number in bx
add ax, bx ; accumulate sum in ax
mov ax, 0x4c00 ; terminate program
int 0x21

Note: ( In Assembly Language ; semicolon is used to write comments in


program)
STEP.2: Save program with the extension of .asm (E.g prog1.asm) in NASM
folder
Note: by default in notepad file type is “Text Document” which makes file
name ultimately as text file (e.g prog1.asm.txt), so change it to “All Files”

STEP.3: Open Command prompt and write following command:


C:\NASM>nasm prog1.asm –l prog1.lst -o prog1.com
Above command is used to give instruction to assembler NASM to assemble
the
prog1.asm file. –l parameter is used to create listing file of prog1.asm as
prog1.lst
and –o parameter is used to create its com (executable file) which can be
executed
in AFD debugger.

STEP.4: Write the following command in command prompt to view listing file
C:\NASM>edit prog1.lst

STEP.5: To execute the program use following command in command prompt


C:\NASM>afd prog1.com

STEP.6: By pressing F1 function key one by one instructions are to be


executed

TASK(S):
1. Write down the code which is produced in listing file by assembler (Use
separate sheet). Describe each column in listing file.

2. Describe each windows in AFD debugger

3. Write down offset values for each instruction

4. Observe and write the changes are being made in IP register and other
registers during the execution of program line by line.

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 12


LAB # 06

OBJECT: Writing a program that uses direct / offset addressing mode.

TOOLS: Desktop System, NASM, AFD and Windows Xp

; a program to add three numbers using memory variables

Program 2: (prog2.asm)

[org 0x0100]
mov ax, [num1] ; load first number in ax
mov bx, [num2] ; load second number in bx
add ax, bx ; accumulate sum in ax
mov bx, [num3] ; load third number in bx
add ax, bx ; accumulate sum in ax
mov [num4], ax ; store sum in num4
mov ax, 0x4c00 ; terminate program
int 0x21
num1: dw 5 ; variable declaration
num2: dw 10
num3: dw 15
num4: dw 0

Program 3: (prog3.asm)
; a program to add three numbers accessed using a single label
[org 0x0100]
mov ax, [num1] ; load first number in ax
mov bx, [num1+2] ; load second number in bx
add ax, bx ; accumulate sum in ax
mov bx, [num1+4] ; load third number in bx
add ax, bx ; accumulate sum in ax
mov [num1+6], ax ; store sum at num1+6
mov ax, 0x4c00 ; terminate program
int 0x21

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 13


num1: dw 5
dw 10
dw 15
dw 0

Program 4: (prog4.asm)
; A program to add three numbers accessed using a single label
[org 0x0100]
mov ax, [num1] ; load first number in ax
mov bx, [num1+2] ; load second number in bx
add ax, bx ; accumulate sum in ax
mov bx, [num1+4] ; load third number in bx
add ax, bx ; accumulate sum in ax
mov [num1+6], ax ; store sum at num1+6
mov ax, 0x4c00 ; terminate program
int 0x21
num1: dw 5, 10, 15, 0

TASK(S):
1. Calculate the size of file by looking/observing the code produced in listing
file.
Hint: calculate the size of opcode generated by assembler in
listing file.

2. Write a program that adds 10 numbers and finally subtract the value 5
from result of summation.

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 14


LAB # 07

OBJECT: To become familiar with Register Indirect addressing mode.

TOOLS: Desktop System, NASM, AFD and Windows Xp

THEORY: The key to this is the need for some register that can hold the
address of data. So that we can change the address to access some other cell
of memory using the same instruction. In direct addressing mode the memory
cell accessed was fixed inside the instruction. There is another method in
which the address can be placed in a register so that it can be changed. For
the following example we will take 10 instead of 100 numbers but the
algorithm is extensible to any size. There are four registers in iAPX88
architecture that can hold address of data and they are BX, BP, SI, and DI.

; a program to add three numbers using indirect addressing

[org 0x100]
mov bx, num1 ; point bx to first number
mov ax, [bx] ; load first number in ax
add bx, 2 ; advance bx to second number
add ax, [bx] ; add second number to ax
add bx, 2 ; advance bx to third number
add ax, [bx] ; add third number to ax
add bx, 2 ; advance bx to result
mov [bx], ax ; store sum at num1+6
mov ax, 0x4c00 ; terminate program
int 0x21
num1: dw 5, 10, 15, 0

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 15


LAB # 08

OBJECT: writing a program using loop


TOOLS: Desktop System, NASM, AFD and Windows Xp

; a program to add ten numbers

[org 0x0100]
mov bx, num1 ; point bx to first number
mov cx, 10 ; load count of numbers in cx
mov ax, 0 ; initialize sum to zero
l1: add ax, [bx] ; add number to ax
add bx, 2 ; advance bx to next number
sub cx, 1 ; numbers to be added reduced
jnz l1 ; if numbers remain add next
mov [total], ax ; write back sum in memory
mov ax, 0x4c00 ; terminate program
int 0x21
num1: dw 10, 20, 30, 40, 50, 10, 20, 30, 40, 50
total: dw 0

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 16


LAB # 09

OBJECT: Writing a program to add ten numbers using loop and register +
offset addressing.

TOOLS: Desktop System, NASM, AFD and Windows Xp

PROGRAM
[org 0x0100]
mov bx, 0 ; initialize array index to zero
mov cx, 10 ; load count of numbers in cx
mov ax, 0 ; initialize sum to zero
l1: add ax, [num1+bx] ; add number to ax
add bx, 2 ; advance bx to next index
sub cx, 1 ; numbers to be added reduced
jnz l1 ; if numbers remain add next
mov [total], ax ; write back sum in memory
mov ax, 0x4c00 ; terminate program
int 0x21
num1: dw 10, 20, 30, 40, 50, 10, 20, 30, 40, 50
total: dw 0

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 17


LAB # 10

OBJECT: A program to add ten numbers without a separate counter


TOOLS: Desktop System, NASM, AFD and Windows Xp
PROGRAM
[org 0x0100]
mov bx, 0 ; initialize array index to zero
mov ax, 0 ; initialize sum to zero
l1: add ax, [num1+bx] ; add number to ax
add bx, 2 ; advance bx to next index
cmp bx, 20 ; are we beyond the last index
jne l1 ; if not add next number
mov [total], ax ; write back sum in memory
mov ax, 0x4c00 ; terminate program
int 0x21
num1: dw 10, 20, 30, 40, 50, 10, 20, 30, 40, 50
total: dw 0

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 18


LAB # 11

OBJECT: A program to add ten numbers without a separate counter using


Unconditional Jump.
TOOLS: Desktop System, NASM, AFD and Windows Xp
PROGRAM
[org 0x0100]
jmp start ; unconditionally jump over data
num1: dw 10, 20, 30, 40, 50, 10, 20, 30, 40, 50
total: dw 0
start: mov bx, 0 ; initialize array index to zero
mov ax, 0 ; initialize sum to zero
l1: add ax, [num1+bx] ; add number to ax
add bx, 2 ; advance bx to next index
cmp bx, 20 ; are we beyond the last index
jne l1 ; if not add next number
mov [total], ax ; write back sum in memory
mov ax, 0x4c00 ; terminate program
int 0x21

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 19


LAB # 12

OBJECT: Sorting a list of ten numbers using bubble sort


TOOLS: Desktop System, NASM, AFD and Windows Xp
PROGRAM
[org 0x0100]
jmp start
data: dw 60, 55, 45, 50, 40, 35, 25, 30, 10, 0
swap: db 0
start: mov bx, 0 ; initialize array index to zero
mov byte [swap], 0 ; rest swap flag to no swaps
loop1: mov ax, [data+bx] ; load number in ax
cmp ax, [data+bx+2] ; compare with next number
jbe noswap ; no swap if already in order
mov dx, [data+bx+2] ; load second element in dx
mov [data+bx+2], ax ; store first number in second
mov [data+bx], dx ; store second number in first
mov byte [swap], 1 ; flag that a swap has been done
noswap: add bx, 2 ; advance bx to next index
cmp bx, 18 ; are we at last index
jne loop1 ; if not compare next two
cmp byte [swap], 1 ; check if a swap has been done
je start ; if yes make another pass
mov ax, 0x4c00 ; terminate program
int 0x21

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 20


MASM
PROGRAMMING

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 21


LAB # 13

OBJECT: To become familiar with MASM and its installation procedure on


Windows 7.
LINK: https://lecturercs.wordpress.com/category/assembly-programming/
TOOLS: Desktop System, Windows 7, MASM, DOSBOX 0.74

THEORY: Open the link mentioned above. And following information will be
displayed. Follow the instructions provided via the above link.

1- Download MASM by clicking on the link. It is a .rar file.


2- Extract MASM in C drive C:/MASM (make MASM folder in C).
3- Download DOSBOX 0.74 by clicking on the link. It is .exe file. Install it. It
will be installed in Program Files (x86) folder in C drive.
4- Go to the Program Files (x86), the Go into DOSBOX folder, here you will
find a file DOSBox 0.74 Options, double click on it. It will open in Notepad.
Enter the following code at the end of the file
mount c c:\
c:
cd MASM
Now whenever you will run DOSBOX it will automatically start to use MASM
That’s End
EXECUTION:
C:\MASM> ML prog2-2.asm
C:\MASM> LINK prog2-2.obj
C:\MASM> DEBUG prog2-2.exe
OR
C:\MASM>AFD prog2-2.exe

TASK(S):
1. Print the interface view of DOSBOX 0.74 and paste it here.

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 22


LAB # 14

OBJECT: To become familiar with basic structure of MASM programming.


TOOLS: Desktop System, MASM, AFD and Windows Xp.

INTRODUCTION:

Data Types:

DB Define Byte
DW Define Word
DD Define Doubleword
DQ Define Quadword
DT Define Terabytes

EQU (Equates)
To assign a name to a constant, we can use EQU psedo-op. the syntax is
Name EQU constant
LF EQU 0Ah

XCHG (Exchange)
The XCHG operation is used to swap the contents of two registers.
XCHG AH, BL

ADD
Adds source to destination and saves the result in destination without
affecting source.
ADD WORD1,AX

SUB
Subtracts source to destination and saves the result in destination without
affecting source.
SUB AX,DX

INC
Adds 1 to contents of a register or memory location.
INC WORD1

DEC
Subtracts 1 to the contents of register or memory location.

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 23


DEC WORD1

ALLOCATION OF SPACE FOR PROGRAM:


.MODEL SMALL
Code in one segment
Data in one segment

.MODEL MEDIUM
Code in more than one segment
Data in one segment

.MODEL COMPACT
Code in one segment
Data in more than one segment

.MODEL LARGE
Code in more than one segment
Data in more than one segment
No array larger than 64K bytes

.MODEL HUGE
Code in more than one segment
Data in more than one segment
Array may be larger than 64K bytes

FUNCTIONS IN MASM:
Function 1:
Single-key input
Input: AH=1
Output: AL= ASCII code if character key is pressed
= 0 if non-character key is pressed

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 24


Function 2:
Display a character or execute a control function.
Input: AH=2
DL=ASCII code of the display character or control
character
Output: AL= ASCII code of character of control character

.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
MOV AH,2
MOV DL,’?’
INT 21H
MOV AH,1
INT 21H
MOV BL,AL
MOV AH,2
MOV DL, 0DH ;carriage return
INT 21H
MOV DL, 0AH ;line feed
INT 21H
MOV AH,4C00H
INT 21H
MAIN ENDP
END MAIN

TASK(S): [Note: Program must be HANDWRITTEN]


Modify the program given above that takes character input and display it,
repeat this 5 times.

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 25


LAB # 15
OBJECT: Write a program that displays a string.
TOOLS: Desktop System, MASM, AFD and Windows Xp.

INTRODUCTION:

FUNCTIONS IN MASM:

INT 21H, Function 9:


Display a string
Input: DX=offset address of string
String must end with ‘$’ sign.

LEA (Load Effective Address)


INT 21H, Function 9 expects the offset address of string into DX register. To
do so we use LEA instruction.
LEA destination, source
LEA DX, MSG1 ; it puts copy of offset address of MSG1
;variable into DX register

Program15-1
.MODEL SMALL
.STACK 100H
.DATA
MSG DB ‘HELLO$’
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
LEA DX,MSG
MOV AH,9
INT 21H
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 26


Writing a program to convert CAPITAL LETTER into SMALL CASE
LETTERS.

Program15-2
.MODEL SMALL
.STACK 100H
.DATA
LF EQU 0AH
CR EQU 0DH
MSG1 DB 'ENTER A LOWER CASE LETTER: $'
MSG2 DB 'CAPITLA LETTER IS: $'
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
LEA DX,MSG1
MOV AH,9
INT 21H
MOV AH,1
INT 21H
MOV BL,AL
MOV AH,2
MOV DL,CR
INT 21H
MOV DL,LF
INT 21H
LEA DX,MSG2
MOV AH,9
INT 21H
MOV AH,2
SUB BL,20h ; To make an ASCII equivalent of Captial case letter
MOV DL,BL
INT 21H
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 27


TASK(S): [Note: Program must be HANDWRITTEN]

1. Write a program that display your biodata as follows:


My name is: M. Wasiq (Your name here)
My roll no. is: 45 (Your roll number here)
My favorite subject is: MPS (Your favorite course name here)

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 28


LAB # 16
OBJECT: Write a program that displays 256 ASCII characters.
TOOLS: Desktop System, MASM, AFD and Windows Xp.

.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
MOV CX,256 ;CX is initialized with 256 ASCII characters
MOV AH,2 ; Display function
MOV DL,0 ; Holds ASCII of character
PRINT_LOOP:
INT 21H
INC DL
DEC CX
JNZ PRINT_LOOP
MOV AH,4CH ; DOS function for terminating program
INT 21H
MAIN ENDP
END MAIN

TASK-1: Write a program to display 256 ASCII characters in reverse


order. [Note: Program must be HANDWRITTEN]

TASK-2: Write a program to display English Alphabets of both cases


“Capital and Small” only. [Note: Program must be HANDWRITTEN]

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 29


LAB # 17

OBJECT: Writing a program which displays ‘*’ 20 times if ‘y’ or ‘Y’ is pressed
TOOLS: Desktop System, MASM, AFD and Windows Xp.
.MODEL SMALL
.STACK
.DATA
MSG1 DB 'ENTER Y OR y CONTINUE....$'
MSG2 DB 'YOU PRESSED Y OR y$'
.CODE
MAIN PROC
MOV AX,@DATA ;LOADS OFFSET OF DATA SEGMENT
MOV DS,AX
MOV AH,9
LEA DX,MSG1 ;DISPLAYS MSG1
INT 21H
MOV CX,20
MOV AH,2
MOV DL,0DH
INT 21H
MOV DL,0AH
INT 21H
MOV AH,1 ;READ INPUT CHARACTER
INT 21H
MOV BL,AL
CMP BL,'Y' ;IF Y IS PRESSED
JNE SMALL ;IF Y IS NOT PRESSED THEN COMPARE y
JE PRINT_STAR
SMALL:
CMP BL,'y'
JNE NO_LOOP ; IF Y OR y IS NOT PRESSED THEN GO TO
;NO_LOOP
JE PRINT_STAR
PRINT_STAR:
MOV AH,2 ;PRINTS STAR
MOV DL,'*'

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 30


INT 21H
DEC CX
JNZ PRINT_STAR ;REPEATS PRINT_STAR LOOP TILL CX IS NOT
;EQUAL TO ZERO
MOV AH,2
MOV DL,0DH ;CARRIAGE RETURN
INT 21H
MOV DL,0AH ;LINE FEED
INT 21H
MOV AH,9 ;PRINTING MSG2
LEA DX,MSG2
INT 21H
NO_LOOP:
MOV AH,4CH ;TERMINATING PROGRAM
INT 21H
MAIN ENDP ;PROCEDURE ENDS
END MAIN ;MAIN ENDS

TASK-1: Write a program to display ‘*’ 50 times in each of two lines


[Note: Program must be HANDWRITTEN]

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 31


LAB # 18

OBJECT: Observing the FLAGS before and after the execution of instruction
TOOLS: Desktop System, MASM, AFD and Windows Xp.

.MODEL SMALL
.STACK 100h
.DATA
OP1 DB 25
OP2 DB 20
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
MOV CL,OP1
MOV DL,23
ADD DL,CL
SUB DL,OP2
NOT DL
XOR DL,[OP1+1]
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 32


CONTENTS
OP ADDR
INSTR
CODE OF DF IF SF ZF AF PF CF MODE

BFR AFT BFR AFT BFR AFT BFR AFT

MOV CL,OP1

MOV DL,23

ADD DL,CL

SUB DL,OP2

NOT DL

XOR
DL,[OP1+1]

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 33


MTS-86C
TRAINER

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 34


LAB #

OBJECT: Understanding the keypad mode of MTS-86C Trainer.

TOOLS:
 MTS-86C Microprocessor Trainer
Theory:
In this experiment we are going to identify the working and functionality of
keys on MTS-86C. The keypad is separated into two groups, FUNCTIONS
KEYS and HEXADECIMAL KEYS, as illustrated below in fig(a):

FUNCTION KEYS HEXADECIMAL KEYS

C D
RESET NMI E F
/IP /FL

8 9 A B
+ -
IW/CS OW/DS /SS /ES

4 5 6 7
: REG
IB/SP OB/BP MV/SI EW/DI

0 1 2 3
, .
EB/AX ER/BX GO/CX ST/DX

Keypad of MTS-86C fig(a)

FUNCTION KEYS:
RESET The “RESET” key allows you to terminate any activity and
return the MTS-86C to its initial state. When pressed, the
MTS-86C welcome message appears in the LCD display and
the keypad is ready for command entry.
NMI The interrupt key is used to generate an immediate Non-
Maskable type 2 interrupt (NMI). The NMI interrupt vector is
initialized on power up or system reset to point to a routine
within the monitor which caused all of the 8086’s registers to
be saved. Control is returned to the monitor for subsequent
command entry.
1The interrupt which can be ignored by the processor, while

performing its operations are called Maskable Interrupts.


Generally maskable interrupts are the interrupts that comes
from the peripheral devices.
“A Non-Maskable Interrupt (NMI) is a hardware interrupt that
cannot be ignored by standard interrupt masking techniques
in the system.”
The examples of maskable are: mouse click, memory read etc.
The examples of non_maskable are: power failure, software

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 35


corrupted etc.
+ The “+” (pulse) key allows you to add two hexadecimal values.
This function simplifies relative addressing data by allowing
you to readily calculate an address location relative to a base
address.
- The “-” (minus) key allows you to subtract one hexadecimal
value from another.
: The “:” (colon) key is used to separate the segment address
and offset address.
Seg. Offs Data
0000:0000_ 22 GO
REG The “REG” (register) key allows you to examine 8086 registers
during debugging.
, The “,” (comma) key is used to separate keypad entries and to
add the address shown on LCD display for 1 increment (1 byte
or 2 byte).
. The “.” Key is the command terminator. When pressed, the
current command will be executed.

HEXADECIMAL KEYS:
The Hex Keys are used for either Hexadecimal Number input or Command
input. Address and data of the memory is input by Hexadecimal function.
Program debugging and executing is controlled by command function.

Hexadecimal Command Register


Key Acronym Name Acronym Name
0 Accumulator
EB Examine Byte Ax
EB/AX Register
1 Examine
ER BX Base Register
EX/BX Register
2
GO GO CX Count Register
GO/CX
3
ST Signal Step DX Data Register
ST/DX
4
IB Input Byte SP Stack Pointer
IB/SP
5
OB Output Byte BP Base Pointer
OB/BP
6
MV Move SI Source Index
MV/SI
7 Destination
EW Examine Word DI
EW/DI Index
8
IW Input Word CS Code Segment
IW/CS
9
OW Output Word DS Data Segment
OW/DS
A
None N/A SS Stack Segment
/SS
B
None N/A ES Extra Segment
/ES
C None N/A IP Instruction

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 36


/IP Pointer
D
None N/A FL Flag
/FL
E None N/A None N/A
F None N/A None N/A

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 37


LAB #

OBJECT: Executing the Program using MTS-86C Trainer.

TOOLS:
MTS-86C Microprocessor Trainer

Theory:

Executing the Program (RAM or ROM):


The following program shows the usage of Keypad of MTS-86C keys. First
time when we press any Hexadecimal key except E and F command function
is performed. After this all Hexadecimal keys work as Hexadecimal
numbers. As shown below we are executing the program from inside the
memory by using keys of Keypad of MTS-86C.
The following example shows how to execute the program inside the memory
by using [GO] Command. Simply specified the starting address of the
program by pressing Hexadecimal keys, the program will be executed after
Command is terminated. Note that the starting address may be located at
RAM or ROM. The Demo program of LED flicking is located at (F000:0000).

RESET MTS-86C SYSTEM RESET


K&H MFG
2 Seg. Offs Data GO Command
GO/CX 0000:0000_ xx
Go
F Seg. Offs Data Input Segment Address F000
0000:000F_ xx
Go
0 Seg. Offs Data Input Segment Address F000
EB/AX 0000:00F0_ xx
Go
0 Seg. Offs Data Input Segment Address F000
EB/AX 0000:0F00_ xx
Go
0 Seg. Offs Data Input Segment Address F000
EB/AX 0000:F000_ xx
Go
: Seg. Offs Data Segment / Offset Separator
F000:F000_ xx (Shift copy of offset address to
Go segment)
0 Seg. Offs Data Input Segment Address 0000
EB/AX 0000:0000_ xx
Go
. MTS_86C> INPUT Command Termination
__ /Prompt

The LED should be flicking after terminated the command

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 38


LAB #

OBJECT: Writing a Program in assembly and generating .list, .obj, .bin and

.hex file.

TOOLS:
 Desktop System
 Windows Xp,
 MTS-86C Microprocessor Trainer and its installed Software.
Theory:
In this Experiment we are going to lighting up all the LED’s in MTS-86C by
using the Assembly Language Program.

PROCEDURE:
STEP.1: Open notepad and write following program.

;a program to lighting up all the LED’s in MTS-86C


CNT3 EQU 3FD6H ;Define 8255 control port address
BPORT3 EQU 3FD2H ;Define 8255 portB address

CODE SEGMENT
ASSUME CS:CODE,DS:CODE

ORG 0

START: MOV SP,4000H ;Setup stack pointer


MOV AL,90H ;Setup control word register
MOV DX,CNT3 ;Setup output port
OUT DX,AL ;Output data

MOV AL,0FFH ;Setup output data


MOV DX,BPORT3 ;Setup output port
OUT DX,AL ;Output data to portB
HLT
CODE ENDS
END START
Note: ( In Assembly Language ; semicolon is used to write comments in
program)
STEP.2: Save program with the extension of .asm (E.g LED.asm) in MTS-
86C\Assembly folder
Note: by default in notepad file type is “Text Document” which makes file
name ultimately as text file (e.g LED.asm.txt), so change it to “All Files”.

STEP.3: Open Command prompt and write following command to make HEX
file:
C:\MTS-86C\Assembly>V LED

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 39


Note: DO NOT Enter [V LED.asm], this may damage your assemble code.
After writing this command LST, OBJ and BIN files will be generated.
STEP.4: Then type [LED.bin] and press Enter twice, the HEX file
[LED.HEX] will be generated from OBJ and BIN files automatically in the
same folder where the assembly code located.
This can be seen in command prompt as shown below in fig(a).

STEP.5: After this Open Hyper terminal by using this path Start>All
Programs>Accessories>communication>HyperTerminal>Hyper Terminal As
shown in fig(b).

STEP.6: Then type MTS-86C in Connection description window as shown in


fig(c).

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 40


STEP.6: BY pressing Ok connect to window will open then select COMM1
connection and Press OK.as shown in fig(d).

STEP.7:Select speed of 19200 Bits Per second and Flow control Xon/Xoff and
press OK.as shown in fig(e).

STEP.8:Press Reset on MTS-86C and Press any key from A to F.IF your
connection is estabilished successfully then you will see the window like this
as shown in fig (f).

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 41


STEP.9:Then write [L 0200].After this you will have to send the HEX file that
you already created.as shown in fig(g).

STEP.10:Then type [G= 0200:0] and press enter and then click Y from the key
board of the computer.

RESULT: You will see the result that all the LED’s are light up on the MTS-
86C.

Discussion:
If you want to light up any pattern of LED’s on the MTS-86C then you will
have to change the assembly language code as shown in fig(i).

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 42


By using this code the Led Pattern will like this 11101110 .Where 1 mean the
LED is on and 0 mean the LED is off.i.e, 0 and 4 LED will not open using the
code of fig(i).

[Microprocessor Based Systems (CPE-312) Lab Manual] Page 43

You might also like