0% found this document useful (0 votes)
18 views19 pages

MPMC Lab Programs

Uploaded by

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

MPMC Lab Programs

Uploaded by

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

-----------------------

8 bit arithmetic
-----------------------
dosseg
.model small
.stack 100h
.data
n1 db 82h
n2 db 0A3h
sum db ?
carry db ?
diff db ?
brw db ?
prod dw ?
quot db ?
rem db ?
.code
start:
mov ax, @data
mov ds, ax
mov cl,00h
mov al,n1
add al,n2
adc cl,00h
mov sum,al
mov carry,cl
mov cl,00h
mov al,n1
sub al,n2
sbb cl,00h
mov diff,al
mov brw,cl
mov al,n1
mul n2
mov prod,ax
mov al,n1
mov ah,00h
div n2
mov quot, al
mov rem, ah
mov ah, 4ch
int 21h
end start
end

Result
sum = 25h
carry = 01h
diff = dfh
brw = ffh
prod = 52c6h
quot = 00h
rem = 82h

-----------------------
16-bit arithmetic
-----------------------
dosseg
.model small
.stack 100h
.data
n1 dw 0C382h
n2 dw 54A3h
sum1 dw ?
carry1 dw ?
difference1 dw ?
borrow1 dw ?
product1 dw ?
product2 dw ?
quotient1 dw ?
remainder1 dw ?
.code
start:
mov ax, @data
mov ds, ax
mov cx,0000h
mov ax,n1
add ax,n2
adc cx,0000h
mov sum1,ax
mov carry1,cx
mov cx,0000h
mov ax,n1
sub ax,n2
sbb cx,0000h
mov difference1,ax
mov borrow1,cx
mov ax,n1
mul n2
mov product1,ax
mov product2,dx
mov ax,n1
mov dx,0000h
div n2
mov quotient1,ax
mov remainder1,dx
mov ah, 4ch
int 21h
end start
end
Result sum1 = 1825h
Carry1 = 0001h
Difference1 = 6EDFh
Borrow1 = 0000h
Product1 = 23C6h
Product2 = 40A3h
Quotient1 = 0002h
Remainder1 = 1A3Ch

-----------------------------------------
32-bit addition and subtraction
-----------------------------------------
dosseg
.model small
.stack 100h
.data
n1 dw 0C720h
n2 dw 0A4B0h
n3 dw 7453h
n4 dw 0BE32h
sum1 dw ?
sum2 dw ?
carry1 dw ?
sub1 dw ?
sub2 dw ?
borrow1 dw ?
.code
start:
mov ax, @data
mov ds, ax
mov ax, n1
mov bx,n2
mov SI, 0000h
add ax,n3
adc bx,n4
adc SI, 0000h
mov sum1, ax
mov sum2, bx
mov carry1, SI
mov ax, n1
mov bx, n2
mov SI, 0000h
sub ax, n3
sbb bx, n4
sbb SI, 0000h
mov sub1, ax
mov sub2, bx
mov borrow1, SI
mov ah, 4ch
int 21h
end start
end

Result sum1 = 3b73h, sum2 = 62E3h, carry1 = 0001h, sub1 = 52CDh, sub2 =
E67Eh, borrow1 = FFFFh

------------------------------------------------
8-bit signed multiplication & division
------------------------------------------------
dosseg
.model small
.stack 100h
.data
r1 db -41h
r2 db 07h
mul1 dw ?
div1 db ?
rem1 db ?
.code
start:
mov ax, @data
mov ds, ax
mov al, r1
imul r2
mov mul1, ax
mov al, r1
mov ah, 0FFh
idiv r2
mov div1, al
mov rem1, ah
mov ah,4ch
int 21h
end start
end

Result mul1 FE39h


Div1 F7h
Rem1 FEh
-------------------------------------------------
16-bit signed multiplication & division
-------------------------------------------------
dosseg
.model small
.stack 100h
.data
r1 dw -4325h
r2 dw 2145h
mul1 dw ?
mul2 dw ?
div1 dw ?
rem1 dw ?
.code
start:
mov ax, @data
mov ds, ax
mov ax, r1
imul r2
mov mul1, ax
mov mul2, dx
mov ax, r1
mov dx, 0ffffh
idiv r2
mov div1, ax
mov rem1, dx
mov ah, 4ch
int 21h
end start
end

