[ Pobierz całość w formacie PDF ]
.In addition to all its other tools, DEBUG also contains a simple assembler, suitable fortaking assembly-language mnemonics like INC DX and converting them to their binarymachine code form.Later on we'll use a standalone assembler like TASM or MASM toassemble complete assembly-language pro-grams.For the time being, we can useDEBUG to do things one or two instructions at a time.Assembling a MOV Instructionfile:///E|/TEMP/Chapter%206%20new.htm (2 of 30) [9/30/02 08:32:40 PM] file:///E|/TEMP/Chapter%206%20new.htmThe single most common activity in assembly-language work is getting data from here tothere.There are several specialized ways to do this, but only one truly general way: theMOV instruction.MOV can move a byte or word of data from one register to another,from a register into memory, or from memory into a register.What MOV cannot do ismove data directly from one address in memory to a different address in memory.The name MOV is a bit of a misnomer, since what is actually happening is that data iscopied from a source to a destination.Once copied to the destina-tion, however, the datadoes not vanish from the source, but continues to exist in both places.This processconflicts a little with our intuitive notion of moving, which usually means that somethingdisappears from a source and reappears at a destination.Because MOV is so general and obvious in its action, it's a good place to start in workingwith DEBUG's assembler.Invoke DEBUG and use the R command to display the current state of the registers.Youshould see something like this:-rAX-0000 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI-0000 DI-0000DS=1980 ES=1980 SS=1980 CS=1980 IP=0100 NV UP El PL NZ NA PO NC1980:0100 701D JO 011FWe ignored the third line of the register display before.Now let's think a little bit moreabout what it means.When DEBUG is loaded without a specific file to debug, it simply takes the emptyregion of memory where a file would have been loaded (had a file been loaded whenDEBUG was invoked) and treats it as though a program file were really there.Theregisters all get default values, most of which are zero.IP, however, starts out with avalue of 0100H, and the code segment register CS gets the segment address of DEBUG'sworkspace, which is theoretically empty.Memory is never really "empty." A byte of memory always contains some value,whether true garbage that happened to reside in memory at power-up time, or a leftovervalue remaining from the last time that byte of memory was used.In the above registerdump, memory at CS:IP contains a JO (jump on overflow) instruction.This ratherobscure instruction was not placed theredeliberately, but is simply DEBUG's interpretation of the two bytes 701DH that happento reside at CS:IP.Most likely, the 701D value was part of some data belonging to thelast program to use that area of memory.It could have been part of a word-processor file,a spreadsheet, or anything else.Just don't that some program necessarily put a JOfile:///E|/TEMP/Chapter%206%20new.htm (3 of 30) [9/30/02 08:32:40 PM] file:///E|/TEMP/Chapter%206%20new.htminstruction in memory.Machineinstructions are just numbers, after all, and what numbers do in memory dependscompletely on how you interpret them and what utility program you feed them to.DEBUG's internal assembler assembles directly into memory, and places instructionsone at a time as you enter them at the keyboard into memory CS:IP.Each time youenter an instruction, IP is incremented to the next free location in memory.So bycontinuing to enter instructions, you can actually type an assembly-language programdirectly into memory.Try it.Type the A (assemble) command and press Enter.DEBUG responds bydisplaying the current value of CS:IP, and then waits for you to enter an assembly-language instruction.Type MOV AX,1 and press Enter.DEBUG again displays CS:IPand waits for a second instruction.It will continue waiting for instructions until you pressEnter without typing anything.Then you'll see DEBUG's dash prompt again.Now, use the R command again to display the registers.You should see something likethis:-rAX=0000 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000DS=1980 ES=1980 SS=1980 CS=1980 IP=0100 NV UP EI PL NZ NA PO NC1980:0100 B80100 MOV AX,0001The registers haven't changed but now the third line shows that the JO instruction isgone, and that the MOV instruction you entered has taken its place.Notice once againthat CS contains 1980H, and IP contains 0100H.The address of the MOV instruction isshown as 1980:0100; in other words, at CS:IP.Executing a MOV Instruction with the Trace CommandNote that you haven't executed anything.You've simply used DEBUG's com-mand towrite a machine instruction into a location in memory.There are two ways to execute machine instructions from within DEBUG.One way is toexecute a program in memory, starting at CS:IP.This means that DEBUG will simplystart the CPU executing whatever sequence of instructions begins at CS:IP.We lookedat the G command very briefly at the end of the last chapter, when we found the JMPinstruction that reboots your PC on power up, and used G to execute that instruction.Thecommand is quite evocative: Go.But don't type G just yet.You haven't entered a program.You've entered one instruction, and one instruction doesnot a program make.The instruction after your MOV instruc-tion could be anything atfile:///E|/TEMP/Chapter%206%20new.htm (4 of 30) [9/30/02 08:32:40 PM] file:///E|/TEMP/Chapter%206%20new.htmall, recalling that DEBUG is simply interpreting garbage values in memory as randommachine instructions.A series of random machine instructions could easily go berserk,locking your system into an endless loop or writing zeroes over an entire segment ofmemory that r contain part of DOS or of DEBUG itself.We'll use DEBUG's Gcommand a little later, once we've constructed a complete program in memory.For now, consider the mechanism DEBUG has for executing one machine instruction ata time.It's called Trace, and you invoke it by typing T.The T command will execute themachine instruction at CS:IP, then give control of the machine back to DEBUG.Traceis generally used to "single-step" a machine-code program one instruction at a time, inorder to watch what it's up to every step of the way.For now, it's a fine way to execute asingle instruction and examine that instruction's effects.DEBUG's G command executes programs in memory starting at CS:IP; DEBUG's Tcommand executes the single instruction at CS:IP.So type T.DEBUG will execute the MOV instruction you entered at CS:IP, and thenimmediately display the registers before returning to the dash prompt [ Pobierz całość w formacie PDF ]
  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • odbijak.htw.pl