Está en la página 1de 14

MICROPROCESSORS

LAB MANUAL
1. INTRODUCTION TO 8086, MASM
This chapter is intended to serve as an introduction to the programming and some
features of 8086 microprocessor. The users are requested to read 8086 architecture and
organization of 8086 for better understanding.
The 8086 programming model includes general purpose registers, segment registers, flag
register, base and pointer registers whose functions are briefly given below
SEGMENT REGISTERS:
Code segment register CS stores the base address of code segment.
Stack segment register SS stores the base address of the stack.
Data segment register DS stores the base address of the data.
Extra segment register ES stores the base address of the extra segment.
INDEX REGISTERS:
Source index register SI stores the base address of the source data.
Destination index register DI stores the base address of the destination data.
POINTER REGISTERS:
Instruction pointer IP stores the address of next instruction.
Stack pointer SP stores the address at the top of the stack.
Base pointer BP stores the base address.
GENERAL PURPOSE REGISTERS:
Accumulator AX used in all arithmetic instructions.
Base register BX used to store base addresses while programming.
Counter register CX used as counter during programming.
Destination register DX - used to store base addresses while programming.
Extended accumulator DX: AX used in some arithmetic instructions.
All these 16 bit registers can also be used as a pair of 2 8-bit registers.
FLAG REGISTER:
The flag register in 8086 is of 16 bit wide in which only 9 bits are used as flags and the other bits
are in dont care condition. For complete flag format the users are requested to refer to the books,
here only the functions of each flags are briefly given in order to be helpful while programming.
A flag is a flip-flop, which is set or reset after an operation according to the data
conditions of the result in the accumulator and other registers.
Dept Of ECEG, Wolaita Sodo University Page 1

1.
2.
3.
4.
5.

6.
7.
8.
9.

Zero flag Z: The flag is set to 1 when the result is zero, otherwise it is reset.
Carry flag (barrow) CY: If an arithmetic operation results in a carry, the CY
flag is set, otherwise it is reset.
Sign flag S: The sign flag is set if the MSB bit of the result is one, otherwise
it is reset.
Parity flag P : If the result has an even number of 1s, the flag is set, for odd
number of 1s the flag is reset.
Direction flag D: This flag selects increment or decrement mode for the DI and/or SI
registers during string instructions. If D=1, the registers are automatically decremented; if
D=0, the registers are automatically incremented.
Overflow flag O: Overflow occurs when signed numbers are added or subtracted. An
overflow indicates that the result has exceeded the capacity of the machine.
Trap flag T: The trap flag enables trapping through an on chip debugging feature.
Interrupt flag I: The interrupt flag controls the operation of INTR input pin. If I=1
INTR is enabled otherwise it is disabled.
Auxiliary carry flag AC: The auxiliary carry holds the carry( half carry) after addition
or barrow after subtraction between bit positions 3 and 4 of the result. This bit is tested in
special instructions like DAA and DAS.

INSTRUCTION SET OF 8086


An instruction is a command to the microprocessor to perform a given task on specified
data. Each instruction has two parts: one is task to be performed, called the operation code
(opcode) and the second is the data to be operated on, called the operand. The entire group of
instructions, called the instruction set, determines what function the microprocessor can perform.
The 8086 instructions can be classified into following categories depending on their
functions.
DATA TRANSFER INSTRUCTIONS:
This group of instructions copies the data from a location called source to another
location called destination, without modifying the contents of the source. The one more specialty
of this group is they will not effect any of the flags in the flag register. The data transfer may be
between registers, memory location and a register, immediate data and memory or register and
between I/O device and the accumulator.
ARITHMETIC INSTRUCTIONS:
These instructions perform arithmetic operations such as addition, subtraction, increment
and decrement. The flags are affected by this group of instructions depending on the results they
produce but some special instructions will not effect flags.
LOGICAL, SHIFTOR ROTATE INSTRUCTIONS:
Dept Of ECEG, Wolaita Sodo University Page 2

These instructions perform various logical operations such as AND, OR, NOT, compare
etc. These instructions will also affect flags.
BRANCHING INSTRUCTIONS:
This group of instructions alters the sequence of program execution either conditionally
or unconditionally. Flags are generally used to generate conditions in case of 1st type of branch
instructions.
MACHINE CONTROL INSTRUCTIONS:
These instructions control machine functions such as halt, interrupt and do nothing etc.
STRING INSTRUCTIONS:
These instructions special and serve the purpose of operations on strings.

