MPMC Programs

Download as pdf or txt
Download as pdf or txt
You are on page 1of 85

Only for reference

MPMC MASTER COPY

By samba
Only for reference

Programs based on hardware using 8086 kit

1. 8-Bit arithmetic operations


2. 16-Bit arithmetic operations
3. 32-Bit Addition
4. 32-Bit Subtraction
5. Swapping of two numbers
6. Factorial of a number

By samba
Only for reference

8-Bit Arithmetic Operations


ADDRESS OPCODE LABEL MNEMONIC OPERANDS COMMENTS

2000 8A0E0030 MOV CL,[3000H] Move data from


3000 address to
CL.

2004 8A2E0130 MOV CH,[3001H] Move data from


3001 address to
CH.

2008 8A1E0030 MOV BL,[3000H]


Move data from
3000 address to
BL.

200C 8A3E0130 MOV BH,[3001H]


Move data from
3001 address to
BH.

2010 8A060130 MOV AL,[3001H] Move data from


3001 address to
AL.

2014 B400 MOV AH,00H Assign data 00h


to AH

Add the data in


2016 02E9 ADD CH,CL
CH and CL.

Subtract the data


2018 2AFB SUB BH,BL in CH, CL.

201A F6E3 MUL BL Multiply the data

By samba
Only for reference

in AX and BL.

201C 882E0630 MOV [3006H],CH Move data from


CH to 3006
address.

2020 883E0830 MOV [3008H],BH Move data from


BH to 3008
address.

Move data from


2024 89060A30 MOV [300AH],AX AX to 300A
address.

Move data from


2028 8A060030 MOV AL,[3000H]
3000 address to
AL.

202C B400 MOV AH,00H Assign the data


00h to AL

Move data from


202E 8A160130 MOV DL,[3001H] 3001 address to
DL.

Divide the data in


2032 F6F2 DIV DL
AX,DL

Move data from


2034 88060C30 MOV [300CH],AL AL to 300C
address.

By samba
Only for reference

2038 88260E30 MOV [300EH],AH Move data from


AH to 300E
address.

203C F4 HLT Halt the program.

RESULT:
Inputs: 34H, 12H

Outputs:

Addition: 46h

Subtraction: DEH

Multiplication: 03A8H

Division: reminder=10H Quotient=02H

By samba
Only for reference

16-Bit Arithmetic Operations


ADDRESS OPCODE LABEL MNEMONIC OPERANDS COMMENTS

2000 8B060030 MOV AX,[3000H] Move data from


3000 address to
AX.

2004 8B1E0230 MOV BX,[3002H] Move data from


3002 address to
BX.

2008 8B0E0030 MOV CX,[3000H]


Move data from
3000 address to
CX.

200C 8A160230 MOV DX,[3002H]


Move data from
3002 address to
DX.

2010 03C3 ADD AX,BX Add the data in


AX and BX.

Subtract the data


2012 2BCA SUBB CX,DX in CX, DX.

2014 89060630 MOV [3006H],AX Move data from


AX to 3006
address.
2018 890E0830 MOV [3008H],CX
Move data from
CX to 3008

By samba
Only for reference

201C 8B060030 MOV AX,[3000H] address.

Move data from


3000 address to
AX.
2020 F7E3 MUL BX Multiply the data
in AX and BX.

2022 89060A30 MOV [300AH],CH Move data from


AX to 300A
address.

2026 89160C30 MOV [300CH],DX Move data from


DX to 300C
address.

202A 8B060030 MOV AX,[3000H]


Move data from
3000 address to
AX.

Assign the data


202E BA0000 MOV DX,0000H 0000H to DX.

2031 F7F3 DIV BX Divide the data


in AX,BX

Move data from


2033 89060E30 MOV [300EH],AX
AX to 300E
address.

2037 89161030 MOV [3010H],AX Move data from


DX to 3010H

By samba
Only for reference

address.

203B F4 HLT Halt the program

RESULT:
Inputs: 5678H, 1234H

Outputs:

Addition: 68ACH

Subtraction: 4444H

Multiplication: 06260060H

Division: reminder=0DA8H Quotient=0004H

By samba
Only for reference

32-Bit Addition
ADDRESS OPCODE LABEL MNEMONIC OPERANDS COMMENTS

2000 8B 060030 MOV AX,[3000H] Move data from


3000 address to
AX.

2004 8B1E0230 MOV BX,[3002H] Move data from


3002 address to
BX.

2008 8B0E0430 MOV CX,[3004H]


Move data from
3004 address to
CX.

200C 8B160630 MOV DX,[3006H]


Move data from
3006 address to
DX.

2010 03C1 ADD AX,CX Add the data in


AX and CX.

Add the data in


2012 13DA ADC BX,DX BX, DX along
with carry flag
bit.

Move data from


2014 89060830 MOV [3008H],AX AX to 3008
address.

2018 891E0A30 MOV [300AH],BX


Move data from

By samba
Only for reference

BX to 300A
address.

Halt the program


201C F4 HLT

RESULT:
Inputs: 12345678H,87654321 H

Output:

Addition: 99999999H

By samba
Only for reference

32-Bit Subtraction
ADDRESS OPCODE LABEL MNEMONIC OPERANDS COMMENTS

2000 8B060030 MOV AX,[3000H] Move data from


3000 address to
AX.

2004 8B1E0230 MOV BX,[3002H] Move data from


3002 address to
BX.

2008 8B0E0430 MOV CX,[3004H]


Move data from
3004 address to
CX.

200C 8B160630 MOV DX,[3006H]


Move data from
3006 address to
DX.

2010 2BC1 SUB AX,CX Subtract the data


in AX and CX.

Subtract the data


2012 1BDA SBB BX,DX in DX and carry
flag bit from data
in BX.

Move data from


2014 89060830 MOV [3008H],AX AX to 3008
address.

