Make your own free website on Tripod.com

Table of Contents

Debug Program examples
Assembler program examples

Debug program examples

You find in this section eleven tested debug programs.
You can execute each assembler program using the "g" (go) command, to see what each debug program does.

Procedure

First step

Load the debug program example

For example:

C:\>debug
-n one.com
-l
-u 100 109
0D80:0100 B80600        MOV     AX,0006
0D80:0103 BB0400        MOV     BX,0004
0D80:0106 01D8          ADD     AX,BX
0D80:0108 CD20          INT     20
-

Note:

-n one.com

It means the name of the program to load it

-l

It means load it

-u 100 109

It means unassemble it from starting address to final address

Second step

Type the g command
For example:

-g


Program terminated normally
-

Debug program examples

First example

-a0100
297D:0100     MOV     AX,0006        ; Puts value 0006 at register AX
297D:0103     MOV     BX,0004        ;Puts value 0004 at register BX
297D:0106     ADD     AX,BX        ;Adds BX to AX contents
297D:0108      INT     20         ;Causes end of the Program

The only thing that this program does is to save two values in two registers and add the value of one to the other.

Go to the page menu

Second example

- a100 
0C1B:0100 jmp 125 ; Jumps to direction 125H 
0C1B:0102 [Enter] 
- e 102  'Hello, How are you ?' 0d 0a '$' 
- a125 
0C1B:0125 MOV DX,0102 ; Copies string to DX register 
0C1B:0128 MOV CX,000F ; Times the string will be displayed 
0C1B:012B MOV AH,09 ; Copies 09 value to AH register 
0C1B:012D INT 21 ; Displays string 
0C1B:012F DEC CX ; Reduces in 1 CX 
0C1B:0130 JCXZ 0134 ; If CX is equal to 0 jumps to 0134 
0C1B:0132 JMP 012D ; Jumps to direction 012D 
0C1B:0134 INT 20 ; Ends the program

This program displays on the screen 15 times a character string.

Go to the page menu

Third example

-a100
297D:0100       MOV     AH,01    ;Function to change the cursor
297D:0102       MOV     CX,0007 ;Forms the cursor
297D:0105       INT     10 ;Calls for BIOS
297D:0107       INT     20 ;Ends the program

This program is good for changing the form of the cursor.

Go to the page menu

Fourth example

-a100
297D:0100         MOV     AH,01 ; Function  1 (reads keyboard)
297D:0102         INT     21 ; Calls for DOS
297D:0104        CMP     AL,0D ; Compares if what is read is a carriage return
297D:0106        JNZ     0100 ; If it is not, reads another character
297D:0108        MOV     AH,02 ; Function 2 (writes on the screen)
297D:010A       MOV     DL,AL ; Character to write on AL
297D:010C       INT     21 ; Calls for DOS
297D:010E       INT     20 ; Ends the program

This program uses DOS 21H interruption. It uses two functions of the same: the first one reads the keyboard (function 1) and the second one writes on the screen. It reads the keyboard characters until it finds a carriage return.

Go to the page menu

Fifth example

-a100
297D:0100       MOV     AH,02 ;  Function 2 (writes on the screen)
297D:0102       MOV     CX,0008 ; Puts value 0008 on register CX
297D:0105       MOV     DL,00 ;  Puts value 00 on register DL
297D:0107      RCL     BL,1 ;   Rotates the byte in BL to the left by one bit through the                                          ;carry flag
297D:0109      ADC     DL,30 ; Converts flag register to 1
297D:010C      INT     21 ; Calls for DOS
297D:010E      LOOP    0105 ; Jumps if CX > 0  to direction 0105
297D:0110       INT     20 ; Ends the program

This program displays on the screen a binary number through a conditional cycle (LOOP) using byte rotation.

Go to the page menu

Sixth example

-a100
297D:0100       MOV     AH,02 ; Function 2 (writes on the screen)
297D:0102       MOV     DL,BL ; Puts BL's value on DL
297D:0104       ADD     DL,30 ; Adds value 30 to DL
297D:0107       CMP     DL,3A ; Compares 3A value with DL's contents without affecting                           ; its value only modifying the state of the carry flag
297D:010A      JL      010F ; jumps if 

