Registers



Debug was first written to instruct the 8086 family of processors. A basic understanding of the processor's registers is necessary to write programs and create data files. The Debug R command displays and edits the contents of these registers. For simple programs that we will deal with here, only a few of them will be introduced.

The contents of the registers may be displayed undef Debug with the R command. On the - prompt, type r and ENTER.
The register contents will be displayed.


-R
AX=0000  BX=0000  CX=0000  DX=0000  SP=FFEE  BP=0000  SI=0000  DI=0000
DS=0AFA  ES=0AFA  SS=0AFA  CS=0AFA  IP=0100   NV UP EI PL NZ NA PO NC
0AFA:0100 05C646        ADD     AX,46C6


The first four registers; AX, BX, CX and DX are the ones that we will be most interested in for simple programs. They are general purpose 16 bit registers. These are the ones that we will use most to provide arguments to the DOS interupts. Knowing what can be done with them is also helpful. For example, a numeric value from 0000 to FFFF can be loaded into any of them.

Additionally, their high hits and low bits can be edited using processor instructions but not directly with the R command. The high bits of the AX register can be addressed as AH and the low bits may be addressed as AL. This is true of the BX, CX and DX registers as well.



A quick explaination of the information that the R display tells us about the status of our processor chip.


SP=FFEE  BP=0000  SI=0000  DI=0000
The SP (stack pointer) points to the highest memory locations in the segment.
The BP ( base pointer), SI (source index), DI (destination index) default to 0000.



DS=0AFA  ES=0AFA  SS=0AFA  CS=0AFA
The DS, ES, SS and CS (segment registers)  are in respect to the memory segment used. 0AFA is the segment of memory used in this example.



IP=0100
The IP (instruction pointer) begins at location 0100 of the selected segment. This is where the program will begin execution with the GO command. More about this when we step through a program later. The first FF locations have their own purpose with a COM program. Program execution actully begins at the location 0100 of the selected segment.



NV UP EI PL NZ NA PO NC
The state of the flags, overflow (NV) through carry (NC) are of interest when operations are performed on these registers.
The last line displays the memory location of the beginning of the program.



0AFA:0100 05C646        ADD     AX,46C6
0AFA:0100 This address defines the memory segment and the instruction pointer.
05C64  Three bytes define the instruction and the argument. 05 is the instruction and C6 46 is the argument.
ADD AX,46C6  This is the Assembler name for the instruction which adds 46C6 to the AX register.



Lets examine the R instruction using the general registers. In the above example, they are all set to zero.
AX=0000  BX=0000  CX=0000  DX=0000
The contents of all four registers are set to zero. We can examine each register independently.

-R AX     the contents of the AX register will be displayed.
0000      the contents of the AX register is 0000
:            the colon invites us to change it. Close the ENTER key to leave it as it is.
-            the prompt invites us to issue another instruction.

Until now, the R instruction has been passive, only reading. We are going to go active and change the register's contents.
again: our entry is in red and the returned display is in green. remarks are in default black.

-R AX    display the contents of the AX register.
0000      the contents is displayed.
:0123     change it to 0123 hex
-            again the prompt invites is to the next instruction.

-R BX    edit the B, C and D registers.
0000
:4567
-

-RCX    edit the C register.
0000
:89AB
-

-R DX    edit the D register.
0000
:CDEF
-




note that the contents of the AX, BX, CX and DX registers have been altered as we redifined their contents.
-R
AX=0123  BX=4567  CX=89AB  DX=CDEF  SP=FFEE  BP=0000  SI=0000  DI=0000
DS=0AFA  ES=0AFA  SS=0AFA  CS=0AFA  IP=0100   NV UP EI PL NZ NA PO NC
0AFA:0100 05C646        ADD     AX,46C6



Summary

Calling Debug from Windows, permits us to make programs and see what the processor's regesters would do. Debug, under Windows is an emulation of processor activity, not actually what the processor is doing. This type of emulation is sometimes called a "Processor Developement Aid". The real processor is happily doing its Processor thing, while Debug is pretending to be a real Processor. The Processor Developement Aid can still create executable programs that will run under the processor it was written for.

Debug permits us to examine the register state during any part of the program that is being developed. This is extremely valuable during developement of a program. Low level programming demands that the programmer know exactly what is going on with the program and its affects on the processor that will execute the program after it has been committed to a file for execution. Debug does a fine job of doing just that for us.

Here is an example of where Debug may be extremely useful as a MicroProcessor Development Aid. Using any number of Assemblers, a short program may be assembled, but it isn't doing as expected. Editing need be done by changing the source code, and re-assembling it again. Then running the program to see if it is corrected. Its very nice to be able to open the executable with Debug and step it through with the G or T function and examine the register activity with the R function. When it works as expected, then the code that is necessary for the Assembler source program is known, and can be corrected. Big time saver.