Result mul1 =2207h, mul2 = F746h, div1 = FFFEh, rem1 = FF65h


-------------------------
Multi-byte Addition
-------------------------
dosseg
.model small
.stack 100h
.data
array1 db 21h, 32h, 26h, 34h, 57h
array2 db 47h, 27h, 32h, 44h, 87h
array3 db ?
.code
start:
mov ax, @data
mov ds, ax
mov dl, 00h
mov cl,05h
lea SI, array1
lea DI, array2
lea bx, array3
L1: mov al, [SI]
adc al, [DI]
mov [bx], al
inc SI
inc DI
inc bx
dec cl
jnz L1
adc dl, 00h
mov [bx], dl
mov ah, 4ch
int 21h
end start
end

Result 68h, 59h, 58h, 78h, DEh

-----------------------------
Multi-byte Subtraction
-----------------------------
dosseg
.model small
.stack 100h
.data
array1 db 47h, 24h, 32h, 49h, 99h
array2 db 23h, 79h, 49h, 54h, 37h
array3 db ?
.code
start:
mov ax, @data
mov ds, ax
mov dl, 00h
mov cl,05h
lea SI, array1
lea DI, array2
lea bx, array3
L1: mov al, [SI]
sbb al, [DI]
mov [bx], al
inc SI
inc DI
inc bx
dec cl
jnz L1
sbb dl, 00h
mov [bx], dl
mov ah, 4ch
int 21h
end start
end

Result 24h, abh, e8h, f4h, 61h


------------------------------------
ASCII Arithmetic Operations
------------------------------------
dosseg
.model small
.stack 100h
.data
asum dw ?
adif dw ?
amul dw ?
aquo dw ?
arem dw ?
.code
start:
mov ax, @data
mov ds, ax
mov al, '7'
mov bl, '6'
mov ah, 00h
add al, bl
AAA
add ax, 3030h
mov asum, ax
mov al, '9'
mov ah, 00h
sub al, bl
AAS
add ax, 3030h
mov adif, ax
mov al, 04h
mov bl, 05h
mul bl
AAM
add ax, 3030h
mov amul, ax
mov ax, 0406h
mov bl, 02h
AAD
div bl
mov aquo, ax
mov arem, dx
mov ah, 4ch
int 21h
end start
end

Result asum 3133h


Adif 3033h
Amul 3230h
Aquo 0017h

---------------------------------------------
No. of positve& negative numbers
---------------------------------------------
dosseg
.model small
.stack 100h
.data
array db 28h, 98h, -48h ,-56h, 12h
pcount db ?
ncount db ?
.code
start:
mov ax, @data
mov ds, ax
mov dl, 05h
mov bl, 00h
mov cl, 00h
lea SI, array
L3: mov al, [SI]
shl al, 01h
jnc l1
inc cl
jmp L2
L1: inc bl
L2: inc SI
dec dl
jnz L3
mov pcount, bl
mov ncount, cl
mov ah ,4ch
int 21h
end start
end

Result pcount = 02h


Ncount = 03h
-----------------------------------
No. of even & odd numbers
-----------------------------------
dosseg
.model small
.stack 100h
.data
array db 28h, 67h, 48h, 59h, 12h
ecount db ?
ocount db ?
.code
start:
mov ax, @data
mov ds, ax
mov dl, 05h
mov bl, 00h
mov cl, 00h
lea SI, array
L3: mov al, [SI]
shr al, 01h
jnc l1
inc cl
jmp L2
L1: inc bl
L2: inc SI
dec dl
jnz L3
mov ecount, bl
mov ocount, cl
mov ah, 4ch
int 21h
end start
end

Result ecount = 03h


Ocount = 02h
---------------------------------------
Packed BCD to Unpacked BCD
---------------------------------------
dosseg
.model small
.stack 100h
.data
pack db 12h
unpack dw ?
.code
start:
mov ax, @data
mov ds, ax
mov al, pack
and al, 0Fh
mov ah, pack
and ah, 0F0h
mov cl, 04h
rol ah, cl
mov unpack, ax
mov ah, 4ch
int 21h
end start
end

