0% found this document useful (0 votes)
6 views53 pages

Advance Microprocessor

The document provides an overview of DEBUG commands used in assembly programming, detailing commands for assembling, executing, disassembling, dumping memory, entering bytes, displaying registers, tracing instructions, loading and writing data to disk, and creating filenames. It also outlines different memory models and provides steps for executing a program using Microsoft Assembler. Additionally, it includes practical examples for adding two 8-bit hex numbers and BCD numbers in assembly language.

Uploaded by

Nihar Desai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views53 pages

Advance Microprocessor

The document provides an overview of DEBUG commands used in assembly programming, detailing commands for assembling, executing, disassembling, dumping memory, entering bytes, displaying registers, tracing instructions, loading and writing data to disk, and creating filenames. It also outlines different memory models and provides steps for executing a program using Microsoft Assembler. Additionally, it includes practical examples for adding two 8-bit hex numbers and BCD numbers in assembly language.

Uploaded by

Nihar Desai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 53

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.

A - Assemble a program using instruction mnemonics

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

xxxx:012F int 21 ; Terminate Program.


xxxx:0131
-g =100

This is my first DEBUG program!

Program terminated normally

G - Execute the program currently in the memory

Syntax:
G [=address] [addresses]

Go is used to run a program and set breakpoints in the program's code.


As we saw in an Example for the ENTER command, the '=address' option is used to tell
DEBUG where to start executing code. If you use 'g' all by itself, execution will begin at
whatever location is pointed to by the CS:IP registers.

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.

U - Disassemble memory into assembler mnemonics

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

D - Dump (display) the contents of memory

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

E - Enter bytes into memory

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

R - Display the contents of registers and flags

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

T - Trace a single instruction

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

L - Load data from disk

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:

-l 100 2 0 1 [ the C: drive. ]


-d 100 10f
xxxx:0100 EB 58 90 4D 53 57 49 4E-34 2E 31 00 02 08 20 00 .X.MSWIN4.1... .
-d 280 2ff
xxxx:0280 01 27 0D 0A 49 6E 76 61-6C 69 64 20 73 79 73 74 .'..Invalid syst
xxxx:0290 65 6D 20 64 69 73 6B FF-0D 0A 44 69 73 6B 20 49 em disk...Disk I
xxxx:02A0 2F 4F 20 65 72 72 6F 72-FF 0D 0A 52 65 70 6C 61 /O error...Repla
xxxx:02B0 63 65 20 74 68 65 20 64-69 73 6B 2C 20 61 6E 64 ce the disk, and
xxxx:02C0 20 74 68 65 6E 20 70 72-65 73 73 20 61 6E 79 20 then press any
xxxx:02D0 6B 65 79 0D 0A 00 00 00-49 4F 20 20 20 20 20 20 key.....IO
xxxx:02E0 53 59 53 4D 53 44 4F 53-20 20 20 53 59 53 7E 01 SYSMSDOS SYS~.
xxxx:02F0 00 57 49 4E 42 4F 4F 54-20 53 59 53 00 00 55 AA .WINBOOT SYS..U.
-
-l 100 0 0 1 [ a floppy in the A: drive. ]
-d 100 13d
xxxx:0100 EB 3C 90 29 47 38 71 33-49 48 43 00 02 01 01 00 .<.)G8q3IHC.....
xxxx:0110 02 E0 00 40 0B F0 09 00-12 00 02 00 00 00 00 00 ...@............
xxxx:0120 00 00 00 00 00 00 29 40-16 D8 13 4E 4F 20 4E 41 ......)@...NO NA
xxxx:0130 4D 45 20 20 20 20 46 41-54 31 32 20 20 20 ME FAT12

P a g e 6 | 53
ADVANCE MICROPROCESSOR

W - Write data from memory to disk

Syntax:

W [address] [drive] [firstsector] [number]


The WRITE (W) command is often used to save a program to your hard disk from
within DEBUG. But the only safe way to do so, especially under Windows, is by
allowing the OS to decide where to physically create that file on the disk. This is
done by first using the Name (N) command to set up an optional path and filename
for the new file (or to overwrite one that already exists). DEBUG will automatically
begin saving program or data bytes from Offset 0100 of the 64 KiB Segment the OS
allocated for it. The only other requirement is to set the size of the file you wish to
write by placing the total number of bytes in the combined BX and CX registers
before executing the WRITE command.

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 ]
-