2018 891E0A30 MOV [300AH],BX


Move data from

By samba
Only for reference

BX to 300A
address.

Halt the program


201C F4 HLT

RESULT:
Inputs: 56781234H,12345678H

Output:

Subtraction: 4443BBBCH

By samba
Only for reference

Swapping of two numbers


ADDRESS OPCODE MNEMONIC OPERANDS COMMENTS

2000 8B060030 MOV AX,[3000H] Move data from


3000H to AX.

Move data from


2004 8B1E0230 MOV BX,[3002H] 3002H to BX.

2008 8BCB MOV CX,BX Move data from BX


to CX.

200A 8BD8 MOV BX,AX Move data from


AX to BX.

200C 8BC1 MOV AX,CX


Move data from CX
to AX.
200E 89060030 MOV [3000H],AX Move data from AX
to 3000H.

2012 Move data from BX


891E0230 MOV [3002H],BX
to [3002H].

2016 F4 HLT
Halt the program

RESULT: INPUT 1111H, 2222H

OUTPUT 2222H, 1111H

By samba
Only for reference

Factorial of a number
ADDRESS OPCODE LABEL MNEMONIC OPERANDS COMMENTS

2000 B80100 MOV AX,0001H The contents are


moved from
0001H to AX.

2003 8B0E0030 MOV CX,[3000H] Move data to CX


from 3000H.

200B 7405 JE L1 If equal then


jump to L1.

Multiply data in
200D F7E1 L2: MUL CX CX,AX.

200F 49 DEC CX Decrement the


value in CX by
1.
2010 75FB JNZ L2
Jump if non zero
to L2.

2012 89060230 L1: MOV[3002H],AX Move data in AX


to 3002H
address.
2016 F4 HLT Halt the
program

RESULT
INPUT 04H
OUTPUT 18H

By samba
Only for reference

MASM PROGRAMS

1. 8-bit arithmetic operations


2. 16-bit arithmetic operations
3. 32-bit arithmetic operations
4. Signed Multiplication
5. Signed Division
6. Multi Byte Addition
7. No. of positive and negative numbers
8. No. of even and odd numbers
9. Arranging the numbers of an array in ascending order
10. ASCII arithmetic operations
11. Conversion of packed BCD number to unpacked BCD number
12. Conversion of BCD number to ASCII form
13. Moving a block of data from array1 to array2
14. Length of a string
15. Reverse of a string
16. String is palindrome or not
17. Comparison between two strings
18. Inserting a character in a string
19. Deleting a character in a string
20. Read a character from keyboard and echo it on monitor
21. Read a character from keyboard and do not echo it on monitor
22. To send a character to monitor
23. To send a string of characters to monitor
24. Read a string of characters from keyboard and echo it on monitor

By samba
Only for reference

8-Bit Arithmetic operations


.dosseg
.model small
.stack 100h
.data
num1 db 87h
num2 db 66h
sum db ?
carry db ?
diff db ?
brw db ?
pro dw ?
quo db ?
rem db ?
.code
start : mov ax,@data
mov ds,ax
mov ah,00h
mov al,num1
add al,num2
adc ah,00h
mov sum, al
mov carry, ah
xor ah,ah
mov al,num1

By samba
Only for reference

sub al,num2
adc ah,00h
mov diff,al
mov brw,ah
xor ah,ah
mov al,num1
mul num2
mov pro,ax
xor ah,ah
mov al,num1
div num2
mov quo,al
mov rem,ah
mov ax,4ch
int 21h
end start
end

RESULT:
INPUTS: 87H, 66H
OUTPUTS: Sum-0EDH
Carry-00H
Diff-21H
Brw-0H
Pro-35CAH
Quo-01H
Rem-21H

By samba
Only for reference

16-Bit Arithmetic Operations


..dosseg
.model small
.stack 100h
.data
a dw 1287h
b dw 5666h
sum dw ?
cary dw ?
diff dw ?
brw dw ?
pro1 dw ?
pro2 dw ?
quo dw ?
rem dw ?
.code
start : mov ax,@data
mov ds,ax
xor ax,ax
mov bx,0000h
mov ax,a
add ax,b
adc bl,00h
mov sum,ax
mov cary,bx
mov ax,a

By samba
Only for reference

xor bx,bx
sub ax,b
jnb l1
dec bx
l1: mov diff,ax
mov brw,bx
mov ax,4ch
int 21h
end start
end

RESULT:
INPUTS: 1287H, 5666H

OUTPUTS: Sum-68EDh
Carry-0000H
Diff-BC21H
Brw-0001H
Pro1-0BBCAH
Pro2-0640H
Quo-0004H
Rem-043DFH

By samba
Only for reference

32-Bit Arithmetic Operations


Addition
.dosseg
.model small
.stack 100h
.data
a1 dw 3000h
a2 dw 2222h
b1 dw 0f222h
b2 dw 1111h
sum1 dw ?
sum2 dw ?
car db ?
.code
start : mov ax,@data
mov ds,ax
mov ax,a1
add ax,b1
mov sum1,ax
mov ax,a2
adc ax,b2
mov bl,00h
jnc l1
inc bl
l1: mov sum2,ax
mov car,bl

By samba
Only for reference

mov ah,4ch
int 21h
end start
end

RESULT:
INPUTS: 22223000H, 1111F222H
OUTPUTS: sum1 -2222H
sum2 -3334H
car - 0000H

Subtraction
.dosseg

.model small

.stack 100h

.data

a1 dw 3000h

a2 dw 2222h

b1 dw 0f222h

b2 dw 1111h

diff1 dw ?

diff2 dw ?

brw db ?

.code

start : mov ax,@data

mov ds,ax

By samba
Only for reference

mov bl,00h

mov ax,a1

sub ax,b1

mov diff1,ax

mov ax,a2

sbb ax,b2

