[ Pobierz całość w formacie PDF ]
.In the middle is a resting-point called object code that we'll take up a little later.The process of creating true machine-code programs is one of translation.You must start with something that you and the rest of us can read andunderstand, and then somehow convert that to something the CPU can understand andexecute.Before examining either end of that road, however, we need to understand alittle more about the land on which the road is built.The God Above, the Troll BelowMost of all, we need to understand DOS.Some people look upon DOS as a god; othersas a kind of troll.In fact, DOS is a little of both.Mostly what you must put behind you isfile:///E|/TEMP/Chapter%203%20The%20Right%20To%20Assemble.htm (3 of 39) [9/30/02 08:29:46 PM]file:///E|/TEMP/Chapter%203%20The%20Right%20To%20Assemble.htmthe common notion that DOS is a part of the machine itself and somehow resides in thesame sort of silicon as the CPU.Not so! DOS is a computer program of an only slightlyspecial nature, called an operating system.In part, an operating system is a collection of routines that do nothing but serve thecomponents of the computer itself.By components I mean things like disk drives,printers, and so on.DOS acts something like a troll living under the bridge to your diskdrive.You tell the troll what you want to do with the disk drive, and the troll does it, bisway, and at some cost (in machine cycles) to you.You could write a program to handle every little aspect of disk operation itself (manygame programs do exactly that) but it would be more trouble than it's worth, becauseevery program that runs on a computer needs to access the disk drives.And regardless ofhow grumpy the troll is, he does get the job done, and (assuming your disk drives aren'tfalling-down damaged) does it right every time.Can you guarantee that you know allthere is to know about running a disk drive? Forgive me if I have my doubts.That is, inmy opinion, what trolls are for.The other (and more interesting thing) that operating systems do is run programs.It ishere that DOS seems more godlike than troll-like.When you want to run a program onyour computer, you type its name at the DOS command line.DOS goes out and searchesone or more disk drives for the named program, loads it into memory at a convenientspot, sets the instruction pointer to the start of the program, and boots the CPU in the rearto get it going.DOS then patiently waits for the program to run its course and stop.When the programstops, it hands the CPU obediently back to DOS, which again tilts a hand to its ear andlistens for your next command from the command line.So as programmers, we use DOS two ways: one is as a sort of toolkit; an army of trolls,each of which can perform some service for your program, saving your program thateffort.The other is as a means of loading a program into memory and getting it going,and then catching the machine gracefully on the rebound when your program is through.I'll be mentioning DOS again and again in this book.Everywhere you look in assemblylanguage, you're going to see the old troll's face.Get used to it.DOS Files: Magnetic MemoryVery simply, DOS files are memory banks stored on a magnetic coating rather thaninside silicon chips.A DOS file contains some number of bytes, stored in a specificorder.One difference from RAM memory is that DOS files stored on disk are sequential-file:///E|/TEMP/Chapter%203%20The%20Right%20To%20Assemble.htm (4 of 39) [9/30/02 08:29:46 PM]file:///E|/TEMP/Chapter%203%20The%20Right%20To%20Assemble.htmaccess memory banks.A disk (floppy or hard) is a circular platform coated with magnetic plastic of some sort.In a floppy disk drive, the platform is a flexible disk of tough plastic; in a hard disk theplatform is a rigid platter of aluminum metal.Data is stored as little magneticdisturbances on the plastic coating in a fashion similar to that used in audio cassettes andVCRs.A sensor called a read/write head sits very close beside the rotating platform, andwaits for the data to pass by.A simplified illustration of a rotating disk device is shown in Figure 3.1.The area of thedisk is divided into concentric circles called tracks.The tracks are further dividedradially into sectors.A sector (typically containing 512 bytes) is the smallest unit ofstorage that can be read from or written to at one time.A DOS disk file consists of one ormore sectors containing the file's data.The read/write head is mounted on a sliding shaft that is controlled by a solenoidmechanism.The solenoid can move the head horizontally to position the head over aspecific track.(In Figure 3.1, the head is positioned over track 2 counting from 0,remember!) However, once the head is over a particular track, it has to count sectors untilthe sector it needs passes beneath it.The tracks can be accessed at random, just like bytesin the computer's memory banks, but the sectors within a track must be accessedsequentially.Perhaps the single most valuable service DOS provides is handling the headaches ofdistributing data onto empty sectors on a disk.Programs can hand sectors of data toDOS,file:///E|/TEMP/Chapter%203%20The%20Right%20To%20Assemble.htm (5 of 39) [9/30/02 08:29:46 PM]file:///E|/TEMP/Chapter%203%20The%20Right%20To%20Assemble.htmone at a time, and let DOS worry about where on the disk they can be placed.Each sectorhas a number, and DOS keeps track of what sectors belong together as a file.The firstsector in a file might be stored on track 3, sector 9; the second sector might be stored ontrack 0, sector 4, and so on.You don't have to worry about that.When you ask for sector0 of your file, DOS looks up its location in its private tables, goes directly to track 3,sector 9 and brings the sector's data back to you.Binary FilesThe data that is stored in a file is just binary bytes and can be anything at all.Files likethis, where there are no restrictions on the contents of a file, are called binary files,because they can legally contain any binary code.Like all files, a binary file consists ofsome whole number of sectors, with each sector (typi-cally) containing 512 bytes.Theleast space any file can occupy on your disk is 512 bytes; when you see the DOS DIRcommand tell you that a file has 17 bytes it in, that's the count of how many bytes arestored in that file.But like a walk-in closet with only one pair of shoes in it, the rest ofthe sector is still there, empty but occupying space on the disk.file:///E|/TEMP/Chapter%203%20The%20Right%20To%20Assemble.htm (6 of 39) [9/30/02 08:29:46 PM]file:///E|/TEMP/Chapter%203%20The%20Right%20To%20Assemble.htmA binary file has no structure, but is simply a long series of binary codes divided intonumbered groups of 512 and stored out on disk in a scheme that is best left to DOS tounderstand
[ Pobierz całość w formacie PDF ]