N - Create a filename for use by the L and W commands

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

Q - Quit DEBUG and return to DOS

Memory models:

Model Data Code Definition


Tiny* Near CS=DS=SS

Small near** near DS=SS

Medium near** far DS=SS, multiple code segments

Compact far near single code segment, multiple data segments

Large far far multiple code and data segments

Huge huge huge multiple code and data segments; single array may be >64 KB

Steps to execute a program using Microsoft Assembler:

 In command prompt, give the path for MASM.


 Write edit file_name.asm to edit an assembly file. Filename should be less than 9
characters.
 Write masm file_name.asm to create an .obj object file.
 Write link file_name.obj to create .exe executable file.
 Type debug file_name.exe to debug or run the code.

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

.model small ; small model

.stack 100 ; initialize stack segment

.data ; initialize data segment

p db 23h,0fdh ; input data

q db 2 dup(0) ;

.code ; initialize code segment

mov ax,@data ; move segment address

mov ds,ax ; into DS

lea bx,p ; pointer to input

lea di,q ; pointer to result

mov al,[bx]

add al,[bx+1] ; add data

mov [di],al ; store data

int 3

end

2. BCD addition

.model small ; small model

.stack 100 ; initialize stack segment

.data ; initialize data segment


P a g e 9 | 53
ADVANCE MICROPROCESSOR

p db 23h,34h ; input data

q db 2 dup(0) ;

.code ; initialize code segment

mov ax,@data ; move segment address

mov ds,ax ; into DS

lea bx,p ; pointer to input

lea di,q ; pointer to result

mov al,[bx]

add al,[bx+1] ; add data

daa ; adjust decimal

mov [di],al ; store result

int 3

end

Output:

Figure 1 Hex Addition

P a g e 10 | 53
ADVANCE MICROPROCESSOR

Figure 2 BCD Addition

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:

.model small ; small model

.stack 64h ; initialize stack segment

.data ; initialize data segment

p db 7fh,34h ; input data

q db 2 dup(0) ;

.code ; initialize code segment

mov ax,@data ; move segment address

mov ds,ax ; into DS

lea bx,p ; pointer to input

lea di,q ; pointer to result

mov al,[bx]

sub al,[bx+1] ; substract data

mov [di],al ; store result

int 3

end

P a g e 12 | 53
ADVANCE MICROPROCESSOR

Output:

Figure 3 Hex subtraction

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:

1. 16 bit hex addition

.model small ; small model

.stack 64h ; initialize small segment

.data ; initialize data segment

p dw 2367h,8976h ; input numbers

q dw 8 dup (0)

.code ; initialize code segment

mov ax,@data ; move segment address

mov ds,ax ; into DS

lea bx,p ; pointer to input

lea si,q ; pointer to result

mov al,[bx]

add al,[bx+2] ; add lower byte

mov [si],al ; store lower byte

mov al,[bx+1]

adc al,[bx+3] ; add higher byte

mov [si+1],al ; store higher byte

int 3

end

P a g e 14 | 53
ADVANCE MICROPROCESSOR

2. 4 digit BCD addition

.model small ; small model

.stack 64h ; initialize stack segment

.data ; initialize data segment

p dw 2367h,8976h ; input data

q dw 8 dup (0)

.code ; initialize code segment

mov ax,@data ; move segment addresss

mov ds,ax ; into DS

lea bx,p ; pointer to input

lea si,q ; pointer to result

mov al,[bx]

add al,[bx+2] ; add lower byte

daa ; adjust for BCD

mov [si],al ; store lower byte

mov al,[bx+1]

adc al,[bx+3] ; add higher byte

daa ; adjust for BCD

mov [si+1],al ; store higher byte

int 3

end

P a g e 15 | 53
ADVANCE MICROPROCESSOR

Output:

Figure 4 16-bit Addition

Figure 5 4 digit BCD Addition

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:

.model small ; small model

stack 64h ; initialize stack segment

.data ; initialize data segment

p db 45h,7fh

r db 2 dup(0)

.code ; initialize code segment

mov ax,@data ; move data address

mov ds,ax ; to DS

lea bx,p ; load effective address from p

lea di,r ; load effective address from r

mov al,[bx]

not al ; component A

mov ah,[bx+1] ;B

and al,ah ; (~A)*B

mov [di],al ;

mov al,[bx] ;A

mov ah,[bx+1] ;