jnb l2

dec bl

l2: mov diff2,ax

mov brw,bl

mov ah,4ch

int 21h

end start

end

RESULT:
INPUTS: 22223000H, 1111F22

OUTPUTS: diff1 -3DDEH

diff2 -1110H

brw -0000H

By samba
Only for reference

Signed Multiplication
.dosseg

.model small

.stack 100h

.data

a1 db -2h

b1 db -6h

a2 dw -2370h

b2 dw 2307h

pro dw ?

pro1 dw ?

pro2 dw ?

.code

start : mov ax,@data

mov ds,ax

mov al,a1

mov ah,00h

imul b1

mov pro,ax

xor dx,dx

mov ax,a2

imul b2

mov pro1,ax

mov pro2, dx

By samba
Only for reference

mov ah,4ch

int 21h

end start

end

RESULT:
INPUTS: - 2H,-6H, -2370H, 2307H

OUTPUTS: Pro-0CH

Pro1-0B7F0H

Pro2-0FB26H

Signed Division
.dosseg

.model small

.stack 100h

.data

x1 db -64h

x2 db -08h

y1 dw -7856h

y2 dw -1234h

q1 db ?

rem1 db ?

q2 dw ?

rem2 dw ?

.code

By samba
Only for reference

start : mov ax,@data

mov ds,ax

mov ah,00h

mov al,x1

idiv x2

mov q1,al

mov rem1,ah

xor dx,dx

mov ax,y1

idiv y2

mov q2,ax

mov rem2,dx

mov ah,4ch

int 21h

end start

end

RESULT:
INPUTS: - 64H,-08H, -7856H, -1234H

OUTPUTS: q1-000CH

Rem1-0FFA4H

q2- 0006H

Rem2-99EEH

By samba
Only for reference

Multi Byte Addition


.dosseg

.model small

.stack 100h

.data

num1 db 01h,02h,03h,04h,05h

num2 db 06h,07h,08h,09h,0Ah

sum db ?

cary db ?

.code

start: mov ax,@data

mov ds,ax

mov cl,05h

xor ax,ax

xor dl,dl

xor bx,bx

mov si,offset num1

mov bx,offset num2

mov di,offset sum

l2: mov al,[si]

mov dl,[bx]

adc al,dl

mov [di],al

inc si

By samba
Only for reference

inc bl

inc di

loop l2

adc ah,00h

mov cary,ah

mov ah,4ch

int 21h

end start

end

RESULT:
INPUTS: num1- 01H,02H,03H,04H,05H

num2- 06H,07H,08H,09H,0AH

OUTPUTS: sum-07H,09H,0BH,0DH,0FH

Cary-00H

By samba
Only for reference

No. of positive and negative numbers

.dosseg

.model small

.stack 100h

.data

num1 dw -0003h,1230h,0159h,2579h

cnt db 04h

post dw ?

negt dw ?

.code

start: mov ax,@data

mov ds,ax

mov cl,cnt

mov bx,0000h

mov dx,0000h

mov si,offset num1

again: mov ax,[si]

shl ax,01h

jc l1

inc bx

jmp l2

l1: inc dx

l2: add si,02h

By samba
Only for reference

dec cl

jnz again

mov negt,dx

mov post,bx

mov ah,4ch

int 21h

end start

end

RESULT:
INPUTS: - 0003H,1230H,0159H,2579H

OUTPUTS: post-03H

negt- 01H

By samba
Only for reference

No. of even and odd numbers


.dosseg

.model small

.stack 100h

.data

num1 dw 2357h,0A59h,0C322h,0957h

cnt db 04h

oddf dw ?

evenf dw ?

.code

start: mov ax,@data

mov ds,ax

mov cl,cnt

mov bx,0000h

mov dx,0000h

mov si,offset num1

l3: mov ax,[si]

ror ax,01

jc l1

inc bx

jmp l2

l1: inc dx

l2: add si,02h

dec cl

By samba
Only for reference

jnz l3

mov oddf,dx

mov evenf,bx

mov ah,4ch

int 21h

end start

end

RESULT:
INPUTS: 2357H,0A59H,0C322H,0957H

OUTPUTS: oddf-03H

Evenf-01H

By samba
Only for reference

Arranging numbers of an array in ascending


order
.dosseg

.model small

.stack 100h

.data

num1 dw 005Eh,007Dh,0002h,0010h

cnt dw 0004h

.code

start: mov ax,@data

mov ds,ax

mov dx,cnt-1

l3: mov cx,dx

mov si,offset num1

l2: mov ax,[si]

cmp ax,[si+2]

jl l1

xchg [si+2],ax

xchg [si],ax

l1: add si,02h

loop l2

dec dx

jnz l3

mov ah,4ch

By samba
Only for reference

int 21h

end start

end

RESULT:
INPUTS: 005EH, 007DH, 0002H, 0010H

OUTPUTS: 0002H, 0010H, 005EH, 007DH

ASCII arithmetic operations


Addition
.dosseg

.model small

.stack 100h

.data

res dw ?

.code

start : mov ax,@data

mov ds,ax

mov al,"9"

mov bl,"9"

add al,bl

AAA

add ax,3030h

mov res,ax

By samba
Only for reference

mov ah,4ch

int 21h

end start

end

RESULT:
INPUTS: 09H,09H

OUTPUTS: res-3138H

Subtraction
.dosseg

.model small

.stack 100h

.data

res dw ?

.code

start : mov ax,@data

mov ds,ax

xor ax,ax

xor bx,bx

mov al,"9"

mov bl,"4"

sub al,bl

AAS

add ax,3030h

By samba
Only for reference

mov res,ax

mov ah,4ch

int 21h

end start

end

RESULT:
INPUTS: 09H,04H

OUTPUTS: res-3035H

Multiplication
.dosseg

.model small

.stack 100h

.data

res db ?

