Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
32 views
Microprocessors and Interfacing Programming and Hardware 2nd Edi DL
Uploaded by
Navrachit Kulshrestha
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Microprocessors and Interfacing Programming and Ha... For Later
Download
Save
Save Microprocessors and Interfacing Programming and Ha... For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
32 views
Microprocessors and Interfacing Programming and Hardware 2nd Edi DL
Uploaded by
Navrachit Kulshrestha
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Microprocessors and Interfacing Programming and Ha... For Later
Carousel Previous
Carousel Next
Save
Save Microprocessors and Interfacing Programming and Ha... For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 64
Search
Fullscreen
INSTRUCTOR'S GUIDE FOR MICROPROCESSORS AND INTERFACING PROGRAMMING AND HARDWARE SECOND EDITION DOUGLAS V. HALL GLENCOE ‘Macmillan/MeGraw-Hill Mission Hil, Cer SCM FGIT. IM PCIAT, aM PS, and MtroChanne rchisctre are eto trademarks of BM Corporaton The leson ig6TA4 860TH, CE NOK Borers, Geert 8 1882 by he Glencoe Divison of Macrae Hl Scho! Publishing Gemptny. Copyright © 1965 by Mecraw-Hl nc. Alihisresoved. Except sere sean, the United States Copyright Act, no parol Wis publication may be toded ietivtod in ny form orb any means, or stored ina calabsse or eave srcn without te prior written prmission of ta pubisher ‘Send al iruies to GLENCOE DIVISION MacmilantAcGraw-+) 896 Eastin Orv Westorvile, OH 4308) ISBN 0.07 0257442 Petes inthe United States of America. 129456789 SEM 9908.0796 05 94 3.9201CONTENTS Introduction ANSWERS TO CHAPTER REVIEW QUESTIONS IN THE TEXT Chapter Page 1 3 2 5 3 7 4 al 5 13 6 There are no questions for this chapter. 7 15 8 19 9 23 10 27 ul 31 12 35 13 37 4 41 15 45 EXPERIMENT NOTES AND ANSWERS TO SELECTED QUESTIONS IN THE EXPERIMENTS SUPPLEMENT Experiment Page Experiment Page a 50 21 ci 2 50 22 61 3 50 23 61 4 51 24 62 5 52 25 62 6 52 26 62 7 53 27 64 8 53 28 64 9 53 29 64 10 54 30 65 n 54 31 66 12 35 52 66 13 56 33 66 4 56 34 66 15 57 35 66 16 58 36 67 17 59 37 67 18 59 38 67 19 60 39 68 20 60 40 68INTRODUCTION In addition to the answers contained In this instructor's guide, I have prepared a set of IBM PC:compatible disks which contain the source files for: All the example programs in the text All the program answers for end-of-chapter problems. All the programs for the experiments, except those for a couple of open- ended exercises. 4. A program called SDKCOM1.EXE, which can be used to download binary programs to an SDK-86 board at 4800 Bd. 1 think you will find that having these programs on disks is much more ‘useful than simply having program listings, because: 1. You can assemble, link, download, and run these programs for demonstrations and/or further experimentation. 2, You can print out listings of selected programs as needed for use in class discussions. 3. You can give students part of the solution to a problem and let them fill in the missing pieces. This allows you (o adapt the text problems and experiments to a wide range of student abilities. 1 initially give an assignment without hints; then, after students have worked on the problem for awhile, I give hints or program fragments as needed to allow the majority of students in a particular elass to experience a feeling of success, This approach helps avoid the tendeney of many students to wait until one of the “sharp” students figures out the solution and then just copy the solution from him or her without trying, to solve the problem independently. 4, You can use these “known good" programs to test the hardware modules used in the laboratory exercises. This last use allows you to quickly deal with the common student complaint, “My program doesn't work; the hardware must be broken.” have tried to make this instructor's guide as accurate as possible. If you nd any errors, have any further questions, or have any suggestions for improving the book or the lab manual, | would appreciate hearing from you. Notes about the Program Disks 1. The directory called TEXTXMPL contains the source code for all the program examples used in the text. 2. The directory called TEXTANS contains the source code for all the programs required as answers to problems ‘The directory called LABANS contains the source code for al the programs for the experiments. ‘The SDACOMIEXE download program s in the root directory, so you can easily copy it to your hard disk. For all the systems I tried SDKCOML.EXE works perfectly, but the older SDKDMP.EXE is included in
. Use whichever program works better on your systems. Also, the source programs and .PRJ file for SDKCOMI are in the LABANS directory if you want to experiment with improving the program. 5, These programs were all compiled with TASM, MASM, or the Turbo Cl Integrated Environment compiler. To the best of my knowledge, they all work, Please let me know about any problems you encounter. Douglas V. HallAnswers to Chapter Review Questions in the TextCHAPTER 1 COMPUTER NUMBER SYSTEMS, CODES, AND DIGITAL DEVICES is 21 = 2048 212 = 4096 2M = 5192 2M = 16,384 16 219 2 32.768 32 2192 65,536 61 217 = 131,072 128 218 = 262.144 2P = 256, 219 524,288 B12 220 1,048,576 1024 4G. 22 decimal = 10110 binary b, 76 decimal = 1001100 binary © 500 decimal = 111110100 binary a 11 dectmat b. 11010001 = 209 decimal © 1110111001011001 = 61.017 decimal @. 83 decimal = 3511 >, 786 decimal = 2F4H © 011 0110 0010 = 362 @. 110 0001 0111 = 6171, > DSH = 211 decimal SPEH = 1022 decimal 44H = 68 decimal @. 86 decimal = 1000 0110 BCD >, 62 decimal = 0100 0010 BCD © 83 decimal = 0011 0011 BCD ‘The 1 key produces the pattern 0101100 (4CH. ‘A carriage return (ODH) would give the pattern (00001101, ‘The term parity is used to show if a data word hhas an even number of 1's, Even parity means fan even number of 1's, Errors in transmitted data are detected as follows. The system sending a data word checks the parity of the word. I there s an odd number of 1's in the word, the system will set the parity bit (bit 7) to @ 1 otherwise it will reset the parity bit. Either way, the parity of the word plus the parity bit Decomes even. The data word is transmaitted and the parity is checked at the other end. I the parity of the word is odd, st can be assumed that {an error ocurred in transmitting the data. @ 10011 + 1011 = 11110 oi 0111 b. 37+25 262 40010 0101 ‘0101 1100 add 6 because > 8 + _on0 ‘1100010 AH + 77H =ClH 0. n 2 B. 14 Decimal __S.Bit eit Sign Magnitude and Magnitude a 426 000110100001 1010 bor (0000 0111 1111 1001 © 26 00011010 11100110 "125 0111 1101 1000 0011 Decimal Pencil _2°s Complement if Sign Bit = 0, Result +, Ignore Carry a out oun 0100 +1100 ‘oO TOON ». 0100101 00100101 90011010 41100110 (00001011 10000 1011 e o1tt tot ont 1101 oloL 101 + 1010 0011 (00100000 10010 0900, a @x3=27) 3001 10010 nol 11010 (26x58 = 130) 101 1i010 11010._ 0000015, 3010 (100/10 = 10) 1010FFTOTOO 1010 1010 4010 69000 a SAH + 94H = CEH b, TAH - 4CH = 12EH © 01011001 BeD-——(59-+ 42= 101) 1001 1011 £0110.0110 {add a correction of 6 6} 10000 6001 4 0111 1001BCD (79+ 49 128) +0100 1001, BCD 1100 0010, +OL100110 (add a correction of 6 6) 1.0010 1000 NUMBER SYSTEMS, CODES, AND DEVICES 315 16 uw. © 0101 1001 BCD =0010 0110 BCD 011 OO1T f 0110 0111 BCD. 0011 100] BCD (0010-1110 = ___ouo ‘0010 1000 For the circuit in Figure 1-23: a. The output fs active high. B. ‘The C signal is active high, The ¥ output is asserted when As high, Bis low, and C is high: or when Ass low, Bis high, and € 4s low. (69-26 = 33) (67-39 = 28) (subtract a correction of 6} When the D lateh is enabled, the @ output follows the D input. in the D fp-flap, the output ‘only follows the D Input on the rising edge of the lock signal ‘Thirteen address lines are fone of the 8192 bytes in a INSS298, (2° 19 address lines, 0 through 12.) $ cHaPrER 1, 20, ‘Most ROMS and RAMs have three-state outputs (logic low, logic high, and floating high- impedance’ states) bevatise usually more than one device is connected to a bus, Only one device at a time can have its outputs active on the bus: all others must be floating. s3_s2 si so m hee. Osco ose) DB A-B-1 0 1 1 0.0 © BHA 1 0 0 0 0 @. 1010 AND 0111 = 0010 1010 OR Ol = UD >. 1011 AND 1100= 1000 10M OR 00 = © 11010111 AND 0011 1000 = 0001 0000 11010111 OR 0011 1000 = 1421 TH An 8-bit mumber ANDed with 1111 0000 will Teave the upper 4 bits the same and zero masi) the lower 4 bits.CHAPTER 2 COMPUTERS, MICROCOMPUTERS, AND MICROPROCESSORS—AN INTRODUCTION 1. Advantages of a distributed processing system over a time-sharing system are as follows: If the large computer goes down, the local microcomputers can continue working until it Is necessary to access the large computer: (b) the Durden on the large computer is greatly reduced: and (c) the system can be designed to use a local ‘microcomputer best suited to the task ft has to do. ‘The sequence of signals Is as follows: 4G. An address is sent out on the address bus. b, A memory-read signal is sent out on the control bus. The memory outputs the instruction byte on the data bus. d. The CPU reads in the instruction and decodes it. 3. The number of bits a microprocessor's ALU can work with at a time determines whether the nleroprovessor Is considered an &-bit, 16-bit, or 82-bit system. 4. @ The 8086 has 20 address lines. b, Twenty address lines allow the 8086 to access 1,048,576 memory addresses eurecly © Each segment contains 64K bytes within this IM-byte range 5. The 8088 has an &-bit data bus, 0 it ean read data from or write data to memory and ports ‘oly 8 bits at a time. The 8086 ean read or write tlther 8 oF 16 bits at a time, @ The 8086 queue holds the next six instruction bytes from memory. +b. The queue speeds up processing because the EU reads the next instruetion from the queue. This is much faster than sending out an address to the system memory and walling for the memory to send back the next instruction byte or bytes, 7. a The CS register will hold 7040H. b. ‘The next code byte fetched from the physteal address » 70400 + 539CH = 7578CH, 8. a 4970:561EH represents 43700H + 561EH 48DIEH, b, 7A32,0028H represents 7A320H + 0028H TAS4BH. 9. The advantage of using a CPU register ts that the data is already in the EU; therefore, it ean be wo, un 2. 1 1B 16. 1, 18. accessed much more quickly than it could in external memory. SS = 3000H and SP = 8434H, TOS = 30000 + 8434H = 88434H or 3000:8434. @ tis very difficult to memorize the thousands of binary instruction codes for a CPU and very easy for an error to occur when working with the long series of I's and 0's required by machine language. Assembly language ‘makes programming easier and less prone to 1b, When an 8086 executes the instruction ADD AX, BX, the contents of the BX register are faded to the contents of the AX register and the result is left in the AX register. BX is leit unchanged, Programs which require a lot of hardware contro! or programs which must run as quickly as possible are usually best written in assembly language. @ MOV BX, OSFFH :Load the number OaFFH Into the BX register. . MOV AL, ODBH jLoad the number DBH Into the AL register. © MOVDH,CL ‘The contents of the CL register are copied into the DH register. CL is unchanged, d. MOV BX, AX :The contents of the AX register are copied into the BX register, AX 1s unchanged, &. MOV BP, 7986 b. MOV SP. BP © MOV DS, AX d. MOV AL, OFSH EA = 14A3H and DS = 7000H, address produced by the BIU = 714A3H, DS = 4000H, physical address for (23481) = 40000 + 2S4BH = 4234BH, MOV [482011], DL MOV AX, 2497H1 = loads the AX register with the number 2437H. MOV AX, [2497H] copies the conterits of memory location DS + 2437H into AL and the contents of memory location DS + 2487H + 1 into AH (Le., loads the 16-bit AX register from vo 8-bit memory locations) CCOMPUTERS:INTRODUCTION. 5CHAPTER 3 8086 FAMILY ASSEMBLY LANGUAGE PROGRAMMING—INTRODUCTION 1. The main steps in developing an assembly language program are: 4. Define the problem, b, Write down, in general terms, the algorithm for what the program has to do, using a flowehart, a sequential list. or pseudocode (Le., represent the structure of the program In some way that Is very clear to you ancl (0 anyone else who might have to work on the program), ¢. Write an initialization checklist for your program. 4, Determine the instruction statements ‘required to do each part of the program. fe, Start writing the assembly language for the program, 2. The top-down design approach produces easy to understand, modular program representations that may be programmed in either high- or low- level languages. A detailed algorithm enables you to break & programming probiem into small modules which can easily be written, tested, and debugged. The more time you spend organizing your programs, the less time it will take you to write and debug them, 4. a@ Sequence, Selection, and Repetition (or Sequence, IF-THEN-ELSE, andl WHILE-DO} b, The advantage of using only these structures when writing the algorithm for a program 1s that the algorithm is easy to understand, Implement, and debug favolds spaghett). 5. Pacudacode: Look in your kitchen for peanut brittle recipe ingredients, IF any of the ingredients are missing THEN go to the store and buy the missing ingredients. Find a teaspoon, a I-cup measure, a 1.5-quart casserole, and a nonstick cookie sheet Measure 1 cup of sugar and pour it into the casserole. Measure 0.5 cup of com syrup and pour it into the casserole. WHILE not mixed DO stir the contents of the casserole Mlerowave on HIGH for 4 minutes. WHILE microwave stil cooking DO sit and read ‘newspaper. Add peanuts. REPEAT stir the contents of casserole UNTIL mixed 6 ‘Microwave on HIGH for 4 minutes. WHILE microwave still cooking DO look out of the window. ‘Add 1 teaspoon of butter. ‘Add 1 teaspoon of vanilla REPEAT siir contents of the casserole UNTIL mixed. Microwave on HIGH for 2 minutes. WHILE microwave still cooking DO start to clean up. ‘Adel 1 teaspoon of baking soda. WHILE not light and foamy DO gently stir mixture. Pour mixture onto nonstick cookie sheet. WHILE minutes passed < 60 DO go do something else. IF mixture not cool THEN wait Tonger ELSE break into pieces. Eat peanut brittle, a. Pseudocode: Get number from memory location and put into a_ register, ‘Subtract 20H from the number tn the register. IF number in register > 25H THEN output 1H to port SAK, b, Flowchart: See Figure 3-1, ‘GetNuwern FRow era FIGURE 3-1. Flowchart for algorithm for question 6. PROGRAMMING INTRODUCTIONNext instruction fetehed from 4000:43E8H or 443E8H. TOS address 7000:0000 or 70000. MOV AX. BX:Copy the contents of BX to AX. AX = BX = 075A. MOV CL, 37H:Load CL with 87H. CL = 37H, INC BX:Increment BX. BX » O75BE. MOV CX, [246BH):Copy the contents of ‘memory at 5246BH and §246CH into the CX register, MOV CX, 246BH;Load CX with 246BH. ADD AL, DH:Add contents of DH to AL and leave result i AL, AL = 85 + 38 = 68H, DH = 33H) MUL BX;Multiply the contents of AX with BX: the result is the high word im DX and the low word In AX. DX = O1EGH, AX BOAZH, DEC BP:Decrement the contents of BP. BP 2467H. DIV BL:Divide AX by BL, quotfent in AL, remainder in AH, AX = BCSBH. SUB AX, BX:AX - BX; result in AX (075A = SADBI OR CL, BCE ts ORed with BL: result in CL 5EH. NOT AH;Complement AH, AH = 1011 1101 ROL BX, 1:BX Is rotated left once. BX was (0000 0111 0101 1010, BX now 0000 1110 1011 0100, CF =0. AND AL, CH:AL is ANDed with CH; AL = 00. MOV DS, AX:Instislize the data segment at 423514 copy contents of AX into DS. ROR BX, CL:Rotate the contents of the BX register right, 4 tumes (CL = 4). BX was 0000 0111 0101 1010, BX now 1010 0000 0111 0101, CF= 1. AND AL, OFH:AL is ANDed with OFH AL OSH. MOV AX, [BXI:Copy the contents of memory fn data Segment, pointed to by BX, into the AX register. AX'= contents of 50754H and S075BH. MOV [BXI[SII. CL:Copy the contents of CL ‘nto memory in data segment at an offset of BX + SI. Memory at S885AH will contain oan. MOV BH, AX:Register size doesn't match Should be MOV BX, AX or MOV BH, AL or MOV BH, AH. ‘MOV DX, CLiRegister size doesn't match. ADD AL, 2073H:Number is too large for AL- ‘Should be ADD AX, 2073H, MOV 7632H, CX:Cannot move a register’s contents into an immediate number. Decide if you want to MOV CX, 7632H or If you ‘want to copy the contents of CX to memory. IN BL, 04F:Can only transfer from a port to the AL or AX registers. 8 cHamTER s 10. 2 13 @ ADDBLAl {BL = SA + 35 = 8FH MOV [0004 BL :50004H = SFH b. MOVCL, 04 :CL=04 RORDLCL — :DI = O7D0H ° ‘AL = 35H + 07H = SCH “AL = 42H 4d. MOV BX, OOOAH :BX = 0008H MOV AL, IBX] GAL = contents of 5000AH =7cH SUBAL,.CL — :AL=7C_04= 78H INC BX SEX = 000BH MOV [BX], AL ;:5000BH = 7811 @ MOVBL.AL — (Copies AL to BL b. MOVCL. 43H ‘Loads CL with 43H e mNcex ‘Increments CX by one. d MOVBP, SP ;Copies SP to BP @ ADDDL,O7H {Adds 07 to DL f MULBE ‘Multiples AL times BL, reault in AX 4g. MOV ASAHI], AX Copies AX to a memory locas at offset of DS:245A81 h DECSP Decrements SP by one £ ROLAL,O1 Rotates the MSB of AL {nto the LSB of AL :Copies DL to memory location pointed to by BX ‘Masi lower 4 bits of BL 'Sets the MSB of AX to 1, doesn't affect other bits sInverts lower 4 bits of AL rbut doesn’t affect otter J. MOY [BXI, DL. ke AND BL, OFOK, L ORAX. BOK m. XORAX, OFH bits Inetretion Binary Code Hx MOVIEXL.CX 10901001 00001 11-89 OF AD Bx, S01] 00000011 01 O11 10108 559 ‘sus ost co10100000 110 11028864820 XCHG CH, E5188) 90100110 100001 1026 862 RORAK. 1 11010001 11601 000 BL es OUTDK.AL snio1ni8 = AND ALG aLa0100 OF 2606 DATA_HERE SEGMENT (0 DATA_HERE ENDS sets up a logical segment for the data called DATA HERE.PRESSURE DB 0 assigns the name PRESSURE to a byte type variable and initializes that variable with the value of zero. PRESSURE is a variable in the DATA. HERE segment, PRESSURE_PORT EQU 04H and CORRECTION FACTOR EQU 07H gives the values of 04 and 07 to the constants PRESSURE_PORT and CORRECTION. FACTOR, CODE_HERE SEGMENT and CODE_HERE ENDS sets up a logical segment called ‘CODE_HERE for the code in the program, ASSUME CS:CODE_HERE, DS:DATA HERE tells the assembler which cade and data segments are to be used. MOV AX, DATAHERB and MOV DS, Ax initializes the data segment register with the starting address of DATA HERE. IN AL, PRESSURE_PORT brings a byte of data into the AL register through the port addressed by PRESSURE, PORT (04H), ADD AL. CORRECTION_FACTOR AND MOV PRESSURE, AL adds a correction of O7H to the contents of AL, and it Is then copied to the variable called PRESSURE in the data segment called DATA_HERE. The last line, END, tells the assembler there aze xno more instructions to assemble, ‘An assembly Janguage program is developed and debugged using system tools m the following way! @. Build an algorithm for your program. b. Decide on the instructions required to build the program. © Build the assembly language source file in the correct format using an editor. @ Assemble the source file by using an assembler which produces an object and list fe ©, Wi necessary, correct the source program using the editor J Print out the assembler list le 3. Use a linker which joins together several object Mes, if necessary. and produces a link file which eantains the binary code for the program, A. If necessary for your system, use a locator program to assign the specific addresses in ‘memory for the object code, 4 If your program requires no external hardware, or requires only hardware accessible directly from your system, use a debugger to run and debug your program. J. Wyour program is intended to work with external hardware, use an emulator to ran and debug your program. Pseudocode for flowchart: REPEAT. REPEAT Create source fle with editar Assemble source fle UNTIL no assembly errors Link Locate * external system THEN Load emitlator Load program Run and test program 1 errors THEN use ermulator tools to find errors SE do nothing ELSE Load debugger ‘Load program Run and test program IF exrors THEN tase debugger tools to find errors BLSE do nothing UNTIL no errors STOP PROGRAMMING INTRODUCTION. 9CHAPTER 4 IMPLEMENTING STANDARD PROGRAM STRUCTURES IN 8086 ASSEMBLY LANGUAGE a a. ROLAX,CL: The accumulator is rotated left twice (CL = 02), which leaves AX = 901EH. b. INAL,DX: A byte Is copied to AL from port DX (FFFAH. 6 MOV CX, [BX]: The contents of memory in the data segment at addresses 324B3H and 24141 are moved into cx ‘The contents in the data segment of memory at address 366B3H (BX + SI = 2483 + 4200 = 66BSH, which is then added to 30000 to give the physical address) and address 36684H are added to the AX register. The result te left in the AX register, d. ADD AX, [BXI(SI} © JMPO23AH; The contents of the Instruction pointer are replaced with the value O23AH, and the program execution jumps to address 2028AH. Jf IMPBX; The contents of the instruction pointer are replaced with the contents of the BX register, and the program execution jumps to address 224B3H. Inetruction __Blaary Code Hes ROLAK.CL 12010011 1 000.000 sco BALE — 11201100 Be Mov ex, jx) 10001011 o0 001 111 sor ADD AX, [BRIS 000000 11 60 400 000 0300 LIMP @aAH (1191001 0011 1010-0000 4010 EBSAC2 Inctraction| lag Contents ORC, BORO, 2483.00 14, a Time for one clock eyele = 1/ 5M Each me the loop Is executed, BL is loaded with 72H, Therefore, BL never reaches zero land execution never Teaves the loop. b, Cannot mix bytes and words in instructions, Use elther CX, AX of Cl, Aly or CH, AL- UMP needs a word, or for an indirect jum address, BLis only a byte. ._JNZ can only go to a label in the range +127 to -128 from current IP; cannot use indirect addressing modes, 5.4, b, See the program A04-05B.ASM. © To add 2 BCD bytes, add the instruction DAA after the line ADD AL, NUM2. 6, See program A04-06.8SM, ‘See program A04-07 ASM. 8. Sce program AD4-08.ASM, 9, See program A04-09.ASM. 10, See program A04-10.ASM. 11, See program AO4-11.ASM, 12, See program A04-12.ASM. 13, See program A04-13.ASM. O2s Number of clock cycles required = 300usec/0-2use¢ = 2500 The following code is used for the delay loop: MOV OX, N 14 clock cycles ‘KILL_TIME:NOP, ‘3 clock eyetes LOOP KILL TIME: 17 or S lock cycles N #(C,-C,+DV/C, ©, = overhead eyeles ‘number of eyeles in loop total mumber of eycles wait 1300 1D. =dlfference between LOOP executing or not = 17-5 = 12. ‘Therefore: N= (2500 - 4 + 12}/20= 125, ._ See program A04-14.ASM, o7DH 06 ASSEMBLY LANGUAGE 14CHAPTER 5 STRINGS, PROCEDURES, AND MACROS ‘a. See program A05-01A.ASM. b b, See program A05-018.ASM. See program AQ5-02.ASM. MOV AX, 40001 MOV $5. AX MOV SP, 8000H CALL FIXIT ;Call a near procedure, FIXTT. PUSH BX Save BX and BP PUSH BP at start of procedure POP EP :At end of procedure, POP BX jnotice order of POPS RETS Return from a procedure and Increment SP by 8, See Figure 5-1. If the POPF instruction was accidentally left out of the procedure, the RET instruction would place the contents of the saved flag registers into the IP register. This means that execution would continue, not just after the place where the procedure was called but at some other place. One way to track down this problem is to Keep a map of the stack. Ifyou make a mistake with the stack map, you can run the program to the end of the procedure wnd then examine the registers to see if the RET instruction occurred at the correct SP. Another way to debug this type of problem is to use the single-step facility of the debugger, although this takes much longer: ‘The binary code for the instruction whieh will call a procedure which is 97 addresses higher 2 memory than the call instruction is 11101000 01011111 RET 4; 11000010 0000100 00000000 ‘Three methods of passing parameters to a procedure include: Using general memory and named memory locations. One advantage of thls method 1s thal it makes programs easier to understand, The disadvantage 4s that you cannot use this method for procedures that call themselves or from procedures that will be called from a higher-level language. Using registers to pass values of varlables. The advantage of this method 4s speed —the parameters are immed: ately available in the procedure. The disadvantage is that you cannot pass a large number of parameters unless you use a reuister to just hold a pointer to, for example, an array of data in memory. Note: Recursive and reentrant procedures can use registers, because the register contents will be pushed on the stack during each call. Also note that some higher-level languages for specific machines do allow a few parameters ta be passed in registers Using the stack to pass values of variables. One advantage of this method is that It does not depend on the architecture of the specific processor, 50 it helps make a program “portable Also, this method can be used for reentrant procedures. The disadvantages are the time overhead involved and the complexity of using a pointer and an offset to access the passed parameters, 2000 sp SP initialized by MOV $P, 40008 SPF AH SFFE AL SP -2 then PUSH AX. AL at SP, AH at SP+2 SEED IP HIGH BFFC PLOW SP -2 then PUSH IP Jor CALL MULTO SFFB F HIGH FFA FLOW — SP-2 then PUSH F SFO BH 3FF8. BL SP- 2 then PUSH BX SFF9 POPBX BX = contents of 3FFS & 3FF9 3FFB POPF Flags = contents of 3FFB & 3FFA SFPD RET 1P tents of SPFD & SEFC BFF POPAX AX = contents of SEFF & aFFE FIGURE 5-1. Stack map for question 4 STRINGS, PROCEDURES, AND MACROS. 1310. n, , The term reentrant means a procedure can be interrupted by another procedure at any time, used by the interrupting procedure, and then pick up where it left off in its first execution. You must use the stack or registers to pass parameters to a reentrant procedure. See program A05-07.ASM, See program AO5-08.ASM, For the algorithm, see Figure 6-28 on page 130 of the text. See program A0S-09.ASM, See program A05-10.ASM. 4a, To tell the assembler to make the label BINADD available to other assembly modules, the statement PUBLIC BINADD ‘would have to be added to the part of the program calling the label ». To tell the assembler to look for a byte type data item named CONVERSION FACTOR in some other assembly module, you would have to add the statement EXTRN CONVERSION FACTOR:BYTE, surrounded by the name of the data segment it was declared in, For instance, if st was declared in the data segment DATA HERE, you would have fo add the lines: DATA_HERE SEGMENT PUBLIC EXTRN CONVERSION FACTOR : BYTE DATA_HERE ENDS, 2 POP_ALL MACRO PoP ss POP ES POP DS POP DI POP SI Por BP POP DX, POP CX POP BX PoP AX POPP ‘THERE ARE NO QUESTIONS FOR CHAPTER 6. 14 CHAPTERSCHAPTER 7 8086 SYSTEM CONNECTIONS, TIMING, AND TROUBLESHOOTING 1, The start of an 8086 state is measured from the 50 percent point of the falling edge of the clock. ‘waveform, 2 Latches hold the address information so that the 8086 can float the address lines and then use them for data input and output. 3. The ALE high signal is used to enable the latches s0 that the address information Is passed through to the latch outputs. When ALE goes low, tte address information is held on the Tateh outputs. a ‘The sequence of events on the 8086 data/address bus and the ALE, M/IO and RD lines as the 8086 fetches an instruction word is: 2. M/TO goes high so that memory is accessed, 1b, ALE qoes high wo enable latehes, An address is sent out on the data/address bus. 4 ALE goes low, the audress ts latched on the latch outputs, the latches are disabled, and the data/address bus ts floated, e. RD goes low, causing the addressed device to put data on the bus. f Data comes in on the data/address bus, 9. RD goes high. = A. The word or byte is read. depending on BAB and AO. ‘When writing to memory, WR = 0, RD = 1, and M/IO = 1. When reading from a port. WR = 1. RD = 0, and M/10 = 0. 6 Minimim mode ts used when there is only one ‘microprocessor on the system buses. Maximum ‘mode Is used when two or more microprocessors share the system buses. 7. When RESET = 1, DS, SS, ES, IP, and the flag registers = 0, and CS = FFFFE. 8. Buffers are often needed on the address/data Unes and control buses in a mleroprocessor system because as more devices are added to the system, each device iput or output acts like & capacitance of a few picofarads connected to ground. To change the logie states up/down, all Of the added capacitance has to be charged/ discharged. The 8086 cannot supply enough _ current to charge or discharge the circuit capacitance rapidly, so high-current drive Dutfers are added to da the Job, 9. @ If the READY input is made low, the 8086 “will enter a WATT state ” 10. a a 1B. 14 4. 16. b, An 8086 enters & WAIT state after the falling ‘edge of T, ¢. Information on the buses remains the same during a WAIT state as iL was at the start of the WAIT state d. The 6086 stays in the WAIT state as long as READY = 0. © The 8086 can have any number of WAIT states, J WAIT states are needed if the system contains devices which cannot respond fast, ‘enough for the processor. ‘The DTV signal is used to specify the direction in_which the buffers are enabled. DT/R high + ‘DEN low = transmit data to memory/ports. DI/R low + DEN low = receive data from smeraory /ports The DEN signal ts used to enable the bidirectional buifers on the data bus, ‘The transition at the tail of the arrow causes the transition at the tip. ‘See Chapter 7 tn the text and Figure 7-4 on text age 169. The clock function tells the analyzer how often to take samples. The trigger tells the analyzer when to display the samples stored in its internal RAM. For detalled dming measurements, use the iogie analyzer’s internal clock. a. Use the falling edge of the ALE si trigger on address FFFFOH te see the sequence of addresses output after a RESET. b. Use the rising edge of RD as a clock signal and trigger on instruction OEAH to see the sequence of instructions read in after a RESET. Use the clock signal as clock (falling edge] to see both the addresses sent out and the words read in. - 4. Clock on the rising edge of RD, clock qualifier input connect to M/IO. Set the analyzer to accept clocks when M/TO Is low. It fs possible for a logic analyzer to display data that occurred before the trigger because ‘whenever it receives a clock, it stores samples in its internal RAM. The trigger position specification is used to tell the analyzer to display samples pre-trigger, post-trigger. or center-tigger. Wire-wrap jumpers are shown as, for instance, wor, CONNECTIONS, TIMING, AND TROUBLESHOOTING 15
You might also like
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Mark Manson
4/5 (6132)
Principles: Life and Work
From Everand
Principles: Life and Work
Ray Dalio
4/5 (627)
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Brene Brown
4/5 (1148)
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
Chris Voss
4.5/5 (935)
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Jeannette Walls
4/5 (8215)
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Angela Duckworth
4/5 (631)
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
Jesmyn Ward
4/5 (1253)
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Stephen Chbosky
4/5 (8365)
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Phil Knight
4.5/5 (860)
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Carmen Maria Machado
4/5 (877)
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Ben Horowitz
4.5/5 (361)
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Margot Lee Shetterly
4/5 (954)
Steve Jobs
From Everand
Steve Jobs
Walter Isaacson
4/5 (2923)
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
Ashlee Vance
4.5/5 (484)
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
Siddhartha Mukherjee
4.5/5 (277)
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Fredrik Backman
4.5/5 (4972)
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Frank McCourt
4.5/5 (444)
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
Colm Toibin
3.5/5 (2061)
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Garth Stein
4/5 (4281)
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
Sarah M. Broom
4/5 (100)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Meik Wiking
3.5/5 (447)
Yes Please
From Everand
Yes Please
Amy Poehler
4/5 (1987)
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Thomas L. Friedman
3.5/5 (2283)
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Gilbert King
4.5/5 (278)
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Roxane Gay
4/5 (1068)
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
Ruth Ware
3.5/5 (2641)
The Outsider: A Novel
From Everand
The Outsider: A Novel
Stephen King
4/5 (1993)
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
Betty Smith
4.5/5 (1936)
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
Viet Thanh Nguyen
4.5/5 (125)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Dave Eggers
3.5/5 (692)
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Doris Kearns Goodwin
4.5/5 (1912)
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Hilary Mantel
4/5 (4074)
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Naomi Klein
4/5 (75)
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Bob Woodward
3.5/5 (830)
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
Jennifer Egan
3.5/5 (901)
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Jay Sekulow
3.5/5 (143)
John Adams
From Everand
John Adams
David McCullough
4.5/5 (2544)
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
M L Stedman
4.5/5 (790)
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
George Packer
4/5 (45)
Little Women
From Everand
Little Women
Louisa May Alcott
4/5 (105)
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel
John le Carré
3.5/5 (109)