not ah ; component B

and al,ah ; A*(~B)

or al,[di]

P a g e 17 | 53
ADVANCE MICROPROCESSOR

mov [di],al ; save to r location

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:

.model small ; small model

.stack 64h ; initialize stack segment

.data ; initialize data segment

p db 23h,0adh,91h,0c1h,54h ;input array

q db 2 dup(0) ;

.code ; initialize code segment

mov ax,@data ; move segment address

mov ds,ax ; into DS

lea bx,p ; pointer to array

lea di,q ; pointer to result

mov cl,05h

mov al,[bx]

next: adc al,[bx+1] ; add numbers

jnc cc

adc ch,00h ; count carry

cc: inc bx

dec cl

jnz next ; take next number

mov [di],al

mov [di+2],ch ; store result


P a g e 19 | 53
ADVANCE MICROPROCESSOR

int 3

end

2. BCD numbers

.model small ; small model

.stack 64h ; initialize stack segment

.data ; initialize data segment

p db 23h,09h,56h,94h,76h ; input array

q db 2 dup(0) ;

.code ; initialize code segment

mov ax,@data ; move segment address

mov ds,ax ; into DS

lea bx,p ;pointer to input

lea di,q ; pointer to result

mov cl,05h ; load count into CL

mov al,[bx]

next: adc al,[bx+1] ; add numbers

daa ; adjust for decimel

jnc cc

adc ch,00h ; count carry

cc: inc bx

dec cl

jnz next ; take next number

mov [di],al ; store results

P a g e 20 | 53
ADVANCE MICROPROCESSOR

mov [di+2],ch

int 3

end

Output:

Figure 6 Hex Addition

Figure 7 BCD Addition

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:

.model small ; small model

.stack 64h ; initialize stack segment

.data ; initialize data segment

p db 20h,67h,45h,78h,47h,12h,3ah,0ch,0b2h,4bh ; input array

q db 2 dup(0) ;

.code

mov ax,@data

mov ds,ax

lea si,p ; pointer to input

lea di,q ;pointer to result

mov cl,0ah ; load count into CL

next: mov al,[si] ; take numbers

cmp al,20h

jc loop1 ; jump if no <20H

cmp al,50h

jnc loop1 ; jump if no>50H

mov [di],al ; store numbers

inc di

loop1: inc si

dec cl

jnz next ; go for next number


P a g e 22 | 53
ADVANCE MICROPROCESSOR

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

.model small ; small model

.stack 64h ; initialize stack segment

.data ; initialize data segment

p db 25h,0ah,0fah,3ah,0dch ; input array

.code ; initialize code segment

mov ax,@data

mov ds,ax

lea si,p ; pointer to input

mov cl,05h ; load count into CL

mov al,[si] ; take a number

next: inc si

cmp al,[si] ; compare with next

jnc loop1

mov al,[si] ; move maximum into AL

loop1: dec cl

jnz next ; go for next

int 3

end

P a g e 24 | 53
ADVANCE MICROPROCESSOR

2. Minimum number

.model small ; small model

.stack 64h ; initialize stack segment

.data ; initialize data segment

p db 25h,0ah,0fah,3ah,0dch ; input array

.code ; initialize code segment

mov ax,@data

mov ds,ax

lea si,p ; pointer to input

mov cl,05h ; load count in CL

mov al,[si] ; take a number in AL

next: inc si

cmp al,[si] ; compare with next

jc loop1

mov al,[si] ; move minimum in AL

loop1: dec cl

jnz next ; go for next

int 3

end

P a g e 25 | 53
ADVANCE MICROPROCESSOR

Output:

Figure 8 Maximum Number

Figure 9 Minimum Number

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

.model small ; small model

.stack 100 ; initialize stack segment

.data ; initialize data segment

p dw 0989h,0ac65h,0ff21h,0034h,0a0dh ;input array

.code ; initialize code segment

mov ax,@data ; get segment address

mov ds,ax ; into DS

mov ch,04h ; load count in CL

pass1: lea si,p ; pointer to input

mov ax,[si] ; get no into AX

mov cl,04h ; load count into CL

pass2: inc si

inc si

cmp ax,[si] ; compare with next

jnc next ; jump if AX> [SI]

mov dx,[si] ; otherwise

mov ax,[si-2] ; exchange

mov [si-2],dx ; [SI] and [SI+2]

mov [si],ax