This program prints a zero value on hex digits

Go to the page menu

Seventh example

-a100
297D:0100      MOV     AH,02 ; Function 2 (writes on the screen)
297D:0102      MOV     DL,BL ;  Puts BL value on DL
297D:0104      AND     DL,0F ;  Carries ANDing numbers bit by bit 
297D:0107      ADD     DL,30 ; Adds 30 to Dl
297D:010A     CMP     DL,3A ;  Compares Dl with 3A
297D:010D      JL      0112 ; Jumps if <0112 direction 297D:010F ADD DL, 07 ; Adds 07 to DL 297D:0112 INT 21 ; Calls for DOS 297D:0114 INT 20 ;Ends the program 
This program is used to print two digit hex numbers. Go to the page menu

Eight example

-a100
297D:0100       MOV     AH,02 ; Function 2 (writes on the screen)
297D:0102       MOV     DL,BL ; Puts BL value on DL
297D:0104       MOV     CL,04 ;  Puts 04 value on CL  
297D:0106       SHR     DL,CL ;  Moves upper four bits of your number to the rightmost                                          ;nibble
297D:0108       ADD     DL,30 ; Adds  30 to DL
297D:010B      CMP     DL,3A ; Compares Dl with 3A
297D:010E       JL      0113 ; Jumps if <0113 direction 297D:0110 ADD DL,07 ; Adds 07 to DL 297D:0113 INT 21 ; Calls for DOS 297D:0115 INT 20 ; Ends the program 
This program works for printing the first of two digit hex numbers Go to the page menu

Ninth example


-a100
297D:0100      MOV     AH,02 ; Function 2 (writes on the screen)
297D:0102      MOV     DL,BL ; Puts BL value on DL
297D:0104      MOV     CL,04 ; Puts 04 value on CL
297D:0106      SHR     DL,CL ; Moves upper four bits of your number to the rightmost                                            ;nibble
297D:0108      ADD     DL,30 ; Adds 30 to DL
297D:010B      CMP     DL,3A ; Compares Dl with 3A
297D:010E      JL      0113 ; Jumps if <0113 direction 297D:0110 ADD DL,07 ; Adds 07 to DL 297D:0113 INT 21 ; Calls for Dos 297D:0115 MOV DL,BL ; Puts Bl value on DL 297D:0117 AND DL,0F ; Carries ANDing numbers bit by bit 297D:011A ADD DL,30 ; Adds 30 to DL 297D:011D CMP DL,3A ; Compares Dl with 3A 297D:0120 JL 0125 ; Jumps if < 125 direction 297D:0122 ADD DL,07 ; Adds 07 to DL 297D:0125 INT 21 ; Calls for Dos 297D:0127 INT 20 ; Ends the Program 
This program works for printing the second of two digit hex numbers Go to the page menu

Tenth example

-a100
297D:0100       MOV     AH,01 ; Function 1 (reads keyboard)
297D:0102       INT     21 ; Calls for  Dos
297D:0104       MOV     DL,AL ; Puts Al value on DL
297D:0106       SUB     DL,30 ;  Subtracts 30 from DL
297D:0109       CMP     DL,09 ; Compares DL with 09
297D:010C       JLE     0111;  Jumps if <= 0111 direction 297D:010E SUB DL,07 ; Subtracts 07 from DL 297D:0111 MOV CL,04 ; Puts 04 value on CL register 297D:0113 SHL DL,CL ; It inserts zeros to the right 297D:0115 INT 21 ; Calls for Dos 297D:0117 SUB AL,30 ; Subtracts 30 from AL 297D:0119 CMP AL,09 ; Compares AL with 09 297D:011B JLE 011F ; Jumps if <= 011f direction 297D:011D SUB AL,07 ; Subtracts 07 from AL 297D:011F ADD DL,AL ; Adds Al to DL 297D:0121 INT 20 ; Ends the Program 
This program can read two digit hex numbers Go to the page menu

Eleventh example

