smvorkoetter@watmum.UUCP (10/15/87)
I ran into an interesting problem the other day. A TSR that I was using would occasionally insist that it was already installed when I first try to install it. Upon examining the code to see how it determined whether or not it had been installed, I found that it checked the interrupt vector it was supposed to take over, and then looked at the memory that this vector pointed to. It checked for the first 3 bytes of itself at that location. The idea of course is that if it were not yet installed, the vector would point to some random location, which would not contain these 3 bytes. The code to do this was: MOV AX,segment ;from the interrupt vector MOV DS,AX MOV BX,offset ;also from the vector CMP BYTE PTR [BX],xx ;check for first byte JNZ install ;jump to install routine CMP BYTE PTR [BX+1],yy ;check second byte JNZ install ;jump to install routine CMP BYTE PTR [BX+2],zz ;check third byte JNZ install ;jump to install routine ;code to print "already installed" message This looks legitimate, but it didn't always work. I ran it under the debugger, setting a break point at the first CMP instruction. I examined the memory location pointed to by DS:BX, and found that it did not contain xx since the program was not yet installed. I then ran the program further, but the JNZ did not jump! The test failed. Looking more carefully, I noticed that the location that DS:BX, and thus the interrupt vector, pointed to was in an empty area, where there was no RAM or ROM. When I changed the code to read: MOV AX,segment MOV DS,AX MOV BX,offset MOV AX,[BX] CMP AX,yyxx JNZ install MOV AH,[BX+2] CMP AH,zz JNZ install NOP... it worked flawlessly. Clearly, the two pieces of code above are equivalent. What I finally suspected is that with the old CMP instructions, the last byte fetched was the value to be tested. Since the location to be tested had no RAM or ROM in it, reading this location put nothing on the bus. Bus capacitance held the previously fetched byte on the bus instead, and it was read again. Thus, the bytes tested as equal. In the changed code, the value was read first and stored, and then compared. It is interesting to note that when I used debug on the second example and set a breakpoint after the MOV AX,[BX] instruction, the value in AX was not the same as what I saw when I looked at location DS:BX with debug. Can anyone confirm or deny my suspicions about this? The system I am using is an IBM PCjr, with a Racore Drive Two expansion and 512K of RAM. Stefan Vorkoetter University of Waterloo
darrylo@hpsrlc.HP.COM (Darryl Okahata) (10/17/87)
In comp.sys.ibm.pc, smvorkoetter@watmum.waterloo.edu (Stefan M. Vorkoetter) writes: > I ran into an interesting problem the other day. A TSR that I was > using would occasionally insist that it was already installed when [ ... ] > location put nothing on the bus. Bus capacitance held the previously > fetched byte on the bus instead, and it was read again. Thus, the > bytes tested as equal. In the changed code, the value was read first > and stored, and then compared. It is interesting to note that when > I used debug on the second example and set a breakpoint after the > MOV AX,[BX] instruction, the value in AX was not the same as what I > saw when I looked at location DS:BX with debug. > > Can anyone confirm or deny my suspicions about this? The system I am > using is an IBM PCjr, with a Racore Drive Two expansion and 512K of > RAM. > > Stefan Vorkoetter > University of Waterloo > ---------- I've heard other people say this, too. You are not the only one, although I can't remember the name of the TSR that they were using. It does make sense, though. -- Darryl Okahata {hplabs!hpccc!, hpfcla!} hpsrla!darrylo CompuServe: 75206,3074 Disclaimer: the above is the author's personal opinion and is not the opinion or policy of his employer or of the little green men that have been following him all day.