Ics 232 Lab 1
Ics 232 Lab 1
Ics 232 Lab 1
Debug can only create files with a .COM extension, and because of the characteristics of
these kinds of programs they cannot be larger that 64 kb, and they also must start with
displacement, offset, or 0100H memory direction inside the specific segment.
Debug provides a set of commands that lets you perform a number of useful operations:
It is possible to visualize the values of the internal registers of the CPU using the Debug
program. To begin working with Debug, type the following prompt in your computer:
C:/>Debug [Enter]
On the next line a dash will appear, this is the indicator of Debug, at this moment the
instructions of Debug can be introduced using the following command:
1
-r[Enter]
All the contents of the internal registers of the CPU are displayed; an alternative of
viewing them is to use the "r" command using as a parameter the name of the register
whose value wants to be seen. For example:
-rbx
BX 0000
:
This instruction will only display the content of the BX register and the Debug indicator
changes from "-" to ":"
When the prompt is like this, it is possible to change the value of the register which was
seen by typing the new value and [Enter], or the old value can be left by pressing [Enter]
without typing any other value.
CPU Registers
The 8086 CPU is 16 bit processor, which has 4 internal registers, each one of 16 bits. The
first four, AX, BX, CX, and DX are general use registers and can also be used as 8 bit
registers, if used in such a way it is necessary to refer to them for example as: AH and
AL, which are the high and low bytes of the AX register. This nomenclature is also
applicable to the BX, CX, and DX registers.
BX Base register :
-Can hold the address of a procedure or variable (SI, DI, and BP can also).
-Can also perform arithmetic and data movement.
DX Data register : holds the high 16 bits of the product in multiply (also handles
divide operations)
2
DS Data Segment register : default base location for variables
CS Code Segment register: holds base location for all executable instructions in a
program.
BP Base Pointers register : contains an assumed offset from the SS register. Often
used by a subroutine to locate variables that were passed on the stack by a calling
program.
SI Source Index register : Used in string movement instructions. The source string is
pointed to by the SI register.
SP Stack pointer register: Contains the offset of the top of the stack.
IP Next Instruction Pointer register: contains the offset of the next instruction to be
executed.
F Flag register: individual bit positions within register show status of CPU or results
of arithmetic operations.
Assembler structure
In assembly language code lines have two parts, the first one is the name of the
instruction which is to be executed, and the second one are the parameters of the
command. For example:
add ah,bh
Here "add" is the command to be executed; in this case an addition, and "ah" as well as
"bh" are the parameters.
For example:
mov al, 25
In the above example, we are using the instruction mov, it means move the value 25 to al
register.
3
The name of the instructions in this language is made of two, three or four letters. These
instructions are also called mnemonic names or operation codes, since they represent a
function the processor will perform.
add al,[170]
The brackets in the second parameter indicate to us that we are going to work with the
content of the memory cell number 170 and not with the 170 value, this is known as
direct addressing.
The first step is to initiate the Debug, this step only consists of typing debug[Enter] on
the operative system prompt.
To assemble a program on the Debug, the "a" (assemble) command is used; when this
command is used, the address where you want the assembling to begin can be given as a
parameter, if the parameter is omitted the assembling will be initiated at the locality
specified by CS:IP, usually 0100h, which is the locality where programs with .COM
extension must be initiated. And it will be the place we will use since only Debug can
create this specific type of programs.
Even though at this moment it is not necessary to give the "a" command a parameter, it is
recommendable to do so to avoid problems once the CS:IP registers are used, therefore
we type:
a 100[enter]
mov ax,0002[enter]
mov bx,0004[enter]
add ax,bx[enter]
nop[enter][enter]
What does the program do?, move the value 0002 to the ax register, move the value 0004
to the bx register, add the contents of the ax and bx registers, the instruction, no
operation, to finish the program. In the debug program, after this is done, the screen will
produce the following lines:
C:\>debug
-a 100
0D62:0100 mov ax,0002
0D62:0103 mov bx,0004
0D62:0106 add ax,bx
0D62:0108 nop
0D62:0109
4
Type the command "t" (trace), to execute each instruction of this program, example:
-t
You see that the value 2 moves to AX register. Type the command "t" (trace), again, and
you see the second instruction is executed.
-t
Type the command "t" (trace) to see the instruction add is executed, you will see the
follow lines:
-t
The possibility that the registers contain different values exists, but AX and BX must be
the same, since they are the ones we just modified. To exit Debug use the "q" (quit)
command.
It would not seem practical to type an entire program each time it is needed, and to avoid
this it is possible to store a program on the disk, with the enormous advantage that by
being already assembled it will not be necessary to run Debug again to execute it.
3. Put the length of the program on the CX register and order Debug to write the
program on the disk.
5
When the program is finally assembled it would look like this:
0C1B:0100 mov ax,0002
0C1B:0103 mov bx,0004
0C1B:0106 add ax,bx
0C1B:0108 int 20
0C1B:010A
To obtain the length of a program the "h" command is used, since it will show us the
addition and subtraction of two numbers in hexadecimal. To obtain the length of ours, we
give it as parameters the value of our program's final address (10A), and the program's
initial address (100). The first result the command shows us is the addition of the
parameters and the second is the subtraction.
-h 10a 100
020a 000a
-n test.com
The "rcx" command allows us to change the content of the CX register to the value we
obtained from the size of the file with "h", in this case 000a, since the result of the
subtraction of the final address from the initial address.
-rcx
CX 0000
:000a
Lastly, the "w" command writes our program on the disk, indicating how many bytes it
wrote.
-w
Writing 000A bytes
To obtain the correct result of the following steps, it is necessary that the above program
be already created.
6
-n test.com
-l
-u 100 109
0C3D:0100 B80200 MOV AX,0002
0C3D:0103 BB0400 MOV BX,0004
0C3D:0106 01D8 ADD AX,BX
0C3D:0108 CD20 INT 20
The last "u" command is used to verify that the program was loaded on memory. What it
does is that it disassembles the code and shows it disassembled. The parameters indicate
to Debug from where and to where to disassemble. Debug always loads the programs on
memory on the address 100H, otherwise indicated.
Activity 1.1: Enter the following program instructions in assembly code at the offset
memory location 100h by typing A 100 at the DEBUG program prompt then press
Enter-key.
Activity 1.2: Use DEBUG command U 100 to unassembled the instructions in Activity
1.1. What is the machine code corresponding to each assembly code instruction?
Activity 1.3: How many bytes does it need to represent each instruction in binary?
7
Register Content
CS
IP
AX
BX
Activity 1.5: Predict the contents of the following registers after execution of each
instruction: CS, IP, AX, and BX.
Register MOV AX, 2864 ADD AX, 3749 MOV BX, AX SUB BX, 2805
CS
IP
AX
BX
8
Debug Flag symbols
Status Flag Set (1) Symbol Clear (0) Symbol
CF CY(Carry) NC(No carry)
PF PE (Even parity) PO (odd parity)
AF AC(Auxiliary carry) NA (No Auxiliary carry)
ZF ZR(zero) NZ(No zero)
SF NG(negative) PL (plus)
OF OV(Overflow) NV(no overflow)
Control Flags
DF DN(Down) UP(up)
IF EI(Enable Interrupt) DI(disable interrupt)
Notes:
- Carry (CF) – set when the result of an unsigned arithmetic operation is too
large to fit into the destination.