-a100 
297D:0100      CALL    0200 ;  Calls for a procedure
297D:0103      INT     20 ;Ends the program

-a200
297D:0200      PUSH    DX ;  Puts DX value on the stack
297D:0201      MOV     AH,08 ; Function 8
297D:0203      INT     21 ; Calls for Dos
297D:0205      CMP     AL,30 ; Compares AL with 30
297D:0207      JB      0203 ; Jumps if CF is activated towards 0203 direction
297D:0209     CMP     AL,46 ; Compares AL with 46
297D:020B     JA      0203 ; jumps if <> 0203 direction
297D:020D    CMP     AL,39 ; Compares AL with 39
297D:020F     JA      021B ; Jumps if <> 021B direction
297D:0211     MOV     AH,02 ; Function 2 (writes on the screen)
297D:0213     MOV     DL,AL ; Puts Al value on DL
297D:0215     INT     21 ; Calls for Dos
297D:0217     SUB     AL,30 ; Subtracts 30 from AL
297D:0219     POP     DX ;  Takes DX value out of the stack
297D:021A    RET ; Returns control to the main program
297D:021B    CMP     AL,41 ; Compares AL with 41
297D:021D    JB      0203 ; Jumps if CF is activated towards 0203 direction
297D:021F     MOV     AH,02 ; Function 2 (writes on the screen)
297D:022       MOV     DL,AL ; Puts AL value on DL
297D:0223     INT     21 ; Calls for Dos
297D:0225     SUB     AL,37 ; Subtracts 37 from AL
297D:0227     POP     DX ; Takes DX value out of the stack
297D:0228     RET ; Returns control to the main program
This program keeps reading characters until it receives one that can be converted to a hex number

Go to the page menu

More assembler programs

In this section we provide you several assembler program examples to run in the Assembler program.

Procedure

To run the assembler programs, you follow the following lines:

First step

Assemble the program
For example:

C:\>tasm one.asm
Turbo Assembler  Version 2.0  Copyright (c) 1988, 1990 Borland International

Assembling file:   one.asm
Error messages:    None
Warning messages:  None
Passes:            1
Remaining memory:  471k

C:\>

This process creates a object program with the same name, in this case will be: one.obj

Second step

Create the executable program
For example:

C:\>tlink one.obj
Turbo Link  Version 3.0 Copyright (c) 1987, 1990 Borland International

C:\>

This process creates the executable program with the same name but different extension, one.exe

Third step

Run the executable program, you just type the name of the program.

Assembler programs

First example

;name of the program:one.asm
;
.model small
.stack
.code
        mov AH,1h       ;Selects the 1  D.O.S. function 
        Int 21h         ;reads character and return ASCII code to register AL
        mov DL,AL       ;moves the ASCII code to register DL
        sub DL,30h      ;makes the operation minus 30h to convert 0-9 digit number
        cmp DL,9h       ;compares if digit number it was between 0-9
        jle digit1      ;If it true gets the first number digit (4 bits long)
        sub DL,7h       ;If it false, makes operation minus 7h to convert letter A-F 
digit1:
        mov CL,4h       ;prepares to multiply by 16 
        shl DL,CL       ; multiply to convert into four bits upper 
        int 21h         ;gets the next character 
        sub AL,30h      ;repeats the conversion operation 
        cmp AL,9h       ;compares the value 9h with the content of register AL 
        jle digit2      ;If true, gets the second digit number 
        sub AL,7h       ;If no, makes the minus operation 7h 
digit2:
        add DL,AL       ;adds the second number digit 
        mov AH,4CH
        Int 21h         ;21h interruption
        End; finish the program code

This program reads two characters and prints them on the screen

Go to the page menu

Second example

;name of the program:two.asm
.model small
.stack
.code
PRINT_A_J       PROC
        MOV DL,'A'  ;moves the A character to register DL
        MOV CX,10   ;moves the decimal value 10 to register cx
		        ;This number value its the time to print out after the A 				        ;character
PRINT_LOOP:
        CALL WRITE_CHAR ;Prints A character out
        INC DL          ;Increases the value of register DL
        LOOP PRINT_LOOP ;Loops to print out ten characters
        MOV AH,4Ch      ;4Ch function of the 21h interruption 
        INT 21h         ;21h interruption