.code

start : mov ax,@data

mov ds,ax

xor ax,ax

xor bx,bx

mov al,"2"

mov bl,"3"

mul bl

AAM

By samba
Only for reference

add ax,3030h

mov res,al

mov ah,4ch

int 21h

end start

end

RESULT:
INPUTS: 02H,03H

OUTPUTS: res-3036H

Division
.dosseg

.model small

.stack 100h

.data

quo db ?

rem db ?

.code

start : mov ax,@data

mov ds,ax

xor ax,ax

xor bx,bx

mov al,"4"

mov bl,"2"

By samba
Only for reference

div bl

AAD

add ax,3030h

mov quo,al

mov rem,ah

mov ah,4ch

int 21h

end start

end

RESULT:
INPUTS: 04H,02H

OUTPUTS: res-3032H

By samba
Only for reference

Conversion of packed BCD number to


unpacked BCD number
.dosseg

.model small

.stack 100h

.data

a db 98h

res db ?

.code

start: mov ax,@data

mov ds,ax

mov di,offset res

mov cl,04h

mov al,a

mov bl,0F0h

and al,bl

ror al,cl

mov[di],al

mov al,a

mov bl,0Fh

and al,bl

mov [di+1],al

mov ah,4ch

int 21h

By samba
Only for reference

end start

end

RESULT:
INPUTS: 98H

OUTPUTS: 0908H

Conversion of BCD number to ASCII form


.dosseg

.model small

.stack 100h

.data

a db 98h

res db ?

.code

start: mov ax,@data

mov ds,ax

mov di,offset res

mov cl,04h

mov al,a

mov bl,0F0h

and al,bl

ror al,cl

add al,30h

mov [di],al

By samba
Only for reference

mov al,a

mov bl,0Fh

and al,bl

add al,30h

mov [di+1],al

mov ah,4ch

int 21h

end start

end

RESULT:
INPUTS: 98H

OUTPUTS: 3938H

By samba
Only for reference

Moving a block of data from array1 to array2


.dosseg
.model small
.stack 100h
.data
array1 db 59h,27h,03h,56h
array2 db ?
cnt db 04h
.code
start: mov ax,@data
mov ds,ax
mov cl,cnt
xor bl,bl
mov si,offset array1
mov di,offset array2
l1: mov bl,[si]
mov [di],bl
inc di
inc si
dec cnt
jnz l1
mov ah,4ch
int 21h
end start
end

By samba
Only for reference

RESULT:
INPUTS: arr1- 59H,27H,03H,56H
OUTPUTS: arr2- 59H,27H,03H,56H

Length of a string
.dosseg
.model small
.stack 100h
.data
string1 db "usha$"
stringlen db ?
.code
start: mov ax,@data
mov ds,ax
mov cl,00h
mov si,offset string1
mov al,"$"
l2: cmp al,[si]
je l1
inc cl
inc si
jmp l2
l1: mov stringlen,cl
mov ah,4ch
int 21h
end start
end

RESULT:
INPUTS: "usha$"
OUTPUTS: 04H

By samba
Only for reference

Reverse of a string
.dosseg

.model small

.stack 100h

.data

string1 db "usha$"

stringlen db ?

.code

start: mov ax,@data

mov ds,ax

mov cl,00h

mov si,offset string1

mov al,"$"

l2: cmp al,[si]

je l1

inc cl

inc si

jmp l2

l1: mov stringlen,cl

dec si

mov bx,offset string1

shr cl,01h

l3: mov al,[bx]

xchg al,[si]

By samba
Only for reference

mov [bx],al

inc bl

dec si

loop l3

mov ah,4ch

int 21h

end start

end

RESULT:
INPUTS: "usha$"

OUTPUTS: ahsu

String is palindrome or not


.dosseg

.model small

.stack 100h

.data

string1 db "madam$"

mes1 db "palindrome$"

mes2 db "notpalindrome$"

.code

start: mov ax,@data

mov ds,ax

mov cl,00h

By samba
Only for reference

mov si,offset string1

mov al,"$"

l: mov al,[si]

cmp al,"$"

jz l1

inc cl

inc si

jmp l

l1: dec si

shr cl,01h

mov bx,offset string1

l3: mov ah,[bx]

cmp ah,[si]

jnz l2

inc bx

dec si

loop l3

mov dx,offset mes1

jmp last

l2: mov dx,offset mes2

last: mov ah,09h

int 21h

mov ah,4ch

int 21h

end start

By samba
Only for reference

end

RESULT:
INPUTS: "madam$"

OUTPUTS: palindrome

Comparison between two strings


.dosseg

.model small

.stack 100h

.data

st1 db "rama$"

st2 db "ram$"

mes1 db "equal$"

mes2 db "notequal$"

.code

start: mov ax,@data

mov ds,ax

mov cl,00h

xor dl,dl

mov si,offset st1

mov bx,offset st2

l: mov dh,[si]

cmp dh,"$"

By samba
Only for reference

jz l1

inc dl

inc si

jmp l

l1: mov ch,[bx]

cmp ch,"$"

jz l2

inc bx

inc cl

jmp l1

l2: cmp dl,cl

jnz nope

mov si,offset st1

mov bx,offset st2

l3: mov al,[si]

cmp al,[bx]

jnz nope

inc si

inc bx

loop l3

mov dx,offset mes1

jmp last

nope: mov dx,offset mes2

last: mov ah,09h

By samba
Only for reference

int 21h

mov ah,4ch

int 21h

end start

end

RESULT:
INPUTS: “rama$",”ram$”

OUTPUTS: not equal

Inserting a character in a string


.dosseg

.model small

.stack 100h

.data

string1 db "god$"

.code

start: mov ax,@data

mov ds,ax

mov cl,00h

mov si,offset string1

mov al,"$"

l2: cmp al,[si]

je l1

