Lab_6
Lab_6
Lab: 6
Familiarization with DOS DEBUG Program and Assembly Language Programming
Example Comment
G Execute from IP to the end of the program
G 50 Execute from the IP to CS:50H and stop
G=10 50 Begin execution at offset 10H and stop before offset 50H
6. H (Hex arithmetic): The H command performs addition and subtraction on two hex numbers entered in the following
formats:
H value1 value2
For example H 1A 10 command add and subtract to hex numbers 1A and 10 and display the results as:
002A 000A
7. M (Move): The M command copies a block of data from one memory location to another. The syntax is
M range address
The range consists of the starting and ending locations of the bytes to be copied. Address is the target location, to which the
data will be copied.
Example Comment
M 100 105 110 Move bytes in the range DS:100-105 to location DS:110
M CS:100 105 CS:110 Same as above except that all offsets arc relative to CS
8. P (Ptrace): Execute the next instruction and stop; if the instruction calls a procedure, execute the procedure and then stop.
The LOOP instruction and string primitive instructions (SCAS, LODS etc.) are executed completely up to the next
instruction.
9. R (Register): The R command may be used in one of three ways:
- Display the contents of one of the register, allowing it to be changed.
- Display registers, flags, and the next instruction about to be executed.
- Display the eight flag settings, allowing any or all of them to be changed.
Example Comment
R Display the contents of all registers.
R IP Display the contents of IP and allow it to be modified.
R CX Same for the CX register.
R F Display all flags and change them if desired.
2
Lab Sheet for Microprocessor for BEX/BCT/BEL @ IOE, Pulchowk Campus
10. S (Search): Search a range of addresses for a list of bytes or a string. Syntax:
S range list
Example Comment
S 100 1000 0D Search DS:100 to DS:1000 for the value 0DH
S 100 1000 CD,20 Search for the sequence CD 20
S 100 9FFF COPY Search for the word COPY.
11. T (Trace): Execute one or more instructions from the current CS:IP location or an optional address if specified. The
contents of the registers are shown after each instruction is executed. Syntax
T [=addrcss], [.value]
Example Comment
T Trace one instruction from the current location
T 5 Trace 5 instructions
T =5.10 Start tracing at CS:5 and trace the next 16 steps
This command traces individual loop iterations, so you may want to use it to debug statements within a loop. Also, the T
'command traces into a procedure call.
12. U (Unassemble): The U command translates memory into assembly language mnemonics. This is called unassembling or
disassembling memory. Syntax
U [address) [range]
Example Comment
U Unassemble the next 32 bytes from the current location
U 0 Unassemble 32 bytes from local ion 0
U 100,108 Unassemble all bytes from offset 100H – 108H
13. Q (Quit): Quit from DEBUG program and return to DOS prompt.
Sample program
Start the debug program from DOS prompt and write following lines sequentially
- A 100
- MOV AX,5
- MOV BX,10
- ADD AX,BX
- INT 20 ; To terminate the program
Now run the program in different ways and trace the different registers and segments using different commands as mentioned
above.
Model directive: The model directive selects a standard memory model for your program. It determines the way segments are
linked together, as well as the maximum size of each segment.
Model Description
Tiny Code & data together may not be greater than 64K
Small Neither code not data may be greater than 64K
Medium Only the code may be greater than 64K
Compact Only the data may be greater than 64K
Large Both code & data may be greater than 64K
Huge All available memory may be used for code & data
Program Segments: Three segment directives are normally used, .stack, .code and .data. They may be placed in any order
within a program. The .stack and .data directives define the size of stack and start of data segment respectively, and .code
directive identifies the start of code (instructions) in a program.
4
Lab Sheet for Microprocessor for BEX/BCT/BEL @ IOE, Pulchowk Campus
Assembling and Linking: Before we assemble and link a program (*.asm file), the following programs should be present.
MASM.EXE
LINK.EXE
Assemble the program: Let a sample program has been created using a text editor and saved to disk as SUM.ASM. To assemble
it we have to type
MASM SUM.ASM
Then MASM displays the number of errors if any. If there are no errors then it creates an intermediate file SUM.OBJ
Link the program: in this step, the linker reads the object file as input and creates an executable file SUM.EXE. The command
is
LINK SUM.OBJ
Create a source program given below using a text editor and compile, link & execute the program
TITLE to add two numbers
.MODEL SMALL
.STACK 32
.DATA
VAL1 DW 1234H
VAL2 DW 2345H
SUM DW ?
.CODE
MAIN PROC FAR
MOV AX,@DATA
MOV DS,AX
MOV AX,VAL1
ADD AX,VAL2
MOV SUM,AX
MOV AX,4C00H
INT 21H
MAIN ENDP
END MAIN
You can use the DOS DEBUG program to unassamble and check the program’s execution. After compiling and linking the
above program, load the SUM.EXE into the DOS DEBUG as
DEBUG SUM.EXE
Now you will see the DEBUG prompt as
-
Unassamble the above program with the U command as
-U
Explain what you see in the screen.
Use other DEBUG program to check the validity of the result.
Assignments:
1. Write an assembly language program to sum numbers from 0 to 255.
2. Write an assembly language program to add ten 16-bit numbers stored in memory and store the result.
3. There are two tables having ten 16-bit data in each. Write an assembly language program to generate the third table
which contains the sum of corresponding element of first and second table.
4. Two tables of data are stored having ten 16-bit data each. Write an assembly language program to generate the third
table which contains 1FFFH if the corresponding data in first table is less then that of second table, else store 0000.
5. Write a program to generate and store a multiplication table of a number stored as num1
6. Write a program to find the sum of the following series up to 20 terms and store the result
2 x 3 + 4 x 5 + … to 20 terms
Assemble all these programs and check the validity of the result with the DOS DEBUG program.