MASM (Macro Assembler)


EDITOR
An editor is a program, which allows you to create a file containing the assembly language
statements for your program. As you type in your program, the editor stores the ASCII codes for
the letters and numbers in successive RAM locations. When you have typed in all of your
programs, you then save the file on a floppy of hard disk. This file is called source file. The next
step is to process the source file with an assembler. In the MASM assembler, you should give
your source file name the extension, .ASM
ASSEMBLER
An assembler program is used to translate the assembly language mnemonics for instructions to
the corresponding binary codes. When you run the assembler, it reads the source file of your
program the disk, where you saved it after editing on the first pass through the source program
the assembler determines the displacement of named data items, the offset of labels and puts this
information in a symbol table. On the second pass through the source program, the assembler
produces the binary code for each instruction and inserts the offset etc that is calculated during
the first pass. The assembler generates two files on floppy or hard disk. The first file called the
object file is given the extension. OBJ. The object file contains the binary codes for the
instructions and information about the addresses of the instructions. The second file generated by
the assembler is called assembler list file. The list file contains your assembly language
statements, the binary codes for each instructions and the offset for each instruction. In MASM
assembler, MASM source file name ASM is used to assemble the file. Edit source file name LST
is used to view the list file, which is generated, when you assemble the file.

Dept Of ECEG, Wolaita Sodo University Page 3

LINKER
A linker is a program used to join several object files into one large object file and convert to an
exe file. The linker produces a link file, which contains the binary codes for all the combined
modules. The linker however doesnt assign absolute addresses to the program, it assigns is said
to be relocatable because it can be put anywhere in memory to be run. In MASM, MLINK
source filename is used to link the file.
DEBUGGER
A debugger is a program which allows you to load your object code program into system
memory, execute the program and troubleshoot are debug it the debugger allows you to look at
the contents of registers and memory locations after your program runs. It allows you to change
the contents of register and memory locations after your program runs. It allows you to change
the contents of register and memory locations and return the program. A debugger also allows
you to set a break point at any point in the program. If you inset a breakpoint the debugger will
run the program up to the instruction where the breakpoint is set and stop execution. You can
then examine register and memory contents to see whether the results are correct at that point. In
MASM, the filename is used to debug the file.
DEBUGGER FUNCTIONS:
1. Debugger allows to look at the contents of registers and memory locations.
2. We can extend 8-bit register to 16-bit register which the help of extended register option.
3. Debugger allows setting breakpoints at any point with the program.
4. The debugger will run the program up to the instruction where the breakpoint is set and then
stop execution of program. At this point, we can examine registry and memory contents at that
point.
COMMANDS TO EXECUTE A GIVEN ALP.
ASSMEBLINIG
:
masm <file name.asm> <Enter>
LINKING
:
link <file name.obj> <Enter>
DEBUGGING
:
debug <file name.exe> <Enter>
Procedure of Masm:
Start

Run

Type CMD

Ok
Display shows

C :\> D:
(Change to D drive because MASM is in D drive)
Dept Of ECEG, Wolaita Sodo University Page 4

(if it is in D drive otherwise no change. Simply C: drive)

Press ENTER

D :\> CD MASM

Press ENTER

D: \MASM> EDIT

Press ENTER

Create A file name with .asm extension Ex: Filename.asm

Write the program in assemble language then Save and Quit


It returns to DOS Prompt

Use the following Commands

D: \MASM> masm filename.asm


It is for viewing errors and warnings report exist in the asm file (refer Assembler)

D: \MASM> link filename.obj


The assembler produces an object file that has the same name as the original file but with the
obj extension

D: \MASM> debug filename.exe


It is for viewing the output window

Click Run and Click View


It shows the output for Corresponding Inputs
Commands:
-u (display the program)
-g (entire program is executed at a time)
-p (instructions are executed one by one)
-q (quit the program)

Dept Of ECEG, Wolaita Sodo University Page 5

1. ADDITION OF TWO 16-BIT NUMBER


AIM: To write an assembly language program to perform addition of two 16-bit numbers.
PROGRAM:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
OPR1 DW 4269H
OPR2 DW 1000H
RES DW ?
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA
MOV DS,AX
MOV AX,OPR1
ADD AX,OPR2
MOV RES,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START
END
RESULT:
INPUT:
OUTPUT:

OPR1 = 4269H
OPR2 = 1000H
RES = 5269H

2. SUBTRACTION OF TWO 16-BIT NUMBERS