By samba
Only for reference

inc cl

inc si

jmp l2

l1: dec si

mov bh,03h

sub cl,bh

add cl,01h

l3: mov dl,[si]

mov [si+1],dl

dec si

loop l3

mov al,"o"

mov [si+1],al

mov ah,4ch

int 21h

end start

end

RESULT:
INPUTS: "god$"

OUTPUTS: good

By samba
Only for reference

Deleting a character in a string


.dosseg

.model small

.stack 100h

.data

string1 db "life$"

.code

start: mov ax,@data

mov ds,ax

mov cl,00h

mov si,offset string1

mov al,"$"

l2: cmp al,[si]

je l1

inc cl

inc si

jmp l2

l1: mov bl,03h

sub cl,bl

mov bh,cl

l4: dec si

loop l4

mov bh,cl

l3: mov al,[si]

By samba
Only for reference

mov [si-1],al

inc si

loop l3

mov ah,4ch

int 21h

end start

end

RESULT:
INPUTS: "life$"

OUTPUTS: lie

Read a character from keyboard and echo it


on monitor

.dosseg

.model small

.stack 100h

.data

a db ?

.code

start: mov ax,@data

mov ds,ax

mov ah,01h

int 21h

By samba
Only for reference

mov a,al

mov ah,4ch

int 21h

end start

end

RESULT:
INPUTS: a

OUTPUTS: a

Read a character from keyboard and without


echo it on monitor

.dosseg

.model small

.stack 100h

.data

a db ?

.code

start: mov ax,@data

mov ds,ax

mov ah,07h

int 21h

mov a,al

By samba
Only for reference

mov ah,4ch

int 21h

end start

end

RESULT:
INPUTS: a

OUTPUTS: a(It will take the character but it won’t be echoed on monitor)

To send a character to monitor


.dosseg

.model small

.stack 100h

.data

a db "u"

.code

start: mov ax,@data

mov ds,ax

mov dl,a

mov ah,02h

int 21h

mov ah,4ch

int 21h

end start

By samba
Only for reference

end

RESULT:
INPUTS: u

OUTPUTS: u

To send a string of characters to monitor


.dosseg

.model small

.stack 100h

.data

sr db "mpmc$"

.code

start: mov ax,@data

mov ds,ax

LEA dx,sr

mov ah,09h

int 21h

mov ah,4ch

int 21h

end start

end

RESULT:
INPUTS: "mpmc$"

OUTPUTS: mpmc

By samba
Only for reference

Read a string of characters from keyboard


and echo it on monitor
.dosseg

.model small

.stack 100h

.data

sr db ?

.code

start: mov ax,@data

mov ds,ax

LEA dx,sr

mov ah,0Ah

int 21h

mov ah,4ch

int 21h

end start

end

RESULT:
INPUTS: “josh$”

OUTPUTS: josh

By samba
Only for reference

Interfacing programs with 8086


microprocessor
1. 8255-Programmable peripheral interface- 1

2. 8255-Programmable peripheral interface- 2

3. 8255-Programmable peripheral interface- 3

4. 8279-Keyboard display

5. 8259-Programmable interrupt controller

6. 8251/8253-USART

By samba
Only for reference

8255(PPI)-1
To configure port A, port B as output ports
ADDRESS OPCODE LABEL MNEMONIC OPERANDS
2000 B0 80 MOV AL,80H

2002 BA 86 00 MOV DX,0086H

2005 EE OUT DX,AL

2006 B0 EE BACK: MOV AL,EEH

2008 BA 80 00 MOV DX,0080H

200B EE OUT DX,AL

200C B0 FF MOV AL,FFH

200E BA 82 00 MOV DX,0082H

2011 EE OUT DX,AL

2012 E9 F1 FF JMP BACK

2015 F4 HLT

RESULT: The data displayed at port A is EEH and at port B is FFH.

By samba
Only for reference

8255(PPI)-2
To configure port A as output and port B as
input port to find the complement of a number

ADDRESS OPCODE LABEL MNEMONIC OPERANDS


2000 B0 82 MOV AL,80H

2002 BA 86 00 MOV DX,0086H

2005 EE OUT DX,AL

2006 BA 82 00 BACK: MOV AL,EEH

2009 EC IN DX,0080H

200A F6 00 NOT DX,AL

200C BA 80 00 MOV AL,FFH

200F EE OUT DX,0082H

2010 E9 F3 FF JMP DX,AL

2013 F4 HLT BACK

RESULT: Input at port B is EEH ; Output at port A is 11H

By samba
Only for reference

8255(PPI)-3
To configure port A as output and port B as input
port to find the factorial of a number
ADDRESS OPCODE LABEL MNEMONIC OPERANDS
2000 B0 82 MOV AL,82H

2002 BA 86 00 MOV DX,0086H

2005 EE OUT DX,AL

2006 BA 82 00 L1: MOV DX,0082H

2009 EC IN AL,DX

200A B9 00 00 MOV CX,0000H

200D 8A C8 MOV CL,AL

200F B8 01 00 MOV AX,0001H

2012 BB 01 00 MOV BX,0001H

2015 F7 E3 L2: MUL AX,BX

2017 43 INC BX

2018 E2 FB LOOP L2

201A BA 80 00 MOV DX,0080H

201D EE OUT DX,AL

201E EB E6 JMP L1

2021 F4 HLT

RESULT: Input at port B is 04H ; output at port A is 18H

By samba
Only for reference

8279-Keyboard display
PROGRAM TO DISPLAY THE VALUE OF THE KEY PRESSED
IN THE DISPLAY FIELD USING ENCODE METHOD

COMMAND PORT = 0082H

DATA PORT = 0080H

ORG 2000H

MOVW SI,#3000

MOVB AL,#00

MOVW DX,#82 ; INITIALIZE 8279

OUTB DX,AL

MOVB AL,#90

