Documente Academic
Documente Profesional
Documente Cultură
Course Objective:
To become skilled in 8086 Assembly Language programming.
To understand programmable peripheral devices and their Interfacing.
To understand and learn 8051 microcontroller.
To learn 8051 assembly Language programming
Learning Outcome:
Able to write8086 Assembly Language programs.
Able to understand programmable peripheral devices and their Interfacing.
Able to write 8051 assembly Language programs.
There are two ways to execute 8086 programs using a computer. One is using the DOS
tool called DEBUG and the second way is using the Assembler TASM / MASM. Hence both the
ways are to be learned.
1. DEBUG
The DOS utility called DEBUG allows entering assembly language programs, to execute
these programs, to view memory locations and also to trace the program execution.
DEBUG Commands
The commands which are required to run / enter the programs are the following.
A Assemble
D Display / Dump
E Enter data
F Fill memory
G Run the program
L Load
N Name a program
P Proceed
Q Quit
R Register
T Trace
U Un Assemble
W Write
The DEBUG does not detect errors until Enter key is pressed. If there is any syntax
mistake then the command line is redisplayed with the word error added at the point at which the
error was detected. If a command line contains more than one error, only the first error will be
detected and indicated and execution will stop at that point.
This command displays the content of a block of memory locations. The syntax for the
command is
D address1 address2
Address1 is the starting address of the memory block and address2 is the ending address.
When the ending address is not specified then from the starting address the contents of 128
locations will be displayed. The display consists of both HEX and ASCII formats. In each line 16
HEX / ASCII numbers will be displayed.
= Start is an optional starting address of the program and break1, break2.. ... are the break
point addresses. If the start address is not specified then the execution starts from the current
value of Instruction Pointer. First time when DEBUG is loaded with a COM program IP is set to
100. So to execute the COM program simply type the command G.
N filename
Ex: N test1.com
R register
Register is the optional name of the register to modify the any of the AX, BX, CX, DX,
SP, BP, SI, DI, DS, ES, SS, CS, IP or F. If the command is given without any parameter then
DEBUG displays the contents of all the registers. If a particular register is specified then
DEBUG displays the content of that register and allows us to change the content.
T = start count
Start is the beginning address and count is the number of instructions to trace, both these
parameters are optional. If the start is not specified then execution will begin with the current
address stored in IP. If the count is excluded then only one instruction will be executed.
U range
Range is an optional when it is used start and end address should be given separated by a
space. If the range is not specified then DEBUG displays the instructions starting from the
current contents of the IP or with the byte following the last byte displayed by the most recent U
command. When range is not specified 16 bytes will decoded and displayed.
The program from the location CS: 0100 is stored. Before using this command the
register CX should be initialized with approximate number of bytes of the program using the R
command.
Example 1.1: Let us assemble a small program and execute the same using the commands
mentioned above.
The program is to add the contents of the registers AX, BX and CX. The program is
In the above program all the numbers are hex numbers only. The INT 20 instruction is a
DOS break point instruction it will display a message Program Terminated Normally when it is
executed.
Type Debug from the DOS prompt to load DEBUG
C :> Debug
-
Observe the DEBUG prompt -. It indicates DEBUG is loaded and it is ready to accept
any DEBUG commands. Now use the Assemble command A and type the instruction by
instruction of the above program and press enter to come out from assembly mode.
-a 100
108F:0100 MOV AX, 1122
108F:0103 MOV BX, 0011
108F:0106 MOV CX, 1133
108F:0109 ADD AX, BX
108F:010B ADD BX, CX
108F:010D MOV [200], AX
108F:0110 INT 20
108F:0112
-
In the above display 108F is the CS content and 0100 is the starting offset address of the
program. The CS is initialized by the operating system so from computer to computer and from
program to program also it may change. Hence offset address is to be used for any reference.
After typing a line the offset address is automatically updated by the number of bytes required
for that instruction. Without typing any instruction simply by typing enters the assembly mode
terminates.
Now let us store this program on hard disk with the file name TEST1.COM. The
commands are
-r cx
CX 0000
: 0f
-
The previous contents of CX are 0000 and it is changed to 0F. (0F is approximate length
of the program in bytes). The next command is required for assigning the filename.
-N TEST1.ASM
Next to store the program use Write command and observe the display.
-W
After giving this command a message will be displayed indicating the number of bytes
written. Now if required quit the DEBUG using the command Q and check the directory for the
filename TEST1.COM. This step is not compulsory. Now Let us reload DEBUG with
After the INT 20 instruction it is the previous program or some random instructions
stored.
Now to execute the program use the Go command
-g
The result is 1133. Observe the ASCII equivalent for 33 is 3 and 11 is not a text character
so just dot is displayed.
-p
2. MASM / TASM
MASM / TASM is an assembler converts the assembly program to machine code. While
writing the program labels can be used so that there is no need to calculate the addresses as in
case of DEBUG. The program can be just entered in the same way as we write. The machine
code generated by the assembler will not be in the format ready for execution. The memory
specifications will not be there. For this Linker software is required. The linker software
substitutes all the required memory values and makes the machine program ready for execution.
The input file given to the assembler should be .ASM. It can be created by any text
editors. The assembler converts this .ASM file to .OBJ file when the given program is syntax
error free. This OBJ file is converted into .EXE by using the Linker software. The machine
program thus generated can be executed by using DEBUG. If the results are stored in memory
then DEBUG is compulsory to execute the program. If the results are to be displayed on CRT
then the program can be directly executed just by typing the name of the EXE program at the
DOS prompt.
In addition to the mnemonics used in a program we can write some instructions to the
compiler also. These instructions are called Assembler Directives. Assembler directives are not
converted into machine language.
In the above program comments are written after the semicolon ;. The first dot
command instructs the assembler about the total memory i.e. code + data segments. The
following table specifies the different memory models.
Memory Model Meaning
Small Program code must fit within a single 64kb segment and program data must fit
within a separate 64Kb segment. Both code and data are near
.STACK 100h defines the stack with 256 locations. However in this program stack instructions
are not used.
.DATA defines all the program data variables or constants along with their data types and their
initial values. In the example program m1 is defined as an array of bytes. The db is called data
definition directive. The other data definition directives are
DB 1byte
DW one word (2 bytes)
DD one double word (4bytes)
While tying the initial value type the last digit h for hex number, o for octal and b for
binary. If no letter is specified then it is assumed that the number is decimal. Whenever hex
number starts with an alphabet i.e. A, B...F then add 0 at the beginning of the number to
differentiate the number from a variable.
To enter an array of numbers just type the numbers separated by comma ,. In case the
data is a single ASCII character then type the character within single quotes. In case if the data is
a string type the string with in double quotes.
In the above program $ symbol is used as last character of the string because the DOS
service routine (no 9) will display the characters up to $.
The number 50 is stored in the variable COUNT. In the main program the COUNT word
is substituted with 50 at the time of compiling.
When the initial data is not known then ? can be used just to create a memory location
without initial value.
The ARRAY1 is created with ten locations and each location is initialized with the value
55. Just to create an array ? can be used along with DUP directive.
After initializing the data segment then to enter the program .CODE segment directive
can be used. Once the .CODE starts it indicates the end of the previous segment and the
beginning of the CODE segment.
In the CODE segment, initialization of data segment register DS is compulsory. The first
two instructions will do this. After this the actual program can be typed. Whenever comments are
required they can be given after typing semicolon.
To end the program i.e. to transfer the control to DOS the service 4Ch should be used for
EXE programs. INT 21H is a DOS service and the actual service number should be stored in the
register AH. HLT should not be used it will force the system to halt then it is required to
RESTART the computer.
The OFFSET directive the example program loads the starting address of the array not
the starting data.
The END directive indicates the physical end of the program. The program written after
END will not be compiled.
After typing the program in an assembler store this program as say prog1.asm. At the
DOS prompt type TASM or MASM prog1.asm. This command activates the assembler and an
object code file is created with same name and extension as .OBJ. The OBJ file will not be
created in case of any errors. Errors should be corrected by looking at appropriate messages.
To convert the .OBJ file to .EXE file type the command TINK prog1.obj at DOS prompt.
To execute this EXE file it should be loaded into DEBUG. However like in example
program the result is displayed on the screen so it can be directly executed just by typing the
name of the file at the DOS prompt itself. The program will display the message Hello
Welcome to Assembly Language on the screen.