0% found this document useful (0 votes)
14 views133 pages

Microprocessors Douglas V Hall PDF Free

Uploaded by

MITALI SHARMA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
14 views133 pages

Microprocessors Douglas V Hall PDF Free

Uploaded by

MITALI SHARMA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 133
EXPERIMENTS IN MICROPROCESSORS AND INTERFACING PROGRAMMING AND HARDWARE SECOND EDITION DOUGLAS ¥. HALL Maen {ake Forest, ins Columbus, Chio Mission ils, California Peoria, Minos BMC, 18M PCAC. eM POVAT, 18M P8:2, ae MiroChannel Architecture are registered "admarks ol 1M Corprein. Te alwng are regen racersrks oft Corporation: 480, e801, RMI. Borand, Stdekeck,Turoo Assembler, TASM, Turbo Debugger, and Tuba Gr= re ‘aglteredademarks of Boland Iicmatond ine. Maeosot, MS, MS OOS, Windows 3.0, ode. and MASM sre registered rademares of Me-ceah Corpeaton. Other product names are fogatted trademarks of tho companies assorted wits ts product name flere nth tox or Agu. Copyright © 1902 by the Glanece Ohison of MacmitanMeGrau- Hil Shoe! Punishing Company. Copyiget 2 1886 ay McGraw, a. All rights reserves. Except as permed Lncer the Unites States Copyright Act, no part ofthe pubieaion may be reproduced or Se appear in the rightmost digit of the address field eorex 60 | Go lad ast press oe hey and then ne a Brat Manet nex mse dceee | TS] LS | frmbol for ass ha vt segnend nee aes | [pa the syaibol for a BG) dake man ee at cre eet es Proms end dm Sho | TL oe Nawesm | ax [omar note that the symbols for the last four keys — Se ee 2. To prepare the SDK to receive its next command, oner fae Seles -) —— prem they anes sist Rese SSCs. Whenever n dash i dplayed on the tetas cchoearueesr rm ocmmracmmat | TET oy loom | |p With one of the keys on the keypad. Figure 1-1 eld — inex Shows the fnetons of eats af ans PES LD Pale | ow eerntien pes ow | urout 2S | Osta Segment poe Ei ana ‘SDK-36 ww an a a ack SF BJ fmm |e fo fa we] | RIMES a twee a nom | wa s [om ren | | oi eae eee roitarnac eg teres ezem ole pe pee eee uae i — ie ope ciel Seon = Trousers, Lr SES A ee [Tf me fae | aoe foe =] Sasssaretae ti 2 Ay mp wae Loam Stel omen ce . Zien tay seo gr eg Poa recent das, Nox tween rgb Sonar {cis ors arecsn tae 2 epeRweNT (@) Hexadecimal keypad interpretation. Intel Conporation) that many of the kes have several functions, depending upon whether yout are entering a com. mand, entering addresses and data, or examining 8086 registers. The 0 key. for example, is used te enter the EB command ifs dash is showing. It is Used to enter the number 0 if an address or data Word ts being entered. Tt is used to represent the AX register if registers are heing examined, “The SDK-86 keypad monitor program allows you to execute 10 baste commands. Figure 1-2 summarizes the format for these commands. Worle your way through the following sections. which show you how to use some of these commands. The sections are ented by the command name 50 thet you ean find them easily if you need to relresh your memory at some future tie, EXAMINE BYTE (EB! ‘The examine byte command Is used to inspect and, if desired, change the byte stored in a memory location. ‘This command allows you to easily enter program code bytes or data bytes in successive memory Jocatlons. As shown in Figure 1-2, the format for the command is EB addr {data .1*. ‘The letters “EB” tell you to press the Key labeled EB. The “addr” tells you to enler the address of the byte that you want io look at. Pressing the comma after entering the address causes the address and the contents of that address to be displayed. The square ‘brackets and the * shown in the command format are not entered. Command parts contained tn square brackets are optional. The inner square brackets in ‘his command indicate that the data at that address can be changed by simply typing in the desired hex value, The“ indicates that the part of the command contained in the outer square brackets can be repeated. In other words, by pressing the <> key, you can step to the next address, see lls contents, and change them if you want ‘To see the byte in a memory location, press the key labeled EB, enter the address of the desired byte, and onmane Funcinlsyoe xarioe | Dielownodtis memory bse eaters Be | EBcoaie> a teu Blo Examine | Diplayeeditar emery word eens ors jeoear> fear 21a Examine | Ospaye-notes 8085 asi contets ager | ER T] 1°10) trout | Digaye cea aetna part Sym | gl ala Wed | Bicootser>orai to urpur | outputs aye out pot bye porte cea ) A foupar | Duessedaen wont cup ore Word | Gicoertacdr> Sdn a eds>1 902 60 | Tater conta fom monitor ow rosary Boia (a cend ed Ol | Bl crane seer) Q)*D FIGURE 1-2 SDK-86 boare! moniter command summaty. {Intel Cosporaion) then press the <> key. Addresses are entered in the segmentioffset form, and so in order to see the contents of the memory location 000100H (0000:0100), you enter 0:160 as the address. Note that the SDK does not require you to enter leading zeros and does net display them, 4. To see the byte in memory at 0000:01008, enter the following series of Keys: BBO:100, ‘Afier you press the <> key, the contents of add- ress 0000:0100 should appear on the rightmost ‘ovo digits of the data field LEDs, 2, To insert some new byte value at that address, center the hex digits of the new value with the keypad, To enter the value C4H, press the keys ca As you press the Keys, you should see the ew vahie appear on the data field LEDS. If you make a mistake while entering a value. Just {ype in the two correct digits; they will replace the previously entered value 8. To examine the next memory location, press <>. You should now see the address 101 displayed on the address fefd digits, and the byte stored at that location displayed on the right two data field LEDs. To change the contents of this new address, enter another value with the keypad. Press the <> key fagain if you want to examine and/or change the next sequential memory address. '5, To terminate the command alter you have looked fat all the memory locations you Want, prese the <> Key, When the dash prompt ) appears, you can enter your next command, 4. EXAMINE WORD (EW) ‘The examine word command is used to mspect and, sf desired, change a word stored In (we memory loca- Uons. AS shown in Figure 1-2. the format for the ‘command is EW addr. {[datal.1* ‘The operation of BW is identical to that of the EB command deseribed in the preceding paragraphs, except that a data word (16 bits) will be displayed on the four data field LEDs. The right two digits of the displayed word represent the byte contained in memory at the address specified in the command, The high byte of the word, displayed on the upper two data fleld LEDs. represents the byte contained in the memory location after the address specified im the ‘command, 1. Examine the word contained in addresses (0000-0100 and 0000:0101 by pressing the keys EW0:100, You should see the byte from 0000:0100% displayed on the right evo data field LEDs and the INTRODUCTION TO THE SOK-85 MICROPROCESSOR DEVELOPMENT BOARD 3 byte from address 0000:0201 displayed on the left ‘vo LEDs, 2, Change the displayed word by entering the desired ord. Press the <> key to step to the next word in memory. 3. Write down the value you see for this word, Then press the <> Key to get the dash prompt back, so that you can enter another command. 4. Use the EB command to verify that the low byte of the displayed word came from the low address (0000:0100) and the high byte of the word came from the higher address (0000-0101). This relax ‘Gonship is very important to remetber, EXAMINE REGISTER (ER) To display the contents of an 8086 register, press the key and then the key that contains the letter Initials for that register. 1, Examine the contents of the AX register by pressing the keys BRAK Notice that the key is also the key. The address field of the display will show the letter A ‘to maleate the register that is being displayed, and ‘the data fled will show the word contained i the AX register, 2, Examine the contents of the next 8086 register by pressing the <> key. Each tlme you press the <.> ‘key, the SDK will display the next register in the sequence AX, BX, CX, DX, SP, BP, Sh. DI, OS, DS. $8, BS. IP, FL. FL ts the flag register. In each case the address field will show one or two mnemonie letters to indicate which register Is being displayed. 3, To change the word in any register, enter the four hex digits for the word you want in the register. ‘Then press the <> key to step to the next register. or press the <> key to get the dash prompt back ‘0 that you can enter your next command, NOTE: ‘The ER command operation is not circular, so if you want to loole at a register earlier In the sequence, press the <> key to terminate the command, Then press the key to start the command again and then press. the key that has the name of the register you ‘want 10 see. co ‘The SDK-86 GO command allows you to run programs which you have previously loaded into RAM. Remember, you can load programs, into RAM starting at address 0000:0100H. The format for the ‘command 1s| GO [addr } |, breakpoint addr! ‘The first address spectiied in the command is the Program address at which you want execution to 4. expentwenT a start. The breakpoint address specified in the command is the program address at which you want execution to stop. Whenever you run a program on a microcomputer, you must I some way prevent the processor from fetching and attempting to execute random bytes stored tn memory after your program. One way to solve this problem is te put a jump instruction as the last instruction in the program to make the program execute over and over again in an ‘endless loop, For programs that you don’t want to execute over land over, you can put & breakpoint after the last program instruction. When the 8086 reaches the breakpoint, tt will save the values that were in the £8086 registers afer the last program instrietion was executed and retum control to the SDK-86 monitor program. You can then use the EB or EW command to look at any program results in memory. You can use the ER command to look at any program results sn registers. Using the SDK-86 Commands io Load and Exectite a Program igure 1-8 shows a simple program that you can enter into the RAM on your SDK and run for practice. When run, this prograin causes the SDK to display ‘4-digit hexadecimal count sequence en the data fleld LEDs. The program keeps counting from QO00H to EFFFH, Don't worry tf you haven't the foggiest nation hhow the program works at this point. You can learn to drive a car without knowing how the camshaft opens the valves, To load and run the program in Figure 1-3, follow these instructions. 12. Look at the first coluran from the left in Figure 1- 3 to find the addresses for the code you will be loading into RAM. The addresses shown in the program listing are relative. This means that they show where the bytes for each instruction are relative to the starting address at which you load the program into RAM. You want to load the program starting at address 0000:0100H, and $0 you add 10014 to each of the addresses in Figure 1-3 to find the actual address of each byte. ‘The E command, deseribed previously, 1s used to enter the sequence of data and instruction bytes shown in Figure 1-2 tnta the SDK-86 RAM start- sng at address 0000:0100H. To see the current contents of address 0000:0100 on the data fleld LEDs. press the keys EBO:100, ‘You want to enter the frst instruction code byte of the program into this location 2, The second column to the left in the program listing contains the codes that you wall be loading into RAM, The reason there are different numbers of code bytes on different lines 1s that the code byte(s) required for an instruction are put on the line with the Instruction, Laole at the 184 Personal Coaputer MACRO Asseabler Version 2,00 Page f+! ages 132 9086 Count Progren 5 5 This progran dinpiays an tnsrononting hanadesiaal count on 5 the data Tielé diaplay of the $0686 board. i 000 COE HERE SeaHEMT PUBLIC S1AE C9:C0BE WERE DECORA, MERE Sanitialize data sepeent 0000 98 1300 OV A, DATA PERE 00039 88 HOW D8, ak 0005. 9F coo HOV Dt, 060 4 zero counter 008 8B 000 OV BK, OFFSET SEVEH SEO 5 pointer to seven-seguent codes 0008 ah RFE DISPLAYENOY DY, OFFER {point at 8279 control address 008 E090 HO AL, 38 5 Yoad control werd for data field 0010 OT BY, aL 4 send control werd $0 279 cout BA SOFF av Dx, OFFEBK 5 point at 4279 display mam 0018 6B OF Mov C1, BT ote a4 cL HOV Aly cl 1 get tow byke to be displayed ons a6 OF AND AL, FH 4 mask upper nibble 00a a7 nate 5 translate Lower nibble'to 7-s09 cade 001g FE OUT Diy a F send to 279 display RAN O0ie a6 cs tov AL, 4 get low byte again OO1E BL OF Ov Ck, 04 4 Toad rotate count 0020 m2 00 fou aL, OL 4 Move apper nibble into Iow position 002224 OF BD AL, FH 5 Mask upper nitble ones 7 tan § translate 2nd nitble to 7-s99 code oes gE WT Day a 5 send to O277 display RAK 08S 8A CS HOY Aly | Set high byte to translate 0088 24 OF a AL oF 4 Mask upper nibble 0024 07 su 5 Translate to Tosey code 002) EE Or Di a send $0 8279 display Rh ooec aa os HOV aly 4 get high byte to fix upper nibble coat 2 C9 ROL Aly cL ‘ove upper nibble into low position cog 24 oF PAD AL, FH 4 sash upper nitble ooge 07 ate 4 translate to T-seg code 0039 SE OWT Dky AL 5 Tosog code to S279 display Aa 0094 3 FFFF NY ST, OFFFFH 4 Jond counter to pause 0087 4 Pause: DEC St 9038-75 FD BAZ. PAUSE 0038 47 INCL 5 incrawent counter nga 6B ce AP oIeLay 0030 (CODE HERE BS 000 DATA HERE SESRENT WORD PUBLIC 9000 3F 06 8 4F 66 6D 79 07 SEVER_SEB DB FH) OOH, Sy OFM, 68H, AIH, 7M, OTH Ve ete sare be 0009. TF AF 77-90-39 SE 79 71 Diy Fy 77My POH, Hy SERS PAM 1 a on DATA, HERE EMIS Ey FIGURET-3 8086 counting program, INTRODUCTION TO THE S088 MICROPROCESSOR DEVELOPMENT BOARD. 5 6 2. {op of that column to find the BEM code byte and. fhe other cades that will be put aller {To put the BS code byte into RAM and ta sce address. G1OT on the address Neld and the contents of ‘that address on the data fel, press the keys Bs. ‘The next code byte (to the right of BBR) is 19H, ‘To enter this with the keypad, press the keys 13, ‘The <> Key steps to the next RAM address ‘The next code byte for the program is OOH, so enter this value and press the <> key to step to the next address, ‘The next code byte, found on the next linen the Program printout, is 8EH, Enter this value and Press the <,> key to step to the next RAM. auldress, - Enter each code byte in column 2, followed ty a When you reach the end of the code bytes in column 2, insert the data bytes, starting with SPH in the series of addresses starting with 0000:013E. Note that address 0000:013D is ‘slapped. - Aer you have entered all the program bytes, ress the <> key to return control to the monitor Program. EXPERIMENT 1 9 The next step 1s to check f the program was entered correctly. Press the keys EB 0:10, to see the byte in the first address, If this byte is ot correct, enter the correct value and prese the <> key to get to the next address. if the byte is correct. just press the <,> key to step to the next address. A common error Is to miss a byte: consequently, the bytes after the missed byte eid LP at wrong addresses. If you find an ervor, you can just insert the correct value(s), and proceed, When the program seems correct in RAM, run the ‘program from the starting address (0000:0106H. Press the keys G00:100, + If the program does not operate correctly, press the RESET key and check the codes in RAM again. If the program stil does not work core reetly. get help, If ie permits we suggest that you now go on and do Experiment 2, which shows you how to luse breslspoinis to debug a program that docs? Work and how to modify the operation of the pro- gram, Experiment 2 uses the same program 16 {his experiment, so ifyou leave the power on and do Experiment 2 now, you won't have to Key the Program in again 10. 4, Keypad Monitor REFERENCES: Hall: Chapter 3 URDA oF Intel: SDK-86 User's Manual EQUIPMENT AND MATERIALS SDK-86 microprocessor board INTRODUCTION Hall: Chapter $ discusses the importance of writing mlcrocomputer programs in a etructured manner so that they are more likely to work correctly. Sometimes, however, in spite of careful planning, vriting, and entering, an exror creeps into @ program, ‘Most systems have programs or a series of commands that help you (0 ind the problems) in program, Finding arid correcting the problems in a program 1 commonly referred to as debugging the program, The ‘ovo debugging techniques we want to teach in this exercise are breakpoints and single stepping. It is important to use these techniques as part of a systematic overall debuyging procedure rather than randomly experimenting. Here Is a debugging sequence that we have found effective. 2. Check your algorithm to make sure tt really ‘specifies what you want I 1 do. 2. Cheek that the instructions you have chosen do actually implement the steps of the algorithm. 3. Check that the instructions are correctly coded, if you are hand coding, and that they are correctly entered Into RAM. If these checks don’t turn up any prablems, choose a logleal checkpoint in the program and predict what the contents of key registers and memory locations should be when the program hhas executed to that point. Record your pre- dictions Im some way set a breakpoint at that point in the program and run the program. The program w= tun to the breakpoint and stop, 5. ©. Use the examine memory ané examine register commands to see if memory and register contents agree with your predictions. The prediction part of this Js very important. because it doesn't do you any good to look at memory and register contents Ifyou don't know what the contents are supposed tobe. 7. If the results are correct at that point, you can predict the memory and register contents for a Tater point in the program and move the breakpoint to that point. You can then run the program to the new breakpoint and recheck Key ‘memory locations and registers to see if they are correct at that point. The breakpoint technique allows you to localize the problem area in a rogram. 8 Another debugging technique available. in some ‘systems is the single step. This fonction exeesstes one instruction and stops. You can then examine memory and register contents to sce if they agree ‘with what you predicted they should be at that point. If the results are correct, you can use the single-step function to execute the next instruction and recheck Key memory and register contents. This function allows you to step your way through @ program one instruction at a time, ‘checking the contents of key memory and register Tocations after each instruction. After you have debugged a few programs. you wil get a feeling for which technique Js best suited (o debugging a particular program, OBJECTIVES At the conclusion of this experiment, you should be able ta 1, Use the SDK-86's keypad monitor commands to run a program to a breakpoint and then examine register and memory contents to see if they agree ‘with predictions, 2, Use the SDK-86 keypad single-step command to step through a program, 2. Modify the operation of a program by changing @ value in the prngrars PROCEDURE ‘The Example Program 1, fits not already loaded, use the SDK-86 keypad ‘moniter, EB command to load the program shown, in Figure 1-8 into RAM starting at address (0000:0200H, as described in Experiment 1. 2. Check that ail the instruetion code bytes and data bytes are inserted correctly. 8, Use the SDK-86 GO command with no specified breakpoint to mam the program aa you did in the last section of Experiment 1. If the program does not run correctly, press RESET to get back to the ‘moniter program s0 that you can enter commands again, Use the EB command to make sue that the ‘codes are all in memory correctly. Remember that the top segment on the LEDS is it for a 6 but is not it for ab. When you get the program working correctly, go on to the next step here. Using a Breakpoint As a fst example ofthe use ofa breakpoint you imight want lo see If the het se anstructons of che Program are Inialeing te speted rogters In tHe Say you want You insert a breakpoint ap part of the GO corimand. As shown ia Figuce 1-2, he format ofthe 9 command i GO [ start adér |, breakpoint addr | Remember, the brackets shown in the command format are not entered; they siniply indleate the parts of the command that are optinaal. For our case here, the starting address is 0000:0100 (CS = 0000, IP = 0100; you could also use 0010:0000—that is, CS 0010 and IP = 0000). The instruction at a specified breakpoint address does not get executed. Therefore, the breakpoint address you use is the address of the instruction after the last instruction you want executed, (A breakpoint must always be put at the adress ofthe first byte of an imatrsetion!) i. Predict what should be in the affected registers after these instructions execute, Because yout are hnew at this business, here's what should be in them, Predicted Observed Register Contents Contents AL 0H BX oiscr Dx FFEAH DI 00008 bs 00001 2, For the example here, you want to execute the first sic instructions, so your breakpoint address will be 0000:0110, the address of the seventa, ‘instruction in the program. Enter the command G00:100.0:110 8 BeeuveNT? ‘When execution reaches the brealzpoint address you have specified, the SDK will display a dash in the address field and the letters “br’ in the data field. Ifthe last instruction in your program is INT 3 (eode CCH), the "br’ message wil not appear. ‘The dash indicates that the SDK is ready for you tocenter your next command. 8. Use the ER command to determine the 8086 register contents. Record these contents so that yyou can compare them with those predicted, NOTE: if the SDK “locks up" and does not reach the breakpoint, you can get back to the monitor by pressing the RESET key. In this ease you may have to reenter the Instruction byte at the breakpoint address, because the moniter does the breakpoint operation by temporarily changing this instruction te CCH, Using the Single-Step Command Another technique that fs sometimes useful for debugging a program is single stepping, When the single-step command on the SDK-86 Is used, the ‘monitor program will execute one program instruction and then stop. You can then use the EB, EW, and ER commands to see ifthe program data is correct. Ifthe data is correct, you can then execute the next in- struction and check again. If the data is not correct, you can try to determine why it isn't As shown in Figure 1-2, the format of the SDK. single-step command is, ST start addr, {| start addr} ,1°. ‘What all ofthis means Is that Ifyou press the keypad kkey labeled ST (the <3> key) followed by the address of the instruction from which you want to start stepping and then press the <> key, the SDK will exceute the instruction al that address, ‘The address of the next sequential instruction will be displayed on the address ficid of the display. Each time you! press the <> key, the SDK will execute one instruction and. step to the next. Pressing the <> key terminates the single-step command and returns exocution 10 the ‘monttor program. 1. Execute the first instruction in our example program by pressing the keys sto:100, 2, The offset of the next instruetion will be displayed ‘on the address field LEDs, and the frst byte of the instruction at that address will be displayed om the data field LEDs. Use the program listing in Figure 1-3 to see if A does this correctly for your program, 8. Now press the <> key until you have stepped ‘ough the first six mstructions, then press the <2 key to return to the moniter. 4, Use the ER command of the SDK to see if the register contents agree with those predicted, 5. There is @ problem if you try to use the single-step command to step all the way through the program. to the INC DI instruction al offset OO9AH. Can you see what the problem is? If you can't, try stepping ‘through the program to the INC DI instruction to determine the problem. In the next section we show you one way around this problem, Modifying the Operation of a Program ‘Take a Jock at the instructions starting at offset 003411 in the program. The first instruction here, MOV SLOFFFFH, loads the immediate number FFFFH {nto the St register, The next instruction, PAUSE:DEC SI, decrements the number in the Si register by 1. If the result of this decrement operation does not leave 0 in the SI register, the JNZ PAUSE instruction will send execution back to the PAUSE:DEC SI Instruction, This type of operation is called a program. {oop and will repeat until the number in SI is counted down to 0. 41. Use this fact to help you predict the number that should be in SI when execution reaches the INC Df instruction at offset OAH. Enter a GO command, which wil nan the program to a breakpoint ai the INC DI instruction’s address, . Use the SDK-86 ER command to cheek your prediction, Changing the MOV Si.OFFFFH Instruction so that ft loads a value other than FFFFH into the SI register has an Interesting eflect on the operation, of the program, What SD&-86 command can yon use to change the word that the instruction loads? AL what address in memory is the FFFIH part of the MOV SI. OFFFFH instruction located? |. Use the proper SDK-86 command to change the FFFFH in the MOV SI,OFFFFH instruction to A0FFH, Use the GO command to run the program with no breakpoints in order to see the effect this change hhas om the operation of tie program. . In your report describe the effect produced by the ‘ew value you put in the MOV SI instruction, Experiment with different count values and observe the effects. DEBUGGING PROGRAMS WITH THE SDIC6 KEYPAD MONITOR 9

You might also like