OUTB DX,AL

MOVW CX,#08

MOVB AL,#00 ; CLEAR THE

MOVW DX,#80 ; DISPLAY

OUTB DX,AL

LOOP 200F

MOVW DX,#82

INB AL,DX

ANDB AL,#07

JZ 2017

MOVW SI,#3000

MOVB AL,#40 ; READ FIFO

OUTB DX,AL

MOVW DX,#80

By samba
Only for reference

INB AL,DX

ANDB AL,#1F

MOVB AH,#00

MOVW CX,AX

ADDW SI,CX

MOVW DX,#82

OUTB DX,AL ;DISPLAY 0

MOVW DX,#80

MOVB AL,#F3

OUTB DX,AL

MOVW DX,#82

MOVB AL,#95

OUTB DX,AL

MOVW DX,#80

MOVB AL,[SI]

OUTB DX,AL

JMP 2017

ORG 3000H

LOOP: DB 0F3H,60H,0B5H,0F4H,66H

DB 0D6H,0D7H,70H,0F7H,76H

DB 77H,0C7H,93H,0E5H,97H

DB 17H,00H,76H,77H,0C7H

DB 93H,0E5H,97H,17H,00H

RESULT: Input: 05(key pressed in keyboard)

Output: 05(value displayed in display)

By samba
Only for reference

8259-Programmable interrupt controller

ORG 2000H

CLI ;CLEAR INTERRUPT FLAG

MOVW AX, #0000 ;INITIALIZE SEGMENT

MOVW CX, AX ;REGISTERS

MOVW ES, AX

MOVW SS, AX

MOVW SP, #3000 ;INITIALIZE SP

;INTERRUPT VECTOR INITIALIZATION

ES

MOVW 0120, #2200 ;INT0 VECTOR ADDRESS

ES

MOVW 0122, #0000 ;(SLAVE)

ES

MOVW 0124, #2250 ;INT1 VECTOR ADDRESS

ES

MOVW 0126, #0000 ;(SLAVE)

ES

MOVW 0128, #2300 ;INT2 VECTOR ADDRESS

ES

MOVW 012A, #0000 ;(SLAVE)

ES

MOVW 012C, #2350 ;INT3 VECTOR ADDRESS

By samba
Only for reference

ES

MOVW 012E, #0000 ;(SLAVE)

ES

MOVW 0130, #2400 ;INT4 VECTOR ADDRESS

ES

MOVW 0132, #0000 ;(SLAVE)

ES

MOVW 0134, #2450 ;INT5 VECTOR ADDRESS

ES

MOVW 0136, #0000 ;(SLAVE)

ES

MOVW 0138, #2500 ;INT6 VECTOR ADDRESS

ES

MOVW 013A, #0000 ;(SLAVE)

ES

MOVW 013C, #2550 ;INT7 VECTOR ADDRESS

ES

MOVW 013E, #0000 ;(SLAVE)

INITIALIZATION SEQUENCE FOR SLAVE

MOVW DX,#0090 ;ICW1

MOVB AL,#15 ;SGL MODE, ICW4 NEEDED

EE

OUTB DX ;EDGE TRIGGERED INTERRUPT

MOVW DX,#0092 ;ICW2

By samba
Only for reference

MOVB AL,#48 ;BASE ADDRESS = 72d

OUTB DX ;FOR TYPE 48 INTERRUPT

MOVB AL,#00 ;ICW3 (SLAVE)

OUTB DX ;SLAVE ID = 000

MOVB AL,#05 ;ICW4

OUTB DX ;86/88 MODE, AEOI

MOVB AL, #00 ;OCW1

OUTB DX ;NO INTERRUPTS MASKED ON SLAVE

;INITIALIZATION SEQUENCE FOR MASTER INTERRUPT CONTROLLER

MOVW DX,#0FFF4 ;ICW1

MOVB AL , #15 ;CAS MODE,ICW4 NEEDED

OUTB DX ;EDGE TRIGGERED INTERRRUPT

MOVW DX, #0FFF6 ;ICW2

MOVB AL, #48 ;BASE ADDRESS =72d

OUTB DX

MOVB AL, #01 ;ICW3 (MASTER)

OUTB DX ;IR0 HAS A SLAVE ON IT

MOVB AL, #0D ;ICW4 (MASTER)

OUTB DX ;86/88 MODE, AEOI

MOVB AL, #0FE ;OCW1 ALL INTERRUPTS

OUTB DX ;ARE MASKED EXCEPT INT0

STI ;SET INTERRUPT FLAG

JMP 20A8

DB 0A ,0A

By samba
Only for reference

DB 0D

ASC ’INTERRUPT - ‘

DB 00

ASC ‘OCCURRED ! ‘

DB 00

ORG 2200 :ISR FOR INTERRUPT 0

CLI

CS

LEA DX, 20AA

MOVW AX,DX

CALLS FE00:1B55

MOVB AL, #30

CALLS FE00:1B50

CS

LEA DX, 20BA

MOVW AX, DX

CALLS FE00:1B55

INT3

ORG 2250 :ISR FOR INTERRUPT 1

CLI

CS

LEA DX, 20AA

MOVW AX,DX

By samba
Only for reference

CALLS FE00:1B55

MOVB AL, #31

CALLS FE00:1B50

CS

LEA DX, 20BA

MOVW AX,DX

CALLS FE00:1B55

INT3

ORG 2300 :ISR FOR INTERRUPT 2

CLI

CS

LEA DX, 20AA

MOVW AX,DX

CALLS FE00:1B55

MOVB AL, #32

CALLS FE00:1B50

CS

LEA DX, 20BA

MOVW AX,DX

CALLS FE00:1B55

INT3

ORG 2350 :ISR FOR INTERRUPT 3

CLI

CS

LEA DX, 20AA

By samba
Only for reference

MOVW AX,DX