PRINT_A_J       ENDP    ;Finishes the procedure

WRITE_CHAR      PROC
        MOV AH,2h   ;2h function of the 21 interruption 
        INT 21h     ;Prints character out from the register DL
        RET         ;Returns the control to procedure called
WRITE_CHAR      ENDP     ;Finishes the procedure
        END  PRINT_A_J   ;Finishes the program code

This program shows ABCDEFGHIJ characters on the screen

Go to the page menu

Third example

;name of the program:three.asm
.model small
.STACK
.code

TEST_WRITE_HEX    PROC
        MOV DL,3Fh     ;moves the value 3Fh to the register DL
        CALL WRITE_HEX ;Calls the procedure
        MOV AH,4CH     ;4Ch function
        INT 21h        ;Returns the control to operating system
TEST_WRITE_HEX ENDP    ;Finishes the procedure


        PUBLIC WRITE_HEX
;........................................................;
; This procedure converts into hexadecimal number the byte is in the register DL and shows the digit number; 
;Use:WRITE_HEX_DIGIT                                 ;
;........................................................;

WRITE_HEX    PROC
        PUSH CX     ;pushes the value of the register CX to the stack memory
        PUSH DX     ;pushes the value of the register DX to the stack memory
      MOV DH,DL   ;moves the value of the register DL to register DH
        MOV CX,4    ;moves the value numeric 4 to register CX
        SHR DL,CL   
        CALL WRITE_HEX_DIGIT ;shows on the computer screen, the first hexadecimal number
        MOV DL,DH   ;moves the value of the register DH to the register DL
        AND DL,0Fh  ;ANDing the upper bit
        CALL WRITE_HEX_DIGIT ; shows on the computer screen, the second hexadecimal number
        POP DX      ;pops the value of the register DX to register DX
        POP CX      ; pops the value of the register DX to register DX
        RET         ;Returns the control of the procedure called
WRITE_HEX  ENDP


        PUBLIC WRITE_HEX_DIGIT
;......................................................................;
;                                                                      ;
; This procedure converts the lower 4 bits of the register DL into hexadecimal ;number and shows them in the computer screen    ;
;Use: WRITE_CHAR                                                   ;
;......................................................................;

WRITE_HEX_DIGIT    PROC
        PUSH DX     ;Pushes the value of the register DX in the stack memory
        CMP DL,10   ;compares if the bit number is minus than number ten
        JAE HEX_LETTER  ;No , jump HEX_LETER
        ADD DL,"0"  ;yes, it converts into digit number
        JMP Short WRITE_DIGIT ;writes the character
HEX_LETTER:
        ADD DL,"A"-10 ;converts a character into hexadecimal number
WRITE_DIGIT:
        CALL WRITE_CHAR ;shows the character in the computer screen
        POP DX      ;Returns the initial value of the register DX to register DL
        RET         ;Returns the control of the procedure called
WRITE_HEX_DIGIT   ENDP



        PUBLIC WRITE_CHAR
;......................................................................;
;This procedure shows the character in the computer screen using the D.O.S. ;
;......................................................................;

WRITE_CHAR   PROC
        PUSH AX   ;pushes the value of the register AX in the stack memory
        MOV AH,2  ;2h Function
        INT 21h   ;21h Interruption
        POP AX    ;Pops the initial value of the register AX to the register AX
        RET       ;Returns the control of the procedure called
WRITE_CHAR   ENDP

        END TEST_WRITE_HEX ;finishes the program code 

Go to the page menu

Fourth example

;name of the program:four.asm
.model small
.stack
.code


TEST_WRITE_DECIMAL    PROC
        MOV DX,12345   ;moves the decimal number  12345 to register DX
        CALL WRITE_DECIMAL ;Calls the procedure
        MOV AH,4CH   ;4Ch function
        INT 21h      ;21h interruption
TEST_WRITE_DECIMAL ENDP    ;Finishes the procedure



        PUBLIC WRITE_DECIMAL
