8086 Microprocessor Lab Environments 8086 Programming by Ravinder Nath Rajotiya - February 21, 2022February 21, 20220 Share on Facebook Share Send email Mail Print Print Table of Contents Toggle Different ways to write 8086 Assembly ProgramMPI Trainer Kit:2. Use of Assembler:3. DEBUG Utility:Lab-2Using DebugDebug ‘R’ command,Assemble: Use the command ‘a’.Trace: Use the command ‘t’.Un-assemble: use debug ‘u’ Different ways to write 8086 Assembly Program Introduction The MPI Lab experiments can be performed using the microprocessor trainer kit or it can be performed using a PC installed with one of the different assembler available like MASM611, NASM, TASM and so on. It all depends on the instructor/faculty which one they prefer. The advantage with the trainer kit is that you can view the different ICs and other components on the kit, you can manually set certain settings using different jumpers/links on the motherboard and feel the concept of low level programming. You are required to first write the program on a coding sheet or notebook, then manually assemble it referring the mnemonic/hex code table and substituting the address all manually with paper and pencil. You then prepare your trainer kit and feed those hex codes in the trainer kit. Though, this gives you an insight of the machine and the machine language, many instructor prefer performing the assembly programs on a PC installed with any assembler. The use of Assembler such as MASM611, NASM, TASM etc. makes the program quite easy, as we are not required to do the assembly of the program manually. We only need to remember the instructions in the form of mnemonics which are easy to remember as compared to hex/binary codes of the instructions. There is no requirement of knowing the physical address where the program is to be loaded in the RAM, the assembler will do it for you. Another method for performing the assembly program is to use the DOS utility is DEBUG. In the following paragraph we describe all the three methods discussed above for performing the MPI Lab programs. MPI Trainer Kit: Though working with the trainer kit is little harder, to keep the discussion / understanding simpler, some of the hardware details will skipped for now and will be taken up later. We use the XPO-86 MPI Trainer kit manufactured by Anshuman Tech Pvt. Ltd, because of its availability in our lab, though the procedure on other brand is more or less similar. To perform program on MPI trainer kit, we follow four step: Writing the assembly program on the coding sheet along with the hex code and the physical Feed the hex codes at the physical address in the trainer kit RAM/scratch pad. The procedure is : Turn on the trainer kit (Ensure Keyboard is connected at the PC-AT connecter at the back) Type S to enter the program (trainer will display SUBSTUT?) Press ENTER, trainer will display MEMORY Press ENTER, trainer will display SRC-SEGR Write the starting address as 0000 Press ENTER, trainer will display ADDR Write the offset address as 1000 Now as you press ENTER you may notice some code at these address; just key in the new byte hex code of the instruction of your program and press enter, you will get the next address for keying the next hex code byte and so on until you feed the last byte of your Next Step is the execution of the program: After you have keyed in all the hex bytes of the program proceed as follows: Press ESCAPE to return to command prompt Type G GOTO? Appears on the display. Press ENTER; Burst mode appears on the display as BURST Press ENTER, trainer will display SRC-SEGR Type 0000 (starting address you used while feeding the program) and press ENTER. ADDR appears on the display type offset address here as 1000 and press ENTER. The program gets executed at one go. The last step is viewing the data and/or result. The data /result can be at one of the three places i.e. memory, i/o or register. The mode can be selected by using any key other than ESC and ENTER(CR). To view the result of the program after it has been executed proceed as follows: Press S and SUBSTUT? Appears on the display Press ENTER, the first mode MEMORY appears on display, if you wish to view the result/data from memory press SRC-SEGR appears on display, type the SRC address of memory where you expect the data and press ENTER. ADDR appears on the display, type the offset address of data/result and press OR press any key other than ESC and ENTER (CR) the next mode INPUT/ OUTPUT appears on display, to get/show data press ENTER and the trainer kit will ask for the port address of i/o. OR still press any key other than ESC and ENTER (CR) the next mode REGISTER_ appears on the display, Press ENTER, a blinking cursor (Hiphen) will appear, you can type the name of the register (AX, BX etc) and the trainer kit will show the value of the specified register. We can continue watching the content of other registers in the similar way. If you press ENTER without specifying the register name, it will display the content of register 2. Use of Assembler: The second method is facilitated by the use of a system software called Assembler. An assembler is a special program installed on a personal computer. It allows us to write the program in symbolic notation so called as mnemonic or assembly language instructions. The assembler, in turn, generates the equivalent machine code of the assembly language program. The process consist of four steps: Editing/ Writing: We can enter the assembly language program in any editor or notepad. Remember to save the program with the .asm Assembling the program: We use the assembler program to convert our assembly language program into machine code. It also assign the logical addresses to each instruction. In doing so, the assembler starts by checking the syntax, validity of the structure of the assembly instruction in the program. Before converting the program into machine code errors if any are reported. If the program is free from any error only then the obj file is created. We use the following command to assemble the E.g. MASM myFirstPrg.asm and press ENTER. This step produces object file (myFirstPrg.obj). Linking of program: Linker is also a system software used to convert the object file into the executable (.EXE) file. Different linkers are LINK (part of MASM s/w), TLINK (part of TASM s/w), NLINK(part of NASM s/w). The .EXE file is self contained and re-locatable. An object file may represent one segment of a long program and thus cannot operate by itself, and must be integrated with other object files of the program in order to produce the final self-contained executable file. With MASM611 we can link the object files using LINK command or ML command as: LINK myFirstPrg.obj…………………… and press ENTER. There may be more than one file name on this line. This will produce myFirstPrg.EXE file. It also produces some other files such as MAP file which contain information about different segments. Executing the Program: This is the last step. You just type the name of the .EXE file and press ENTER. By doing so another program known as LOADER comes into picture. Loader loads the executable in the RAM of your machine. The microprocessor executes the program and gives the desired result. Step b and c can be performed in MASM611 using a single command i.e. ML (ml) command as follows: ML /Fl /Zi myprg.asm This will generate the .lst and .exe file 3. DEBUG Utility: This is a DOS utility. It is used to find logical errors in the program. Even if the program does not contain any errors, it may not produce desired results on execution. These errors are found by tracing the execution of the program. Once the logical errors are detected the source assembly program may be re-edited to fix the error, reassembled, re-linked. Debug commands are summarized below: Lab-2 DOS DEBUG Utility This is a DOS utility. It is used to find logical errors in the program. Even if the program does not contain any errors, it may not produce desired results on execution. These errors are found by tracing the execution of the program. Once the logical errors are detected the source assembly program may be re-edited to fix the error, reassembled, re-linked. The “Debug” program is part of MS-DOS hence available on every DOS/Windows machine. It is simple to use but offer limited capabilities for complex assembly programs. The different commands of the DOS- DEBUG are summarized below: C:\debug This is the debug prompt, Type ? to get debug help -? Command Syntax Assemble A [address] Compare C range address Dump D [range] Enter E address [list] Fill F range list Go G [=address] [addresses] Hex H value1 value2 Input I port Load L [address] [drive] [firstsector] [number] Move M range address Name N [pathname] [arglist] Output O port byte Proceed P [=address] [number] Quit Q Register R [register] Search S range list Trace T [=address] [value] Unassembled U [range] Write W [address] [drive] [firstsector] [number] allocate expanded memory XA [#pages] deallocate expanded memory XD [handle] map expanded memory pages XM [Lpage] [Ppage] [handle] display expanded memory status XS Using Debug Debug ‘R’ command, To display the contents of all registers: Use ‘R’ at debug Figure shows all the registers of 8086. The 09 flags of the 8086 shown above are explained below: Symbol Meaning NV / OV No Overflow / Overflow UP / DN Direction normal / direction reverse EI / DI Enable Interrupt / Disable Interrupt PL / NG Positive / Negative NZ / ZR Non zero / Zero NA / AC No Aux. carry / Aux. Carry PO / PE Parity Odd / Parity Even NC / CY No Carry / Carry Assemble: Use the command ‘a’. The debug will prompt CS : IP address, you can type your assembly instructions here, an ENTER will prompt next correct CS:IP address automatically. To end the assembly we press ENTER Trace: Use the command ‘t’. To execute in a single step, i.e. one instruction at a time. Type T at the debug prompt ( – ), an instruction will execute and the result can be seen in all different registers. It is clearly seen that a program is written at the CS:IP which is displayed after issue of ‘a’ command. The program consist of three instructions starting at address 1377:010C to 1377:0110. The program is executed by the ‘t’ command, on issue of each t command the content of registers can be seen. The flags are also seen to be changing. Un-assemble: use debug ‘u’ This command is used to unassembled an assembly program Program to add two ascii numbers ‘5’ and ‘7’.On issuing the ‘u’ command, the assembly instructions are unassembled and their machine(hex) code are generated as seen after the CS:IP address. Assembly program written using DEBUG utility Software Assignments for Microprocessor Trainer Kit: In this program we have copied the ascii code of number 5 as 35h into register AL. Next is ADD AL, 37. The addition of 35h and 37h results in 6C which of correct hex addition of 35 and 37 but is not the correct result of addition of number 5 and 7. Thus we need to give the next instruction as AAA i.e. ascii adjust after addition. After execution of instruction AAA we get the correct unpacked result in AH (01) and AL (02). Write a program to sum numbers from 1 to 10. The program must be stored at address starting from 15A1:0100 and the result be stored at memory location 0000:1000h. Solution: Turn ON the trainer Kit, you will see the ANSHUMAN_ on the display, the system is ready to accept the commands from you. Type S and you will see SUBSTUT? on screen. Press ENTER (CR), now you will see word MEMORY on display Press ENTER (CR), and the system will ask you SRC-SEGR (segment:offset) Type 15A1 and ENTER(CR), at ADDR type 0100 and press ENTER (CR). Now the system is ready, Enter the hex code bytes of the assembly statements, as you press enter after every hex byte codes, next SEG:offset address will Assembly program written using DEBUG utility Executing the Program: Above figure shows the complete program, On kit you may only input hex codes shown on the left side of figure. After inputting the complete program: Type G, GOTO? Will appear on display, press ENTER BURST appear on display, press ENTER (CR). SRC-SEGR appears on display, Type 15A1 and press ENTER (CR) ADDR appears on display, type 0100 and press System displays WAIT for a moment and the displays COMMAND=_, It means program has executed successfully To see the result: At COMMAND= prompt type S SUBSTUT? Appears on display. Press ENTER (CR). The word MEMORY appears on display. Since the result is in memory at 0000:1000h, press ENTER (CR). SRC-SEGR appears on display, type 0000 and ENTER (CR) At ADDR type 1000 and enter You get the result for the above program (addition of 1 – 10) as 37 (in hex) which = 55 in decimal. Share on Facebook Share Send email Mail Print Print