[ Pobierz całość w formacie PDF ]
.Now, the DOS dispatcher controls access to dozens of individual service routines.Howdoes it know which one to execute? You have to tell the dispatcher which service youneed, and you do so by placing the service's number in 8-bit register AH.The dispatchermay require other information as well, and will expect you to provide that information inthe correct place before executing INT 21.Look at the following three lines of code from EAT.ASM:lea DX,Eat1 ; Load offset of Eat1 message string into DXmov AH,09H : Select DOS service 09H: Print Stringint 21H ; Call DOSThis sequence of instructions requests that DOS display a string on the screen.The firstline sets up a vital piece of information: the offset address of the string to be displayed onthe screen.Without that, DOS will not have any way to know what it is that we want todisplay.The dispatcher expects the offset address to be in DX, and assumes that thesegment address will be in DS.The address of the data segment was loaded into DSearlier in the program by these two instructions:mov AX,MyData ; Set up our own data segment address in DSmov DS,AX ; Can't load segment reg.directly from memoryOnce loaded, DS is not disturbed during the full run of the program, so the DOSfile:///E|/TEMP/Chapter%207%20Our%20Object%20All%20Sublime.htm (26 of 38) [9/30/02 08:34:08 PM]file:///E|/TEMP/Chapter%207%20Our%20Object%20All%20Sublime.htmdispatcher's assumption is valid even though DS is loaded early in the program and noteach time we want to display a string.In moving 09H into register AH, we tell the dispatcher which service we want performed.Service 09H is DOS's Print String service.This is not the fastest nor in other ways thebest way to display a string on the PC's screen, but it is most certainly the easiest.DOS service 09H has a slightly odd requirement: that the end of the string be markedwith a dollar sign ($).This is the reason for the dollar signs hung incongruously on theends of both of EAT.ASM's strings.Given that DOS does not ask us to pass it a valueindicating how long the string is, the end of the string has to be marked somehow, and thedollar sign is DOS's chosen way.It's a lousy way, unfortunately, because with the dollarsign acting as a marker, there is no way to display a dollar sign.If you intend to talkabout money on the PC's screen, don't use DOS service O9H! As I said, this is theeasiest, but certainly not the best way to display text on the screen.With the address of the string in DS:DX and service number 09H in AH, we take a trip tothe dispatcher by executing INT 21H.The INT instruction is all it takes boom! andDOS has control, reading the string at DS:DX and sending it to the screen throughmechanisms it keeps more or less to itself.Getting Home AgainSo much for getting into DOS.How do we get home again? The address in vector 21Htook control into DOS, but how does DOS know where to go to pass execution back intoEAT.EXE? Half of the cleverness of software interrupts is knowing how to get there, andthe other half just as clever is knowing how to get back.To get into DOS, a program looks in a completely reliable place for the address of whereit wants to go: the address stored in vector 21H.This address takes execution deep intoDOS, leaving the program sitting above DOS.To continue execution where it left offprior to the INT 21 instruction, DOS has to look in a completely reliable place for thereturn address, and that completely reliable place is none other than the top of the stack.I mentioned earlier (without much emphasis) that the INT 21 instruction pushes anaddress to the top of the stack before it launches off into the unknown.This address is theaddress of the next instruction in line for execution: the instruction immediately followingthe INT 21H instruction.This loca-tion is completely reliable because, just as there is only one interrupt vectortable in the machine, there is only one stack in operation at any one time.This means thatthere is only one top of the stack that is, SS:SP and DOS can always send executionback to the program that called it by popping the address off the top of the stack andfile:///E|/TEMP/Chapter%207%20Our%20Object%20All%20Sublime.htm (27 of 38) [9/30/02 08:34:08 PM]file:///E|/TEMP/Chapter%207%20Our%20Object%20All%20Sublime.htmjumping to that address.The process is shown in Figure 7.5, which is the continuation of Figure 7.4.Justas the INT instruction pushes a return address onto the stack and then jumps to theaddress stored in a particular vector, there is a "combination" instruction that popsthe return address off the stack and then jumps to the address.The instruction isInterrupt RETurn (IRET) and it completes this complex but reliable system ofjumping to an address when you really don't know the address.The trick, onceagain, is knowing where the address can reliably be found.(There's actually a little more to what the software interrupt mechanism pushesonto and pops from the stack, but it happens transparently enough so that I don'twant to complicate the explanation at this point.)This should make it clear by now what happens when you execute the INT 21Hinstruction.EAT.ASM uses DOS services to save it the trouble of writing its string datato the screen a byte at a time.The address into DOS is at a known location in the InterruptVector Table, and the return address is at a known location on the stack.All other software interrupts and there are many operate in the same fashion.In thenext chapter, we'll use a few more, and explore some of the many services availablethrough the BIOS interrupts that control your video display and printerfile:///E|/TEMP/Chapter%207%20Our%20Object%20All%20Sublime.htm (28 of 38) [9/30/02 08:34:08 PM]file:///E|/TEMP/Chapter%207%20Our%20Object%20All%20Sublime.htm.file:///E|/TEMP/Chapter%207%20Our%20Object%20All%20Sublime.htm (29 of 38) [9/30/02 08:34:08 PM]file:///E|/TEMP/Chapter%207%20Our%20Object%20All%20Sublime.htmSoftware Interrupts vs.Hardware InterruptsSoftware interrupts evolved from an older mechanism that did involve some genuinefile:///E|/TEMP/Chapter%207%20Our%20Object%20All%20Sublime.htm (30 of 38) [9/30/02 08:34:08 PM]file:///E|/TEMP/Chapter%207%20Our%20Object%20All%20Sublime.htminterrupting: hardware interrupts.A hardware interrupt is your CPU's mechanism forpaying attention to the world outside itself.There is a fairly complex electrical system built into your PC that allows circuit boards tosend signals to the CPU.An actual metal pin on the CPU chip is moved from one voltagelevel to another by a circuit board device like a disk drive controller or a serial port board.Through this pin the CPU is "tapped on the shoulder" by the external device.The CPUrecognizes this tap as a hard-ware interrupt
[ Pobierz całość w formacie PDF ]