next: dec cl
P a g e 27 | 53
ADVANCE MICROPROCESSOR

jnz pass2 ; 1st iteration

dec ch

jnz pass1 ; 2nd iteration

int 3

end

2. Descending order

.model small ; small model

.stack 100 ; initialize stack segment

.data ; initialize data segment

p dw 0989h,0ac65h,0ff21h,0034h,0a0dh ; input array

.code ; initialize code segment

mov ax,@data ; get segment address

mov ds,ax ; into DS

mov ch,04h ; load count into CH

pass1: lea si,p ; pointer to input

mov ax,[si] ; get number into AX

mov cl,04h

pass2: inc si

inc si

cmp ax,[si] ; compare with next

jc next ; jump if AX<[SI+2]

mov dx,[si] ; otherwise

mov ax,[si-2] ; exchange

mov [si-2],dx ; [SI] and [SI+2]

P a g e 28 | 53
ADVANCE MICROPROCESSOR

mov [si],ax

next: dec cl

jnz pass2 ; 1st iteration

dec ch

jnz pass1 ; 2nd iteration

int 3

end

Output:

Figure 10 Ascending Order

Figure 11 Descending Order

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:

.model small ; small model

.stack 100 ; initialize stack segment

.data ; initialize data segment

p db 0a2h,05h,0b3h,00h,47h,9fh,7eh ; input array1

q db 0ffh,31h,07h,0bah,06dh,68h,92h ; input array2

r db 2 dup(0) ;

.code ; initialize code segment

mov ax,@data ; move segment address

mov ds,ax ; into DS

mov cl,07h ; load count into CL

mov bx,0000 ; pointer to input

lea si,r ; pointer to result

loop1: mov ah,00h

mov al,p[bx] ; take array1

add al,q[bx] ; add array2

jnc loop2

inc ah ; count carry

loop2: mov [si],ax ; store results

inc bx

add si,02h

P a g e 30 | 53
ADVANCE MICROPROCESSOR

loop loop1 ; go for next

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:

.model small ; small model

.stack 64h ; initialize stack segment

.data ; initialize data segment

a db 08h

b db 08h

.code ; initialize code segment

mov ax,@data ; move segment address

mov ds,ax ; into DS

mov al,a

mov bl,b

mov ah,00h

mov dl,03h

ad:

add ax,ax ; multiply by 2

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

.model small ; small model

.stack 64h ; initialize stack segment

.data ; initialize data segment

p db 2dh ; initializing variables

r db 2 dup(0)

.code ; initialize code segment

mov ax,@data ; moving data segment address

mov ds,ax ; to DS

lea bx,r ; loading effective address from r

mov al,p

add al,00

daa ; Decimal adjust after addition to obtain BCD

mov [bx],al

hlt

end

2) BCD to HEX

.model small ; small model

.stack 64h ; initialize stack segment

.data ; initialize data segment

P a g e 34 | 53
ADVANCE MICROPROCESSOR

p db 01h,45h ; initializing variables

r db 4 dup(0)

.code ; initialize code segment

mov ax,@data ; moving data segment address

mov ds,ax ; to DS

lea bx,p ; loading effective address from p

lea di,r ; loading effective address from r

mov al,[bx]

mov dl,0ah ; storing 10 D

mov dh,64h ; storing 100 D

mul dh ; hundred’s place (a) * 100

mov [di],al

mov al,[bx+1]

and al,0f0h ; masking to obtain tens digit

mov cx,0004h ; count of 4 to right shift nibble

ror al,cl

mul dl ; ten’s place (b) * 10

add al,[di] ; a*100+b*10

mov [di],al ;

mov al,[bx+1]

and al,0fh ; masking to obtain unit’s place

add al,[di] ; a*100+b*10+unit

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.

i) Mode 0 – 20 rows, 40 characters


ii) Mode 1 – 25 rows, 80 characters
iii) Mode 2 – 320x200 pixels

Certain Function types:

1) Function 01h (storing in AH register) - Cursor shape


This function determines how many pixels lines will be used to make up the cursor.
Value stored in CH register denotes starting line
Value stored in CL register denotes ending line
2) Function 02h (storing in AH register) – Cursor position
Value stored in DH register denotes row number (00h-18h)
Value stored in DL register denotes column number (00h-4Fh)
Value stored in BH register denotes page number
3) Function 09h (storing in AH register) – Position of text character
This function helps write a text character at cursor position.
Value stored in BH register denotes page number
Value stored in BL register denotes attributes for the monitor type (00h-FFh)
Value stored in CX register denotes number of characters times to be repeated
Value stored in AL register denotes the ASCII value of the character that is to be
displayed
2. BIOS keyboard interrupt 16H

