DEBUG
A software that is classifies as debugger which is used for testing and debugging executable programs
Advantages
It is Free
It is universally available
It is simple to use
It requires relatively little memory
DEBUG COMMANDS
E (Enter)
-enable you to key in data or machine instruction into memory beginning at a specific location address.
E.g -E 0200
D (Display or Dump)
Displays the contents of a portion memory ni hex and ASCII forms starting with the given address
E.g. -D 0200
A (Assemble)
Allows you to create a program in mnemonic or symbolic code.
E.g. -A 0100
T (Trace)
Runs he program in single-step mode. It also displays the new values of the registers and the next
instruction to be executed.
E.g -T
G (Go)
Runs the program as a whole in memory an displays the output
E.g. -G
U (Unassemble)
Lists all the instructions contained in the program beginning at the given address. You can also specify
the last address location.
E.g. -U 0100
-U 0100 0109
N (Name)
Gives a name to your program, coded as N <path> <filename>
Extention nae is .COM
E.g. -N A:SAMPLE.COM
W (Write)
Saves the program onto disk storage
E.g. -W
BASIC ASSEMBLY INSTRUCTIONS USED IN DEBUG
MOV (Move Data)
Copies and transfers data between two registers, or between an immediate data to a register
Format: MOV <register>, <register>
MOV <register>, <immediate data>
Example: MOV AX, BX
MOV CX, 5083
MOV CL, DL
MOV BL, 33
ADD (Add Data)
Used to get the sum of two registers or a register and an immediate data, and stores the result to the
left most register
Format: ADD <register>, <register>
ADD <register>, <immediate data>
Example: ADD CX, BX
ADD AX, 0308
ADD AL, BL
ADD DH, 85
MUL (Multiply Data)
It is used to get the product of a given register and AX register, and stores the result to AX register. If the
product is greater than 16 bits, the overflow is stored in DX register.
Format: MUL <register>
Example: MUL CX
DIV (Divide Data)
Used to divide the value of a given register and AX register, stores the quotient to AX and the remainder
to DX registers respectively
Format: DIV <register>
Example DIV BX
INC (Increment by One)
Used to increase the value of the register by one (1).
Format: INC register
Example: INC AX
INC CH
Directives
Statements that give information to the assembler
Sometimes called pseudo-ops
Examples:
TITLE DOSSEG .MODEL
.STACK .DATA .CODE
Rules in Constructing Valid identifier
It must use letters (A...Z, az), number (09) and/or special characters like underscore (_), question
mark (?) and at sign (@).
It must always start with a letter
It must not use reserved words
It must not exceed to 31 character.
Examples of valid identifiers:
neym r2d2
num_1 msg8
Examples of invalid identifiers:
title num-1
4ever
Statement
May begin anywhere on the line
Each line can only contain one statement
Assembly is not case sensitive
Examples:
ADD AX, BX ; uses 2 operands
DEC CX ; uses
RET ; no operand
.MODEL
It specifies and initializes the memory model before defining any segment
Format:
.MODEL <memory-model>
Examples:
.MODEL TINY
.MODEL SMALL
.MODEL MEDIUM
.STACK
It defines the size of the attack. The default stack size is 1,024 bytes which you can overrule.
Format:
.STACK <size>
Example:
.STACK 0100h
.DATA
It defines and marks the beginning of data segment
Format:
.DATA
Example:
.DATA
.CODE
It defines and marks the code segment which consists of a set of instructions.
Format:
.CODE
Example:
.CODE
START:
Defines the start of program execution
Format:
START:
Examples:
START:
END
Screen Processing
The monitor
A typical video screen has 80 columns numbered form 0 to 79 and 25 rows numbered from 0 to 24.
Clearing the screen in Assembly Approach
Interrupt 10h and function 06h handles the process of clearing the screen and scrolling
Clear all or part of display beginning at any screen location and ending at any higher-numbered location.
Sample code shows how to clear screen code in assembly
MOV AX, 0600h ; AH = 00h (scroll), AL, 00h (Full screen)
MOV BH, 07h ; 0 (BLACK BACKGROUND), 7 (WHITE TEXT COLOR)
MOV CX, 0000h ; CH = 00H (ROW), CL, 00H (COLUMN)
MOV DX, 184Fh ; DH = 18H (ROW), DL=4FH (COLUMN)
INT 10h ; CALL INTERRUPT SERVICE
SETTING THE CURSOR FUNCTION
Interrupt 10h is the BIOS operation for screen handling and function 02h tells the operation to set the
cursor
Its position determines where the next character is to be displayed.
MOV AH, 02H ; REQUEST TO SET THE CURSOR POSITION
MOV BH, 00H ; PAGE NUMBER 0
MOV DH, 0AH ; ROW - 10 IN DECIMAL
MOV DL, 08H ; COLUMN = 8 IN DECIMAL
INT 10H
MAY CONTINUATION PA PO ITO, WAIT NYO LANG
.MODEL SMALL
.STACK 100H
.DATA
str1 DB 'she$'
str2 DB ' SHE SHE$'
str3 DB ' SHING$'
.CODE
MAIN PROC
MOV AX, @DATA ; initialize DS
MOV DS, AX
LEA DX, str1 ; load & display the STRING_1
MOV AH, 9
INT 21H
MOV AH, 2 ; carriage return
MOV CX, 0DH
INT 21H
MOV DL, 0AH ; line feed
INT 21H
LEA DX, str2 ; load & display the STRING_2
MOV AH, 9
INT 21H
MOV AH, 2 ; carriage return
[1] OUTPUT
54321
5432
543
54
5
Code:
.model small
.stack 100
.data
lfcr db 10,13, '$'
.code
.startup
;number 1
mov ax, 0003
int 10h
mov bl, '1'
yy: mov cl, '5'
[2] OUTPUT
1
21
321
4321
54321
Code:
.model small
.stack 100
.data
lfcr db 10,13,'$'
.code
.startup
mov ax, 0003
int 10h
mov bl, '1'
yy: mov cl, bl
xx: mov ah, 02
mov dl, cl
int 21h
dec cl
cmp cl, '1'
JAE xx
mov ah, 09
lea dx, lfcr
int 21h
inc bl
cmp bl, '5'
JBE yy
mov ch, 4ch
int 21h
end
[3] OUTPUT
Input a character: %
Input a height: 5
%%%%%
%%%%%
%%%%%
%%%%%
%%%%%
Code:
.model small
.stack 100
.data
lfcr db 10,13,'$'
mess1 db "Input a character: $"
mess2 db 10,13,"Input a height: $"
.code
.startup
mov ax, 0003
int 10h
mov ah, 09
lea dx, mess1
int 21h
mov ah, 01
int 21h
mov bh, al
mov ah, 09
lea dx, mess2
int 21h
mov ah, 01
int 21h
mov ch, al
mov ah, 09
lea dx, lfcr
int 21h
mov bl, '1'
yy:mov cl, '1'
xx: mov ah, 02
mov dl, bh
int 21h
inc cl
cmp cl, ch
JBE xx
mov ah, 09
lea dx, lfcr
int 21h
inc bl
cmp bl, ch
JBE yy
mov ch, 4ch
int 21h
end
[4] OUTPUT
aaaaa
ccccc
eeeee
ggggg
iiiii
Code:
.model small
.stack 100
.data
lfcr db 10,13,'$'
lett db 'a'
.code
.startup
mov ax, 0003
int 10h
[5] OUTPUT
abcde
abcde
abcde
abcde
abcde
Code:
.model small
.stack 100
.data
lfcr db 10,13,'$'
.code
.startup
mov ax, 0003
int 10h
mov bl, '1'
yy: mov cl, 'a'
xx: mov ah, 02
mov dl, cl
int 21h
inc cl
cmp cl, 'e'
JBE xx
mov ah, 09
lea dx, lfcr
int 21h
inc bl
cmp bl, '5'
JBE yy
mov ch, 4ch
int 21h
end
[6] OUTPUT
edcba
edcba
edcba
edcba
edcba
Code:
.model small
.stack 100
.data
lfcr db 10,13,'$'
.code
.startup
mov ax, 0003
int 10h
mov bl, '1'
yy: mov cl, 'e'
xx: mov ah, 02
mov dl, cl
int 21h
dec cl
cmp cl, 'a'
JAE xx
mov ah, 09
lea dx, lfcr
int 21h
inc bl
cmp bl, '5'
JBE yy
end
[7] OUTPUT
11111
22222
33333
44444
55555
Code:
.model small
.stack 100
.data
lfcr db 10,13,'$'
.code
.startup
mov ax, 0003
int 10h
mov bl, '1'
yy: mov cl, '1'
xx: mov ah, 02
mov dl, bl
int 21h
inc cl
cmp cl, '5'
JBE xx
mov ah, 09
lea dx, lfcr
int 21h
inc bl
cmp bl, '5'
JBE yy
mov ch, 4ch
int 21h
end
[8] OUTPUT
54321
54321
54321
54321
Code:
.model small
.stack 100
.data
lfcr db 10,13,'$'
.code
.startup
mov ax, 0003
int 10h
mov bl, '1'
yy: mov cl, '5'
xx: mov ah, 02
mov dl, cl
int 21h
dec cl
cmp cl, '1'
JAE xx
mov ah, 09
lea dx, lfcr
int 21h
inc bl
cmp bl, '5'
JBE yy
mov ch, 4ch
int 21h
end
[9] OUTPUT
12345
1234
123
12
1
Code:
.model small
.stack 100
.data
lfcr db 10,13,'$'
.code
.startup
mov ax, 0003
int 10h
mov bl, '5'
yy: mov cl, '1'
xx: mov ah, 02
mov dl, cl
int 21h
inc cl
cmp cl, bl
JBE xx
mov ah, 09
lea dx, lfcr
int 21h
dec bl
cmp bl, '1'
JAE yy
mov ch, 4ch
int 21h
end
[10] OUTPUT
1
12
123
1234
12345
Code:
.model small
.stack 100
.data
lfcr db 10,13,'$'
.code
.startup
mov ax, 0003
int 10h
mov bl, '1'
yy: mov cl, '1'