In this tutorial it is shown how to write 8086 assembly program, how to use embedded software development tool to run the program and save the program in executable format. The program we will be writing is a simple two 16 bit word multiplication stored in memory. The Intel 8086 microprocessor is a 16 bit microprocessor which can still be used for embedded system design for industrial plants.
The assembly program is as follows,
data segment
x dw 40D
y dw 02D
z dw 2 dup(0)
data ends
code segment
ASSUME CS:code,DS:data
start: mov ax,data
mov ds,ax
mov ax,x
mul y
mov z,ax
mov z+2,dx
code ends
end start
In the above code we have used the segments and ends directives to group the data and code parts of the program. The data segment in the first line and data ends groups the data in the code. They are called logical segment. Within this logical segment called data we have declared some data x, y and z. x is the multiplicand and y is the multiplier and z is the product, that is- z = x*y. We have used dw to define the variables x,y and z. x is initialized to 40D which means 40 in decimal, y is initialized to 2D which means 2 in decimal and the z dw 2 dup(0) sets aside memory for 2 words initialized to all zeros.
The code segment with code ends contains the program code. Within it the first line is the assume directive. This assume directive tells assembler that the logical segment called data contains the data and the logical segment called code contains the program code.
Next start is a label which gives an identification for an address. The mov ax,data instruction causes the accumulator register AX to store the starting addressing of the data segment in it. The next instruction mov ds,ax causes the transfer of address stored in accumulator to the DS register. This is required because the DS register is not directly reachable via instructions. Next mov ax,x causes to move the value stored(40D) in memory location x to the accumulator. Then the value stored in memory location y(2D) is multiplied with the contained in the accumulator which is 40D. The result is stored in the accumulator which is 50H(80D). The next instruction mov z,ax moves the result of multiplication from AX register to memory location specified by z. The final instruction mov z+2,dx copies the high word of the multiplication result from DX to memory. When the assembler reads this instruction, it will add the indicated 2 to the displacement it calculated for z and inserts the result as for the binary code for the instruction.
To write an assembly language program and create executable file we need an assembler. To do this we can use emu8086 which is freely available on the internet.
The following is a screenshot which shows the program entered into this 8086 embedded software development tool.
To create the executive file(.exe) we can click on the compile button on the toolbar. Doing this the software ask where to save the .exe file. Choose some folder in your computer and hit ok. Once you have saved it you can run the program.
The software will run the program and stop the execution as shown below.
To check the program(or debug for if you had some problem) we can click on the reload button and then check the program step by step by clicking on the single step button.
The following screenshot shows one of the stepped in view which show the result of the multiplication which is 50H stored in accumulator.
Now you have the program in .exe format which you can use for your 8086 microprocessor based embedded system designs.
This tutorial showed you how to write a simple program to multiply two 16 bit words for 8086 microprocessor. It also showed you how you can use the emu8086 software as your 8086 microprocessor embedded software development tool.
The assembly program is as follows,
data segment
x dw 40D
y dw 02D
z dw 2 dup(0)
data ends
code segment
ASSUME CS:code,DS:data
start: mov ax,data
mov ds,ax
mov ax,x
mul y
mov z,ax
mov z+2,dx
code ends
end start
In the above code we have used the segments and ends directives to group the data and code parts of the program. The data segment in the first line and data ends groups the data in the code. They are called logical segment. Within this logical segment called data we have declared some data x, y and z. x is the multiplicand and y is the multiplier and z is the product, that is- z = x*y. We have used dw to define the variables x,y and z. x is initialized to 40D which means 40 in decimal, y is initialized to 2D which means 2 in decimal and the z dw 2 dup(0) sets aside memory for 2 words initialized to all zeros.
The code segment with code ends contains the program code. Within it the first line is the assume directive. This assume directive tells assembler that the logical segment called data contains the data and the logical segment called code contains the program code.
Next start is a label which gives an identification for an address. The mov ax,data instruction causes the accumulator register AX to store the starting addressing of the data segment in it. The next instruction mov ds,ax causes the transfer of address stored in accumulator to the DS register. This is required because the DS register is not directly reachable via instructions. Next mov ax,x causes to move the value stored(40D) in memory location x to the accumulator. Then the value stored in memory location y(2D) is multiplied with the contained in the accumulator which is 40D. The result is stored in the accumulator which is 50H(80D). The next instruction mov z,ax moves the result of multiplication from AX register to memory location specified by z. The final instruction mov z+2,dx copies the high word of the multiplication result from DX to memory. When the assembler reads this instruction, it will add the indicated 2 to the displacement it calculated for z and inserts the result as for the binary code for the instruction.
To write an assembly language program and create executable file we need an assembler. To do this we can use emu8086 which is freely available on the internet.
The following is a screenshot which shows the program entered into this 8086 embedded software development tool.
To create the executive file(.exe) we can click on the compile button on the toolbar. Doing this the software ask where to save the .exe file. Choose some folder in your computer and hit ok. Once you have saved it you can run the program.
The software will run the program and stop the execution as shown below.
To check the program(or debug for if you had some problem) we can click on the reload button and then check the program step by step by clicking on the single step button.
The following screenshot shows one of the stepped in view which show the result of the multiplication which is 50H stored in accumulator.
Now you have the program in .exe format which you can use for your 8086 microprocessor based embedded system designs.
This tutorial showed you how to write a simple program to multiply two 16 bit words for 8086 microprocessor. It also showed you how you can use the emu8086 software as your 8086 microprocessor embedded software development tool.
0 comments:
Post a Comment