Professional Documents
Culture Documents
Wsu Microprocessors Lab
Wsu Microprocessors Lab
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.
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.
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
Press ENTER
D :\> CD MASM
Press ENTER
D: \MASM> EDIT
Press ENTER
OPR1 = 4269H
OPR2 = 1000H
RES = 5269H
RESULT:
INPUT:
OUTPUT:
OPR1 = 4269H
OPR2 = 1000H
RES = 3269H
MOV AX,OPR1
DIV OPR2
MOV RESQ,AL
MOV RESR,AH
MOV AH,4CH
INT 21H
CODE ENDS
END START
END
RESULT:
INPUT:
OUTPUT:
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)
RESULT:
For Right,
INPUT:
OUTPUT:
OPR1 = 1639H
RES =
For Left,
NEXT: INC SI
DEC CX
JNZ UP
MOV RES,BL
INT 3
CODE ENDS
END START
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