AIM: To write an assembly language program to perform subtraction of two 16-bit
numbers.
PROGRAM:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
OPR1 DW 4269H
OPR2 DW 1000H
RES DW ?
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA
MOV DS,AX
MOV AX,OPR1
SUB AX,OPR2
MOV RES,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START
END
Dept Of ECEG, Wolaita Sodo University Page 6

RESULT:
INPUT:
OUTPUT:

OPR1 = 4269H
OPR2 = 1000H
RES = 3269H

3. MULTIPLICATION OF TWO 16-BIT


AIM: To write an assembly language program to perform multiplication of two 16-bit
Numbers.
PROGRAM:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
OPR1 DW 2000H
OPR2 DW 4000H
RESLW DW ?
RESHW DW ?
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA
MOV DS,AX
MOV AX,OPR1
MUL OPR2
MOV RESLW,AX
MOV RESHW,DX
MOV AH,4CH
INT 21H
CODE ENDS
END START
END
RESULT:
INPUT:
OPR1 = 2000H
OPR2 = 4000H
OUTPUT:
RESLW = 0000H (AX)
RESHW = 0800H (DX)

4. DIVISION OF 16 BIT NUMBER BY 8 BIT NUMBER


AIM: To write an assembly language program to perform division of 16-bit
number by 8-bit number.
PROGRAM:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
OPR1 DW 2C58H
OPR2 DB 56H
RESQ DB ?
RESR DB ?
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA
MOV DS,AX
Dept Of ECEG, Wolaita Sodo University Page 7

MOV AX,OPR1
DIV OPR2
MOV RESQ,AL
MOV RESR,AH
MOV AH,4CH
INT 21H
CODE ENDS
END START
END
RESULT:
INPUT:
OUTPUT:

OPR1 = 2C58H (DIVIDEND)


OPR2 = 56H (DIVISOR)
RESQ = 84H (AL)
RESR = 00H (AH)

5. LOGICAL OPERATIONS
AIM: To write an Assembly language program to perform the Logical AND, OR, and XOR
operations.
PROGRAM:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
OPR1 DW 6493H
OPR2 DW 1936H
RES DW ?
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA
MOV DS,AX
MOV AX,OPR1
AND AX,OPR2
(or) OR AX,OPR2
(or) XOR AX,OPR2
MOV RES,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START
END
RESULT:
INPUT:
OUTPUT:

OPR1 = 6493H
OPR2 = 1936H
RES = 0012H (AND)
RES = 7DB7H (OR)
RES = 7DA5H (XOR)

Dept Of ECEG, Wolaita Sodo University Page 8

6. LOGICAL NOT OPERATION


AIM: To write an Assembly language program to perform the Logical Invert operation.
PROGRAM:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
OPR1 DW 6493H
RES DW ?
DATA ENDS
CODE SEGMENT
START:MOV AX,DATA
MOV DS,AX
MOV AX,OPR1
NOT AX
MOV RES,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START
END
RESULT:
INPUT:
OPR1 = 6493H
OUTPUT:
RES = 9B6CH

7. SHIFT ARITHMETIC / LOGICAL LEFT OPERATION


AIM: To write an Assembly language program to perform the Shift arithmetic / Logical
operation.
PROGRAM:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
OPR1 DW 1639H
RES DW ?
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA
MOV DS,AX
MOV AX,OPR1
SAL AX,01H
(or)
SHL AX,01H
MOV RES,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START
END
RESULT:
INPUT:
OPR1 = 1639H
OUTPUT:
RES = 2C72H

Dept Of ECEG, Wolaita Sodo University Page 9

8. SHIFT LOGICAL RIGHT OPERATION


AIM: To write an Assembly language program to perform the Shift Logical Right operation.
PROGRAM:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
OPR1 DW 8639H
RES DW ?
DATA ENDS
CODE SEGMENT
START:MOV AX,DATA
MOV DS,AX
MOV AX,OPR1
SHR AX,01H
MOV RES,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START
END
RESULT:
INPUT:
OPR1 = 8639H
OUTPUT:
RES = 431CH

9. SHIFT ARITHMETIC RIGHT OPERATION


AIM: To write an Assembly language program to perform the Shift Arithmetic Right operation.
PROGRAM:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
OPR1 DW 8639H
RES DW ?
DATA ENDS
CODE SEGMENT
START:MOV AX,DATA
MOV DS,AX
MOV AX,OPR1
SAR AX,01H
MOV RES,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START
END
RESULT:
INPUT:
OPR1 = 8639H
OUTPUT:
RES = C31CH

