Advance Microprocessor
Advance Microprocessor
Introduction
Debug Commands:
DEBUG commands: We’ll be using only some of the DEBUG commands in this experiment.
If you want to have a look at the entire command-set, you can enter ‘HELP DEBUG’ at the
DOS prompt on your PC, if it has help available. The meaning of some of the following
commands might become clear to you later during this experiment.
Syntax:
A [address]
Creates machine executable code in memory beginning at CS:0100 (or the specified address)
from the 8086/8088 (and 8087) Assembly Language instructions which are entered. Although
no Macro instructions nor labels are recognized, you can use the pseudo-instructions 'DB' and
'DW' (so you can use the DB opcode to enter ASCII data like this: DB 'This is a string',0D,0A
); spaces after the commas would make it clearer but aren't necessary.
The 'A' command remembers the last location where any data was assembled, so successive 'A'
commands (when no address is specified) will always begin at the next address in the chain of
assembled instructions. This aspect of the command is similar to the Dump command which
remembers the location of its last dump (if no new address is specified).
The assembly process will stop after you ENTER an empty line.
Example:
-a 100
xxxx:0100 jmp 126 ; Jump over data that follows:
xxxx:0102 db 0d,0a,"This is my first DEBUG program!"
xxxx:0123 db 0d,0a,"$"
xxxx:0126 mov ah,9 ; Function 09 of Int 21h:
xxxx:0128 mov dx,102 ; DS:DX -> $-terminated string.
xxxx:012B int 21 ; Write String to STD Output.
xxxx:012D mov ah,0 ; Function 00 of Int 21h:
P a g e 1 | 53
ADVANCE MICROPROCESSOR
Syntax:
G [=address] [addresses]
Breakpoints are used to HALT the execution of a program we're testing at some point of interest
before its termination. Up to 10, optional breakpoint addresses may be set by simply listing
them on the '-g' command line; separated by spaces. DEBUG will halt execution just before
any of breakpoint addresses is about to be executed, and all of them will be 'cleared' at this time
as well. (If you should somehow attempt to set more than 10 breakpoints, DEBUG will respond
with: bp Error.
Syntax:
U [range]
Disassembles machine instructions into 8086 Assembly code. Without the optional [range],
it uses Offset 100 as its starting point, disassembles about 32 bytes and then remembers the
next byte it should start with if the command is used again. ( The word 'about' was used above,
because it may be necessary to finish with an odd-number of bytes greater than 32, depending
upon the last type of instruction DEBUG has to disassemble. )
P a g e 2 | 53
ADVANCE MICROPROCESSOR
NOTE: The user must decide whether the bytes that DEBUG disassembles are all 8086
instructions, just data or any newer x86 instructions (those for the 80286, 80386 on up to the
lastest CPU from Intel; which are all beyond the ability of DEBUG to understand)!
Example:
-u 126 12F
xxxx:0126 B409 MOV AH,09
xxxx:0128 BA0201 MOV DX,0102
xxxx:012B CD21 INT 21
xxxx:012D B400 MOV AH,00
xxxx:012F CD21 INT 21
Syntax:
D [range]
D [address] [length]
Examples:
-d 100 130
xxxx:0100 EB 24 0D 0A 54 68 69 73-20 69 73 20 6D 79 20 66 .$..This is my f
xxxx:0110 69 72 73 74 20 44 45 42-55 47 20 70 72 6F 67 72 irst DEBUG progr
xxxx:0120 61 6D 21 0D 0A 24 B4 09-BA 02 01 CD 21 B4 00 CD am!..$......!...
xxxx:0130 21
-d 102 l24
xxxx:0100 0D 0A 54 68 69 73-20 69 73 20 6D 79 20 66 ..This is my f
xxxx:0110 69 72 73 74 20 44 45 42-55 47 20 70 72 6F 67 72 irst DEBUG progr
xxxx:0120 61 6D 21 0D 0A 24 am!..$
P a g e 3 | 53
ADVANCE MICROPROCESSOR
Used to enter data or instructions (as machine code) directly into Memory locations.
Example.
First we'll change a single byte at location CS:FFCB from whatever it was before to D2 :
-e ffcb d2
Syntax:
R [register]
Entering ' r ' all by itself will display all of the 8086 register's contents and the
next instruction which the IP register points to in both machine code and an
unassembled (Assembly Language) form. For example, if you start DEBUG in a
Windows 95B DOS-box with the command line:
>debug c:\windows\command\choice.com
and then enter an ' r ' at the first DEBUG prompt, DEBUG will display someting
similar to this:
AX=0000 BX=0000 CX=1437 DX=0000 SP=FFFE BP=0000 SI=0000 DI=0000
DS=0ED8 ES=0ED8 SS=0ED8 CS=0ED8 IP=0100 NV UP EI PL NZ NA PO NC
0ED8:0100 E90E01 JMP 0211
If you enter the ' r ' followed by the abbreviation for an 8086 register, such as: ' rcx
', then DEBUG will display only the contents of that register followed by a line
with a colon symbol (:) on which you can enter a hex number to change the
contents of that register. If you simply press the ENTER key, the contents remain
the same. For example:
-rcx
CX 0100
:273
-
P a g e 4 | 53
ADVANCE MICROPROCESSOR
means the Register command was used to change the contents of the CX register
from 0100 to 0273. The command rcx could also be used again to verify the
change had indeed taken place
Syntax:
T [=address] [number]
The T command is used to trace (step through) CPU instructions one at a time. If
you enter the T command by itself, it will normally step through only ONE
instruction beginning at the location specified by your CS:IP registers, halt
program execution and then display all the CPU registers plus an unassembled
version of the next instruction to be executed; this is the 'default' mode of the
TRACE command. Say, however, you wanted DEBUG to trace and execute seven
instructions beginning at address CS:0205; to do so, you would enter:
-t =205 7
Remember that the value for the number of instructions to execute must be given
in hexadecimal just as all other values used in DEUBG. (Since the T command
uses the "hardware trace mode" of the CPU, it's possible to step through
instructions in a ROM - Read Only Memory - chip; or step into BIOS code which
has been shadowed in read-only portions of Memory for decades now.) NOTE: If
you find yourself stuck inside a long LOOP or REPeat string instruction, enter a P
(Proceed) command and it will complete the operation and move to the next
instruction.
P a g e 5 | 53
ADVANCE MICROPROCESSOR
Syntax:
L [address] [drive] [firstsector] [number]
This command will LOAD the selected number of sectors from any disk's Logical Drive
under the control of MS-DOS or Windows into Memory. The address is the location in
Memory the data will be copied to (use only 4 hex digits to keep it within the memory allocated
to DEBUG), the drive number is mapped as: 0=A:, 1=B:, 2=C:, etc., firstsector counts from
ZERO to the largest sector in the volume and finally number specifies in hexadecimal the
total number of sectors that will be copied into Memory (so a floppy disk with 0 through 2,879
sectors would be: 0 through B3F in Hex).
Examples:
P a g e 6 | 53
ADVANCE MICROPROCESSOR
Syntax:
Example:
After creating and running a small program inside of DEBUG which copies the
Master Boot Record (MBR) to Offset 0000h through 01FFh, these DEBUG
commands save the MBR to a file on the hard disk:
-n mymbr.bin
-rcx
CX 0001
:200
-w 0
Writing 00200 bytes [ 512 bytes in decimal ]
-
Syntax:
N [pathname] [arglist]
P a g e 7 | 53
ADVANCE MICROPROCESSOR
This command can be used to load files into DEBUG's Memory after you have started the
program, but it's main function is to create a new file under control of the Operating System
which DEBUG can WRITE data to.
Normally, when you want to 'debug' a file, you'd start DEBUG with a command like
this: C:\WINDOWS>debug test.com . But it's also possible to load a file into DEBUG's
Memory from within DEBUG itself by using the 'N' command and then the 'L' command
(with no parameters) like this:
-n c:\temp\test.com
-l
which will load the file test.com into DEBUG's Memory starting at location CS:0100
Memory models:
Huge huge huge multiple code and data segments; single array may be >64 KB
P a g e 8 | 53
ADVANCE MICROPROCESSOR
Practical-1(A)
Aim: Write an assembly level program to add two 8-bit hex numbers and BCD numbers.
Program Code:
1. Hex addition
q db 2 dup(0) ;
mov al,[bx]
int 3
end
2. BCD addition
q db 2 dup(0) ;
mov al,[bx]
int 3
end
Output:
P a g e 10 | 53
ADVANCE MICROPROCESSOR
P a g e 11 | 53
ADVANCE MICROPROCESSOR
Practical-1(B)
Aim: Write an assembly level program to subtract one 8-bit number from other.
Program Code:
q db 2 dup(0) ;
mov al,[bx]
int 3
end
P a g e 12 | 53
ADVANCE MICROPROCESSOR
Output:
P a g e 13 | 53
ADVANCE MICROPROCESSOR
Practical-2(A)
Aim: Write an assembly level program to add two 16-bit hex numbers and two 4 digit BCD
numbers.
Program Code:
q dw 8 dup (0)
mov al,[bx]
mov al,[bx+1]
int 3
end
P a g e 14 | 53
ADVANCE MICROPROCESSOR
q dw 8 dup (0)
mov al,[bx]
mov al,[bx+1]
int 3
end
P a g e 15 | 53
ADVANCE MICROPROCESSOR
Output:
P a g e 16 | 53
ADVANCE MICROPROCESSOR
Practical-2(B)
Aim: Write an assembly program to Ex-or the two 8-bit numbers without using Logical
instruction (XOR).
Program Code:
p db 45h,7fh
r db 2 dup(0)
mov ds,ax ; to DS
mov al,[bx]
not al ; component A
mov ah,[bx+1] ;B
mov [di],al ;
mov al,[bx] ;A
mov ah,[bx+1] ;
not ah ; component B
or al,[di]
P a g e 17 | 53
ADVANCE MICROPROCESSOR
hlt
end
Output:
P a g e 18 | 53
ADVANCE MICROPROCESSOR
Practical-3(A)
Aim: Write an assembly level program to add an array of hex numbers and BCD numbers.
Program Code:
1. Hex numbers:
q db 2 dup(0) ;
mov cl,05h
mov al,[bx]
jnc cc
cc: inc bx
dec cl
mov [di],al
int 3
end
2. BCD numbers
q db 2 dup(0) ;
mov al,[bx]
jnc cc
cc: inc bx
dec cl
P a g e 20 | 53
ADVANCE MICROPROCESSOR
mov [di+2],ch
int 3
end
Output:
P a g e 21 | 53
ADVANCE MICROPROCESSOR
Practical-3(B)
Aim: Write an assembly level program to separate hex numbers between 20H and 50H.
Program Code:
q db 2 dup(0) ;
.code
mov ax,@data
mov ds,ax
cmp al,20h
cmp al,50h
inc di
loop1: inc si
dec cl
int 3
end
Output:
P a g e 23 | 53
ADVANCE MICROPROCESSOR
Practical-4(A)
Aim: Write an assembly level program to find minimum and maximum numbers from an
array.
Program Code:
1. Maximum number
mov ax,@data
mov ds,ax
next: inc si
jnc loop1
loop1: dec cl
int 3
end
P a g e 24 | 53
ADVANCE MICROPROCESSOR
2. Minimum number
mov ax,@data
mov ds,ax
next: inc si
jc loop1
loop1: dec cl
int 3
end
P a g e 25 | 53
ADVANCE MICROPROCESSOR
Output:
P a g e 26 | 53
ADVANCE MICROPROCESSOR
Practical-4(B)
Aim: Write an assembly level program to sort an array into ascending and descending order.
Program Code:
1. Ascending order
pass2: inc si
inc si
mov [si],ax
next: dec cl
P a g e 27 | 53
ADVANCE MICROPROCESSOR
dec ch
int 3
end
2. Descending order
mov cl,04h
pass2: inc si
inc si
P a g e 28 | 53
ADVANCE MICROPROCESSOR
mov [si],ax
next: dec cl
dec ch
int 3
end
Output:
P a g e 29 | 53
ADVANCE MICROPROCESSOR
Practical-5
Aim: Write an assembly level program to add elements of two arrays and store results in third
array.
Program Code:
r db 2 dup(0) ;
jnc loop2
inc bx
add si,02h
P a g e 30 | 53
ADVANCE MICROPROCESSOR
int 3
end
Output:
P a g e 31 | 53
ADVANCE MICROPROCESSOR
Practical-6
Aim: Write an assembly level program to multiply two 8-bit numbers using add-shift method.
Program Code:
a db 08h
b db 08h
mov al,a
mov bl,b
mov ah,00h
mov dl,03h
ad:
rcl bl,01
jnc skip
add ax,bx
skip:
dec dl
jnz ad
int 3
P a g e 32 | 53
ADVANCE MICROPROCESSOR
end
Output:
P a g e 33 | 53
ADVANCE MICROPROCESSOR
Practical-7
Aim: Write an assembly level program to convert given HEX data into equivalent BCD and
given BCD to HEX equivalent.
Program code:
1) HEX to BCD
r db 2 dup(0)
mov ds,ax ; to DS
mov al,p
add al,00
mov [bx],al
hlt
end
2) BCD to HEX
P a g e 34 | 53
ADVANCE MICROPROCESSOR
r db 4 dup(0)
mov ds,ax ; to DS
mov al,[bx]
mov [di],al
mov al,[bx+1]
ror al,cl
mov [di],al ;
mov al,[bx+1]
mov [di],al
hlt
P a g e 35 | 53
ADVANCE MICROPROCESSOR
end
Output:
P a g e 36 | 53
ADVANCE MICROPROCESSOR
Practical-8
Aim: To study different DOS and BIOS Interrupts.
Theory:
1. BIOS screen service type interrupt 10H –used to control Display of text character
on CRT Monitor
Total 18 different modes are available some of which are discussed here.
1) Function 00H (storing in AH register) – Getting key from the keyboard buffer
It will return the value of the ASCII code in AL register and scan code in AH register.
P a g e 37 | 53
ADVANCE MICROPROCESSOR
Program Code:
i) Interrupt 10H
- Function 01H
.model small
.stack 64H
.code
mov ah,01h
mov cx,2034h
int 10h
hlt
end
- Function 02H
.model small
.stack 64H
.code
P a g e 38 | 53
ADVANCE MICROPROCESSOR
mov ah,02h
mov dx,1034h
int 10h
hlt
end
- Function 09H
.model small
.stack 64H
.code
mov ah,09h
mov bx,004fh
mov cx,0004h
mov al,’A’
int 10h
hlt
end
.model small
.stack 64H
.code
mov ah,00h
int 16h
hlt
end
P a g e 39 | 53
ADVANCE MICROPROCESSOR
- Function 01H
.model small
.stack 64H
.code
mov ah,01h
int 16h
hlt
end
- Function 02H
.model small
.stack 64H
.code
mov ah,02h
int 16h
hlt
end
.model small
.stack 64H
.code
mov ah,01h
int 21h
hlt
end
P a g e 40 | 53
ADVANCE MICROPROCESSOR
- Function 08H
.model small
.stack 64H
.code
mov ah,01h
int 21h
hlt
end
- Function 09H
.model small
.stack 64H
.data
.code
mov ax,@data
mov ds,ax
mov ah,09h
lea bx,p
int 21h
hlt
end
P a g e 41 | 53
ADVANCE MICROPROCESSOR
Practical-9
Aim: Program to obtain factorial of a number.
Program Code:
mov ax, 01
mov di, ax
mov bp, 2
mov bx, dx
mov bx, di
dec bp
int 21h
cmp bx, 01
jz l11
l12: mul bx
P a g e 42 | 53
ADVANCE MICROPROCESSOR
dec bx
cmp bx, 01
jne l12
ret
end
Output:
P a g e 43 | 53
ADVANCE MICROPROCESSOR
Practical-10(A)
Aim: Program to move a string from one memory location to another.
Program Code:
q db 5 dup(?) ; Destination
cld
int 3
end
P a g e 44 | 53
ADVANCE MICROPROCESSOR
Output:
P a g e 45 | 53
ADVANCE MICROPROCESSOR
Practical-10(B)
Aim: Program to compare a string with input string from user
Program Code:
cld
jmp ok ; otherwise OK
int 3h
end
P a g e 46 | 53
ADVANCE MICROPROCESSOR
Output:
P a g e 47 | 53
ADVANCE MICROPROCESSOR
Practical-10(C)
Aim: Program to find occurrence of a character in a string.
Program Code:
cld
inc al ; present
dec cl
int 3h
P a g e 48 | 53
ADVANCE MICROPROCESSOR
end
Output:
P a g e 49 | 53
ADVANCE MICROPROCESSOR
Practical-11(A)
Aim: Program to disply string using near procedure call.
Program Code:
.code
mov ds,ax
call disp
int 21h
mov ah,09h
lea dx,string
int 21h
disp endp
ret
end
P a g e 50 | 53
ADVANCE MICROPROCESSOR
Output:
P a g e 51 | 53
ADVANCE MICROPROCESSOR
Practical-11(B)
Aim: Program using far procedure call.
Program Code:
Main.asm
int 3h
end
pro.asm
p1 db 30h ; input 1
p2 db 5h ; input 2
public addf
mov al,p1
add al,p2
P a g e 52 | 53
ADVANCE MICROPROCESSOR
addf endp
end
P a g e 53 | 53