CALLS FE00:1B55

MOVB AL, #33

CALLS FE00:1B50

CS

LEA DX, 20BA

MOVW AX,DX

CALLS FE00:1B55

INT3

ORG 2400 :ISR FOR INTERRUPT 4

CLI

CS

LEA DX, 20AA

MOVW AX,DX

CALLS FE00:1B55

MOVB AL, #34

CALLS FE00:1B50

CS

LEA DX, 20BA

MOVW AX,DX

CALLS FE00:1B55

INT3

ORG 2450 :ISR FOR INTERRUPT 5

CLI

CS

By samba
Only for reference

LEA DX, 20AA

MOVW AX,DX

CALLS FE00:1B55

MOVB AL, #35

CALLS FE00:1B50

CS

LEA DX, 20BA

MOVW AX,DX

CALLS FE00:1B55

INT3

CLI

CS

LEA DX, 20AA

MOVW AX,DX

CALLS FE00:1B55

MOVB AL, #36

CALLS FE00:1B50

CS

LEA DX, 20BA

MOVW AX,DX

CALLS FE00:1B55

INT3

ORG 2550 :ISR FOR INTERRUPT 7

CLI

CS

LEA DX, 20AA

By samba
Only for reference

MOVW AX,DX

CALLS FE00:1B55

MOVB AL, #37

CALLS FE00:1B50

CS

LEA DX, 20BA

MOVW AX,DX

CALLS FE00:1B55

INT3

RESULT:
Input: Interrupt 3(set the dip switch in interfacing kit)

Output: Interrupt 3 occurred(displayed on the monitor)

By samba
Only for reference

8251/8253-USART
TO DISPLAY "WELCOME TO GSAS STUDY CARD"
FOR 9600 BAUD.

EXECUTE THE PROGRAM FROM 2000H

CONTROL REGISTER 8253 = 0080H

DATA PORT 8251 = 0090H

COMMAND PORT 8251 = 0092H

ORG 2000H

MOV AL,36

MOV DX,0086

OUT DX,AL

MOV DX,0080 ;Timer 0 in mode 3

MOV AL,0A

OUT DX,AL

MOV AL,00

OUT DX,AL

MOV SP,3000

MOV DX,0092 ;Initialize USART

OUT DX,AL

OUT DX,AL

OUT DX,AL

OUT DX,AL

CALL 304A

By samba
Only for reference

MOV AL,40 ;Reset 8251

OUT DX,AL

CALL 304A

MOV AL,CE

OUT DX,AL

CALL 304A

MOV AL,27

OUT DX,AL

CALL 304A

MOV SI,3100

MOV DX,0092 ;Get USART status

IN AL,DX

AND AL,81

CMP AL,81

JNE 3031

MOV AL,[SI]

INC SI

CMP AL,00

JE 3049

MOV DX,0090

OUT DX,AL

JMP 3031

INT 03

ORG 2100H

DB 0A,0A

DB 0A,0A

By samba
Only for reference

DB 0A,0A

DB 0A,0A

DB 20,20

DB 20,20

DB 20,20

DB 20,20

ASC'WELCOME TO GSAS STUDY CARD'

RESULT:
Output: WELCOME TO GSAS STUDY CARD (displayed on the monitor)

By samba
Only for reference

KIEL software programs

1. Write a data into port 0 from memory

2. To send the data from port to given memory location

3. Write a data into port 0 from memory

4. Timer program

By samba
Only for reference

Write a data into port 0 from memory

Mov dptr,#1000h

Mov r0,#0ah

Mov a,#00h

Mov r1,a

Loop: movc a,@a+dptr

Mov p0,a

Inc r1

Mov a,r1

Dec r0

Cjne r0,#00h,loop

Org 1000h

Db 23h,44h,98h,65h,03h,93h,82h,04h,00h,07h

End

RESULT:
Output : 23h,44h,98h,65h,03h,93h,82h,04h,00h,07h is written into port0

By samba
Only for reference

To send the data from port to given memory


location

mov a,p0
mov r0,a
mov r1,#60h
loop: mov a,p0
mov @r1,a
inc r1
dec r0
cjne r0,#00h,loop
end

RESULT:
Given input: 33h, 04h, 06h

Expected output: at 60h: 33h, 61h: 04h, 62h: 06h

Obtained output: at 60h: 33h, 61h: 04h, 62h: 06h

By samba
Only for reference

To transfer the data to the serial port


mov tmod,#20h
mov th1,0fdh
mov scon,#50h
setb tr1
mov a,#"N"
acall trans
mov a,#"E"
acall trans
mov a,#"E"
acall trans
mov a,#"H"
acall trans
mov a,#"A"
acall trans
acall xx
trans:
mov sbuf,a
here:
jnb t1,here
ret
xx:
end

RESULT:
Expected output: NEEHA

Obtained output: NEEHA

By samba
Only for reference

Timer program
Setb tr0

Mov tmod,#06h

Clr tr0

Setb tr0

Mov tmod,#04h

Clr tr0

Setb tr0

Mov tmod,#05h

Clr tr0

Setb tr0

Mov tmod,#07h

Clr tr0

Setb tr0

Mov tmod,#00h

Clr tr0

End

RESULT:
00000110: 8 bit counter mode

00000100: 13 bit timer/counter

00000101: 16 bit timer/counter

00000111: two 8 bit timer/counter

00000000: 13 bit timer mode

By samba
Only for reference

INTERFACING WITH MICROCONTROLLER


1. Alphanumeric LCD panel and Hex keypad input interface to 8051
2. Generation of different waveforms square, Triangle using DAC interface to 8051
3. ADC for DAC

ALPHANUMERIC LCD PANEL AND HEX KEYPAD INPUT