;.................................................................;
;This procedure writes 16 bit number is a unsigned number in decimal notation ;
;Use: WRITE_HEX_DIGT                                          ;
;.................................................................;

WRITE_DECIMAL    PROC
        PUSH AX   ;Pushes the value of the register AX to the stack memory
        PUSH CX; Pushes the value of the register CX to the stack memory
        PUSH DX; Pushes the value of the register DX to the stack memory
        PUSH SI; Pushes the value of the register SI to the stack memory
        MOV AX,DX ;moves the value of the register DX to AX
        MOV SI,10 ;moves the value 10 to register SI
        XOR CX,CX ;clears the register  CX
NON_ZERO:
        XOR DX,DX ;clears the register DX
        DIV SI    ;divides operation between SI
        PUSH DX   ;Pushes one digit number in the stack memory
        INC CX    ;increases CX
        OR AX,AX  ;no zero
        JNE NON_ZERO  ; jumps  NON_ZERO
WRITE_DIGIT_LOOP:
        POP DX    ;Returns the value in reverse mode
        CALL WRITE_HEX_DIGIT  ;Calls the procedure
        LOOP WRITE_DIGIT_LOOP ;loop 
END_DECIMAL:
        POP SI;pops the value of the register SI to register SI
        POP DX;pops the value of the register DX to register DX
        POP CX;pops the value of the register CX to register CX
        POP AX; pops the value of the register AX to register AX
        RET       ;Returns the control to procedure called
WRITE_DECIMAL   ENDP ;Finishes the procedure

        PUBLIC WRITE_HEX_DIGIT
;......................................................................;
;                                                                      ;
; This procedure converts the lower 4 bits  of the register DL into;
;hexadecimal number and prints them out ;
;Use: WRITE_CHAR                                                   ;
;......................................................................;

WRITE_HEX_DIGIT    PROC
        PUSH DX     ;Pushes the value of the register DX to the stack memory
        CMP DL,10   ;Compares the value 10 with the value of the register DL
        JAE HEX_LETTER  ;No , jump HEX_LETER
        ADD DL,"0"  ;yes, converts into digit number
        JMP Short WRITE_DIGIT ;writes the character
HEX_LETTER:
        ADD DL,"A"-10 ;converts a character to hexadecimal number
WRITE_DIGIT:
        CALL WRITE_CHAR ;shows the character on the computer screen
        POP DX      ;Returns the initial value to register DL
        RET         ;Returns the control the procedure called
WRITE_HEX_DIGIT   ENDP



        PUBLIC WRITE_CHAR
;......................................................................;
;This procedure prints on the computer screen a character using D.O.S. function ;
;......................................................................;

WRITE_CHAR   PROC
        PUSH AX   ;Pushes the value of the register AX to the stack memory
        MOV AH,2  ;2 function 
        INT 21h   ;21 Interruption
        POP AX    ;Pops the initial value of the register AX
        RET       ;Returns the control to the procedure called
WRITE_CHAR   ENDP


        END TEST_WRITE_DECIMAL ;finishes the program code 

This program shows 12345 numbers on the screen

Go to the page menu

Fifth example



;name of the program:five.asm
.model small
.stack
.code

PRINT_ASCII       PROC
        MOV DL,00h  ;moves the value 00h to register DL
        MOV CX,255   ;moves the value decimal number 255. this decimal number will be 255 times to prints out after the character A
PRINT_LOOP:
        CALL WRITE_CHAR ;Prints the characters out
        INC DL          ;Increases the value of the register DL content
        LOOP PRINT_LOOP ;Loops to print out ten characters
        MOV AH,4Ch      ;4Ch function 
        INT 21h         ;21h Interruption
PRINT_ASCII       ENDP    ;Finishes the procedure

WRITE_CHAR      PROC
        MOV AH,2h   ;2h function to print character out
        INT 21h     ;Prints out the character in the register DL
        RET         ;Returns the control to the procedure called
WRITE_CHAR      ENDP     ;Finishes the procedure

        END  PRINT_ASCII   ;Finishes the program code

This program shows the 256 ASCII values on the screen

Go to the page menu