Result unpack = 0102h


--------------------------------
BCD to ASCII Conversion
--------------------------------
dosseg
.model small
.stack 100h
.data
array1 db 02h, 05h, 03h, 07h, 01h
count db 05h
array2 db ?
.code
start:
mov ax, @data
mov ds, ax
mov cl, count
lea SI, array1
lea DI, array2
L1: mov al, [SI]
add al, 30h
mov [DI], al
inc SI
inc DI
dec cl
jnz L1
mov ah, 4ch
int 21h
end start
end

Result 32h,35h,33h,37h,31h
---------------------------------------------------
Arranging Numbers in Ascending Order
---------------------------------------------------
dosseg
.model small
.stack 100h
.data
array db 32h, 45h, 7Eh, 83h, 76h
.code
start:
mov ax, @data
mov ds, ax
mov dx, 04h
L3: mov cx, dx
lea SI, array
L2: mov al, [SI]
cmp al, [SI + 01h]
jl L1
mov bl, [SI]
xchg bl, [SI + 01h]
mov [SI], bl
L1: inc SI
dec cx
jnz L2
dec dx
jnz L3
mov ah, 4ch
int 21h
end start
end

Result 83h, 32h, 45h, 76h, 7Eh


-------------------------
Reverse of a String
-------------------------
dosseg
.model small
.stack 100h
.data
str1 db 'mvgrcoe$'
.code
start:
mov ax, @data
mov ds, ax
mov al, '$'
mov cl, 00h
lea SI, str1
L2: cmp al, [SI]
jz L1
inc cl
inc SI
jmp L2
L1: dec SI
mov DI, SI
shr cl, 01h
lea SI, str1
L3: mov al, [SI]
xchg al, [DI]
mov [SI], al
inc SI
dec DI
dec cl
jnz L3
lea dx, str1
mov ah, 09h
int 21h
mov ah, 4ch
int 21h
end start
end

Result eocrgvm
------------------------------------------------------------------------
Moving a block of Data from one Array to another Array
------------------------------------------------------------------------
dosseg
.model small
.stack 100h
.data
array1 db 'mvgr$'
array2 db ?
.code
start:
mov ax, @data
mov ds, ax
lea SI, array1
lea DI, array2
mov cl, 04h
L1: mov al, [SI]
mov [DI], al
inc SI
inc DI
dec cl
jnz L1
mov ah, 4ch
int 21h
end start
end

Result mvgr
------------------
String Length
-----------------
dosseg
.model small
.stack 100h
.data
str1 db 'mvgrcoe$'
len1 db ?
.code
start:
mov ax, @data
mov ds, ax
mov al, '$'
mov cl, 00h
lea SI, str1
L2: cmp al, [SI]
jz L1
inc cl
inc SI
jmp L2
L1: mov len1, cl
mov ah, 4ch
int 21h
end start
end
Result 07h
-----------------------------------------
Inserting a Character in a String
-----------------------------------------
dosseg
.model small
.stack 100h
.data
str1 db 'mvgroe$'
str2 db ?
.code
start:
mov ax, @data
mov ds, ax
lea SI, str1
lea DI, str2
mov cl, 00h
L1: mov al, [SI]
cmp al, '$'
jz L4
inc cl
cmp cl, 05h
jz L3
mov [DI], al
inc SI
inc DI
jmp L1
L3: mov al, 'c'
mov [DI], al
inc DI
jmp L1
L4: mov al, '$'
mov [DI], al
lea dx, str2
mov ah, 09h
int 21h
mov ah, 4ch
int 21h
end start
end

Result mvgrcoe
-----------------------------------------
Deleting a Character in a String
-----------------------------------------
dosseg
.model small
.stack 100h
.data
str1 db 'mvgrcofe$'
str2 db ?
.code
start:
mov ax, @data
mov ds, ax
lea SI, str1
lea DI, str2
mov cl, 00h
L1: mov al, [SI]
cmp al, '$'
jz L4
inc cl
cmp cl, 07h
jz L3
mov [DI], al
inc SI
inc DI
jmp L1
L3: inc SI
jmp L1
L4: mov al, '$'
mov [DI], al
lea dx, str2
mov ah, 09h
int 21h
mov ah, 4ch
int 21h
end start
end