INTERFACE TO 8051
/******************************** Keyboard Interface *****************************

Object : To Demonstrate the keyboard interface

Connection : Connect the interface module to 26 pin FRC connector J7 of ESAMCB51.

Output : Displays the pressed key's key code on the

On-board LCD of the ESAMCB 51

It uses the LCD library to write on the LCD.

**********************************************************************************/

#include <REG51xD2.H>

#include "lcd.h"

unsigned char getkey();

void delay(unsigned int);

main()

unsigned char key;

InitLcd(); /* Initialise LCD */

WriteString("Key Pressed="); /* Display msg on LCD */

while(1)

By samba
Only for reference

GotoXY(12,0); /* Set Cursor Position */

key = getkey(); /* Call Getkey method */

unsigned char getkey()

unsigned char i,j,k,indx,t;

P0=0x0ff;

P1=0x0ff;

P2 = 0x00; /* P2 as Output port */

indx = 0x00; /* Index for storing the first value of

scanline */

for(i=0x00E;i>=0x00B;i<<=1) /* for 4 scanlines */

P2 = i; /* write data to scanline */

t = P0; /* Read readlines connected to P0*/

t = ~t;

if(t>0) /* If key press is true */

delay(6000); /* Delay for bouncing */

for(j=0;j<=7;j++) /* Check for 8 lines */

t >>=1;

if(t==0) /* if get pressed key*/

By samba
Only for reference

k = indx+j; /* Display that by converting to Ascii */

t = k>>4;

t +=0x30;

WriteChar(t); /* Write upper nibble */

t = k & 0x0f;

if(t > 9)

t+=0x37;

else

t+=0x30;

WriteChar(t); /* write lower nibble */

return(indx+j); /* Return index of the key pressed */

RESULT:
Input: 06(key pressed in the keyboard)

Output: 06 (Displayed on LCD monitor)

By samba
Only for reference

GENERATION OF DIFFERENT WAVEFORMS SQUARE,


TRIANGLE USING DAC INTERFACE TO 8051

*****************************Square wave *****************************

Object : To demonstrate how to generate square wave using ESA Dual DAC interface.

Connection: Connect the interface module to 26pin FRC connector J7 of ESAMCB51.

Output: Generates the square wave with 2.5v amplitude. User can change the amplitude and

frequency by pressing the following keys.

To change Amplitude press P3.3/INT1 on ESAMCB5

To change frequency press P3.2/INT0 on ESAMCB51.

*****************************************************************************/

#include <REG51xD2.H>

#include "lcd.h"

sbit Amp = P3^3; /* Port line to change amplitude */

sbit Fre = P3^2; /* Port line to change frequency */

void delay(unsigned int x) /* delay routine */

for(;x>0;x--);

main()

/*`````````````````````````````````````````````111 */

unsigned char on = 0x7f,off=0x00;

unsigned int fre = 100;

InitLcd(); /* Initialize LCD */

WriteString("Squarewave"); /* Write to LCD */

By samba
Only for reference

while(1)

if(!Amp) /* if user choice is to change amplitude */

while(!Amp); /* wait for key release */

on+=0x08; /* Increase the amplitude */

if(!Fre) /* if user choice is to change frequency */

if(fre > 1000) /* if frequency exceeds 1000 reset to default */

fre = 100;

while(!Fre); /* wait for key release */

fre += 50; /* Increase the frequency */

P0=on; /* write apmlitude to port */

P1=on;

delay(fre);

P0 = off; /* clear port */

P1 = off;

delay(fre);

RESULT:
OUTPUT: Square wave is displayed on CRO

By samba
Only for reference

/************************** Triangle wave *************************

Object : To demonstrate how to generate a triangular wave form using ESA Dual DAC

interface.

Connection: Connect the Interface to 26pin FRC connector J7 of ESAMCB51.

Output: Generates a Triangular waveform with 5v Amp.

*******************************************************************/

#include <REG51xD2.H>

#include "lcd.h"

main()

unsigned char i=0;

InitLcd(); /* Initialise LCD */

WriteString("Triangular Wave"); /* Display on LCD */

P0 = 0x00; /* P0 as Output port */

while(1)

for(i=0;i<0xff;i++){ /* Generate ON pulse */

P1 = i;

P0 = i; }

for(i=0xfe;i>0x00;i--) /* Generate OFF pulse */

{P0 = i;

P1 = i;}

RESULT:
OUTPUT: Triangular wave is displayed on CRO

By samba
Only for reference

/****************************** DAC FOR ADC Interface******************************

Object : To display the Digital value for the given Analog input

Connections : Connect the Interface and MCB51 board through 26 pin connector

working procedure :

On interface card move the nob of the variable register VR1 to set

the analog input signal . Press the STC key on the interface, To start

the conversation. The equivalent digital value of the input analog

voltage will be Displayed on serial Port.

************************************************************************************/

#include <at89c51xd2.h>

#include <stdio.h>

void delay()

int l;

for (l=0;l<=0xfff;l++);

void main()

unsigned int i,j,k;

P0=0X00; /* port0 & Port1 output Ports */

P1=0X00;

P2=0XFF; /* port2 as input */

SCON = 0x52; /* Initialize Serial Interface */

TMOD |= 0x20;

By samba
Only for reference

TH1 = 0xe6;

TR1 = 1;

while(1)

while((i=(0x02& P2))==0); /* checking for the STC to be pressed */

delay();

while((i=(0x02& P2))==0x02); /* checking for the STC to be realesed */

for(j=0x00;j<=0xff;j++)

P0 =j; /* sending the digital value*/

if((k=P2&0x01)==0)

break; /* come out when digital value = input


analog value*/

delay();

if(j>=0x0ff)

j=0x0ff;

printf("\n DIGITAL VALUE: %x ",j);

RESULT:
Input: Analog value(kept in interfacing board using potentiometer)

Output: Digital value(displayed in the interfacing board using LEDs and also displayed on
monitor)

By samba

You might also like