Dept Of ECEG, Wolaita Sodo UniversityPage 10

10.ROTATE RIGHT/LEFT WITHOUT CARRY


AIM: To write an Assembly language program to perform the Rotate Right without carry
operation.
PROGRAM:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
OPR1 DW 1639H
RES DW ?
DATA ENDS
CODE SEGMENT
START:MOV AX,DATA
MOV DS,AX
MOV AX,OPR1
ROR AX,01H
(or) ROL AX,01H
MOV RES,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START
END
RESULT:
For right,
INPUT:
OPR1 = 1639H
OUTPUT:
RES =
For left,
INPUT:
OPR1 = 8097H
OUTPUT:
RES =

11.ROTATE RIGHT/LEFT WITH CARRY


AIM: To write an Assembly language program to perform the Rotate Right with carry
operation.
PROGRAM:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
OPR1 DW 1639H
RES DW ?
DATA ENDS
CODE SEGMENT
START:MOV AX,DATA
MOV DS,AX
MOV AX,OPR1
RCR AX,01H
(or) RCL AX,01H
MOV RES,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START
END

Dept Of ECEG, Wolaita Sodo UniversityPage 11

RESULT:
For Right,

INPUT:
OUTPUT:

OPR1 = 1639H
RES =

For Left,

12.FACTORIAL OF A GIVEN NUMBER


AIM: To write an Assembly language program to find out the factorial of a given number
operation.
PROGRAM:
DATA SEGMENT
A DB 3
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START: MOV AX,DATA
MOV DS,AX
MOV AH,00
MOV AL,A
L1:
DEC A
MUL A
MOV CL,A
CMP CL,01
JNZ L1
MOV AH,4CH
INT 21H
CODE ENDS
END START

13.LARGEST OF A GIVEN NUMBER


AIM: To write an Assembly language program to find out the factorial of a given number
operation.
PROGRAM:
DATA SEGMENT
STRING1 DB 08H,14H,05H,0FH,09H
RES DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV CX,04H
MOV BL,00H
LEA SI,STRING1
UP: MOV AL,[SI]
CMP AL,BL
JL NEXT
MOV BL,AL
Dept Of ECEG, Wolaita Sodo UniversityPage 12

NEXT: INC SI
DEC CX
JNZ UP
MOV RES,BL
INT 3
CODE ENDS
END START

14.CHECK WHETHER A GIVEN 16-BIT NUMBER IS EVEN OR ODD


AIM: To write a program to check the given 16 bit number is odd or even
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
NUM1 DW 0008H
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA
MOV DS,AX
MOV AX,NUM1
MOV BX,0002H
MOV CX,0000H
DIV BX
CMP CX,DX
JE EVEN
MOV AX,1111H
JMP NEXT
EVEN: MOV AX,FFFFH
NEXT: INT 03H
CODE ENDS
END START
OBSERVATIONS: (Theoretical)
INPUT: NUM1=0008H
OUTPUT: AX=FFFFH BX=0002H
OBSERVATION: (Practical)
INPUT: NUM1=
OUTPUT: AX= BX=

15.CHECK WHETHER A GIVEN 16-BIT NUMBER IS POSITIVE OR


NEGATIVE
AIM: To write a program to check whether a given 16 bit number is positive or negative.
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
NUM1 DW 0002H
DATA ENDS
Dept Of ECEG, Wolaita Sodo UniversityPage 13

CODE SEGMENT
START: MOV AX,DATA
MOV DS,AX
MOV AX,NUM1
ROL AX,01H
JC NEG_NUM
MOV AX,FFFFH
JMP EXIT
NEG_NUM:MOV AX,1111H
EXIT: INT 3
CODE ENDS
END START
OBSERVATIONS:(Theoretical)
INPUT: NUM1=0008H
OUTPUT: AX=FFFFH
BX=0000H
OBSERVATION: (practical)
INPUT: NUM1=
OUTPUT: AX=
BX=

16.DISPLAYING A STRING
AIM: To write a program to displaying a given string.
PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
STRING DB 'HAPPY NEW YEAR', 0DH, 0AH,'$'
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
LEA DX, STRING
MOV AH, 09H
INT 21H
CODE ENDS
END START
OBSERVATIONS:
INPUT: HAPPY NEW YEAR
OUTPUT: HAPPY NEW YEAR

Dept Of ECEG, Wolaita Sodo UniversityPage 14

También podría gustarte