Result mvgrcoe
------------------------
String Comparison
------------------------
dosseg
.model small
.stack 100h
.data
str1 db 'mvgrcoe$'
str2 db 'mvgrcoe$'
mes1 db 'strings are equal$'
mes2 db 'strings are not equal$'
.code
start:
mov ax, @data
mov ds, ax
lea SI, str1
lea DI, str2
mov cl, 00h
mov dl, 00h
mov al, '$'
L2: cmp al, [SI]
jz L4
inc cl
inc SI
jmp L2
L4: cmp al, [DI]
jz L3
inc dl
inc di
jmp L4
L3: cmp cl, dl
jne L5
lea SI, str1
lea di, str2
L6: mov al, [SI]
cmp al, [DI]
jne L5
inc SI
inc DI
dec cl
jnz L6
lea dx, mes1
jmp L7
L5: lea dx, mes2
L7: mov ah, 09h
int 21h
mov ah ,4ch
int 21h
end start
end

Result strings are equal


------------------------------------------------------------------------------
Read a Character from Keyboard and Echo it on the Monitor
------------------------------------------------------------------------------
dosseg
.model small
.stack 100h
.data
char1 db ?
.code
start:
mov ax, @data
mov ds, ax
mov ah, 01h
int 21h
mov char1, al
mov ah ,4ch
int 21h
end start
end
Result g
--------------------------------------------------------------------------------------
Read a Character from Keyboard without Echoing it on the Monitor
--------------------------------------------------------------------------------------
dosseg
.model small
.stack 100h
.data
char1 db ?
.code
start:
mov ax, @data
mov ds, ax
mov ah, 07h
int 21h
mov char1, al
mov ah ,4ch
int 21h
end start
end

Result j
-----------------------------------------------------------------------------------------
Read a String of Characters from Keyboard until Enter Key is pressed
-----------------------------------------------------------------------------------------
dosseg
.model small
.stack 100h
.data
str1 db ?
.code
start:
mov ax, @data
mov ds, ax
lea dx, str1
mov ah, 0Ah
int 21h
mov ah ,4ch
int 21h
end start
end

Result srikanth
---------------------------------------------------
To send a Character on to the Monitor
---------------------------------------------------
dosseg
.model small
.stack 100h
.code
start:
mov dl, 's'
mov ah, 02h
int 21h
mov ah ,4ch
int 21h
end start
end

Result s
----------------------------------------------------------------
To send a String of characters on to the Monitor
----------------------------------------------------------------
dosseg
.model small
.stack 100h
.data
str1 db 'mvgrcoe$'
.code
start:
mov ax, @data
mov ds, ax
lea dx, str1
mov ah, 09h
int 21h
mov ah ,4ch
int 21h
end start
end

Result mvgrcoe

mov r0,#05h
mov r1,#60h
loop:mov a,p0
mov @r1,a
inc r1
dec r0
cjne r0,#00h,loop
end
Result bb 23 45 67 54

mov dptr,#1000h
mov R0,#0ah
mov a,#00h
mov r1,a
l1:movc a,@a+dptr
mov p0,a
inc r1
mov a,r1
dec r0
cjne r0,#00h,l1
org 1000h
db 1h,2h,3h,4h,5h,6h,7h,8h,9h,0h
end

Result 1h,2h,3h,4h,5h,6h,7h,8h,9h,0h

setb tr0
mov tmod,#00h
clr Tr0
setb Tr0
mov tmod,#01h
clr Tr0
setb Tr0
mov tmod,#02h
clr Tr0
setb Tr0
mov tmod,#03h
clr Tr0
end

Result
0: 13Bit Timer/Counter
1: 16Bit Timer/Counter
2: 8 Bit auto-reload
3: Two 8 Bit Timer/Cnt

mov tmod,#20h
mov th1,#0fdh
mov scon,#50h
setb tr1
mov a, #'c'
acall trans
mov a, #'a'
acall trans
mov a,#'t'
acall trans
acall xx
trans:mov sbuf,a
here: jnb ti,here
ret
xx:
end

Result
cat

You might also like