Certain Function types:

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

2) Function 01H (storing in AH register) – Read keyboard status


It will return the value of the ASCII code in AL register and scan code in AH register
along with the status reflected in zero flag
ZERO FLAG = 0 – No waiting
1 – Waiting
3) Function 02H- Read control key status
It will return the value of the ASCII code in AL register and scan code in AH register
along with displaying the same.
3. DOS interrupt 21H
1) Function 01H – Keyboard Input with Echo
2) Function 08H – Keyboard Input ASCII value to AL
3) Function 09H – Display the string pointed by DS:BX
String must end with $ character though it won’t be printed.

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

ii) Interrupt 16H


- Function 00H

.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

iii) Interrupt 21H


- Function 01H

.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

p db “BVM Engineering College”

.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:

.model small ; small model

.stack 64h ; initialize stack segment

.data ; initialize data segment

num db 08h ; input data

.code ; initialize code segment

mov ax, @data ; move segment address

mov ds, ax ; into DS

mov ax, 01

mov bx, num

call fact ; call procedure fact

mov di, ax

mov bp, 2

mov bx, dx

mov bx, di

dec bp

mov ah, 4ch

int 21h

fact proc near ; declare near procedure

cmp bx, 01

jz l11

l12: mul bx
P a g e 42 | 53
ADVANCE MICROPROCESSOR

dec bx

cmp bx, 01

jne l12

ret

l11: mov ax, 01

ret ; return from call

fact endp ; end procedure

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:

.model small ; small model

.stack 64h ; initialize stack segment

.data ; initialize data segment

p db 'hello' ; source data

q db 5 dup(?) ; Destination

.code ; initialize code segment

start: mov ax,@data ; mov segment address

mov ds,ax ; into DS

mov es,ax ; initialtze extra segment

lea si,p ; pointer to source

lea di,q ; pointer to destination

mov cx,05 ; load count

cld

rep movsb ; move characters

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:

.model small ; small model

.stack 64h ; initialize stack segment

.data ; initialize data segment

pwd db 'assembly' ; data string

strln equ $-pwd ; find length

input db 8 dup(0) ; input from user

.code ; initialize code segment

mov ax,@data ; move segment address

mov ds,ax ; into DS

mov es,ax ; extra segment address

lea si,pwd ; pointer to data string

lea di,input ; pointer to input string

mov cl,strln ; load count into CL

cld

repe cmpsb ; compare characters

jne false ; jump if not matched

jmp ok ; otherwise OK

false: mov al,'w' ;show ‘w’ for wrong

ok: mov al,'c' ; and ‘c’ for correct

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:

.model small ; small model

.stack 64h ; initialize stack segment

.data ; initialize data segment

input db 'modified' ; data string

strln equ $- input ; find length

chc db ‘i’ ; character to count

.code ; initialize code segment

mov ax,@data ; move segment address

mov ds,ax ; into DS

mov es,ax ; extra segment address

lea si,input ; pointer to data string

lea di,chc ; pointer to character

mov cl,strln ; load count into CL

cld

next: cmpsb ; compare strings

jne count ; count if character is

inc al ; present

count: dec di ; point to character

dec cl

jnz next ; go for next character

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:

.model small ; small model

.data ; initialize data segmrnt

string db 'advance microprocessors $' ; input string

.code

mov ax,@data ; intialize data and extra segment

mov ds,ax

call disp

mov ah,4ch ; terminate program

int 21h

disp proc near

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

.model small ; small model

extrn addf:far ; name of far procedure

.stack 64h ; stack segment

.code ; code segment

call addf ; call far procedure

int 3h

end

pro.asm

.model small ; small model

.stack 64h ; initialize stack segment

.data ; initialize data segment

p1 db 30h ; input 1

p2 db 5h ; input 2

.code ; initialize code segment

addf proc far ; define far procedure

public addf

mov ax,@data ; move segment address

mov ds,ax ; into DS

mov al,p1

add al,p2
P a g e 52 | 53
ADVANCE MICROPROCESSOR

ret ; return from procedure

addf endp

end

P a g e 53 | 53

You might also like