Lab Workbook of Microprocessor For Students
Lab Workbook of Microprocessor For Students
Lab Workbook of Microprocessor For Students
PROGRAMMING
8086 MICROPROCESSOR:
REGISTER SET
c. Instruction Pointer:
d. FLAG Register:
c. Instruction Pointer:
d. FLAG Register:
iAPX88 ARCHITECTURE:
a. Description:
INTRODUCTION:
NOTEPAD AS AN EDITOR:
NASM:
AFD:
THEORY:
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
INSTRUCTION GROUPS
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
cmp ax, 0
jne 1234
INSTRUCTION ENCODING
1. Instruction defined by Opcode and Operands
2. Decoded by examining bit patterns
3. If operands used, must specify addresses
Examples:
One-address instruction:
Opcode Address
TASK(S):
INSTRUCTION OPCODE
a. ADD:
b. JNZ
c. MOV
d. JNE
e. SUB
f. CMP
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
TASK(S):
Note: Use a separate sheet to answer the following questions:
THEORY:
MOVE 5 TO AX
MOVE 10 TO BX
ADD BX TO AX
MOVE 15 TO BX
Conversion
Note: the general format of instructions is operation destination, source
MOV AX,5
MOV BX,10
ADD AX,BX
MOV BX,15
STEP.4: Write the following command in command prompt to view listing file
C:\NASM>edit prog1.lst
TASK(S):
1. Write down the code which is produced in listing file by assembler (Use
separate sheet). Describe each column in listing file.
4. Observe and write the changes are being made in IP register and other
registers during the execution of program line by line.
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
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.
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.
[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
[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
OBJECT: Writing a program to add ten numbers using loop and register +
offset addressing.
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
THEORY: Open the link mentioned above. And following information will be
displayed. Follow the instructions provided via the above link.
TASK(S):
1. Print the interface view of DOSBOX 0.74 and paste it here.
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.
.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
.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
INTRODUCTION:
FUNCTIONS IN MASM:
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
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
.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
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,'*'
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
MOV CL,OP1
MOV DL,23
ADD DL,CL
SUB DL,OP2
NOT DL
XOR
DL,[OP1+1]
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):
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
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
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.
TOOLS:
MTS-86C Microprocessor Trainer
Theory:
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.
CODE SEGMENT
ASSUME CS:CODE,DS:CODE
ORG 0
STEP.3: Open Command prompt and write following command to make HEX
file:
C:\MTS-86C\Assembly>V LED
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.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).
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).