Lab MPMC
Lab MPMC
NAME : DIVYADHARSHINI . S
ROLL NO : 2303717672622018
SUBJECT : MPMC LAB
SUBCODE : 40MSS46
DATE : 22.02.25
INDEX
30.12.25
AIM :
TABLE :
MOV BL, 01
MOV DS:[0200H],AL
MOV AL, 00
Termina on
HLT End program execu on.
LABEL CODE COMMENTS
Termina on
HLT; End program execu on.
OUTPUT :
RESULT : To perform addi on of two 8 bit and 16 bit numbers has been done successfully.
EX NO : 2 ADDITION OF TWO ONE DIGIT DECIMAL NUMBERS
6.1.25
AIM:
TABLE :
mov bl, al
mov ah, 9
int 21h
mov ah, 1
int 21h
sub al, 48
mov bh, 0
cmp bl, 9
jle no_carry
sub bl, 10
mov bh, 1
no_carry:
RESULT Display
lea dx, msg3
mov ah, 9
mov ah, 2
int 21h
mov dl, bl
add dl, 48
mov ah, 2
int 21h
hlt
Termina on
Data defini on msg1 db "Enter First Number
(0-9): $"
OUTPUT :
RESULT :
To add two one-digit decimal numbers using 8086 microprocessor has been successfully.
EX NO : 3 ADDITION OF 2 TWO DIGIT DECIMAL NUMBERS
8.1.25
AIM:
TABLE:
.data
.code
main:
mov ax,@data
mov ds,ax
mov ah,01h
int 21h
Complete First
Number
sub al,30h
mov bh,al
mov ah,01h
int 21h
sub al,30h
int 21h
mov ah,01h
int 21h
sub al,30h
mov ch,al
mov ah,01h
int 21h
sub al,30h
add bl,cl
mov al,bl
mov ah,00h
aaa
mov cl,al
mov bl,ah
add bl,ch
Adjust final sum using
AAA; store RESULT in BX.
mov al,bl
mov ah,00h
aaa
mov bx,ax;mov
bh,ax;mov bl,al
Show the RESULT message
Display RESULT and OUTPUT the three
mov dx,offset c RESULT digits.
mov ah,09h
int 21h
mov dl,bh
add dl,30h
mov ah,02h
int 21h
mov dl,bl
add dl,30h
mov ah,02h
int 21h
mov dl,cl
add dl,30h
mov ah,02h
int 21h
ret
OUTPUT:
RESULT :
To add two two-digit decimal numbers using 8086 microprocessor has been successfully.
EX NO : 4 SUBTRACTION OF ARRAY OF NUMBERS
13.1.25
AIM:
TABLE
Setup & Data org 100h Ini alize program start, data
Ini aliza on segment, and define data items
(array, RESULT, and messages).
.data
num db 10 dup(0)
RESULT db ?
input_prompt db 0dh,
0ah, 'Enter a number: $'
.code
start:
mov ax,@data
mov ds, ax
Prompt for lea dx, prompt Display the prompt, read a
Array Size character for total number of
mov ah, 09h
terms, convert it from ASCII,
int 21h store in CL, and check size.
int 21h
mov cl, al
jb end_program
int 21h
int 21h
mov cx, si
mov si, 1
sub_loop:
cmp si, cx
Store the final subtrac on
jae display_RESULT
RESULT, display the RESULT
sub al, num[si] message, check if nega ve (print
'-' if so), then display the
inc si
absolute RESULT.
jmp sub_loop
display_RESULT:
mov RESULT, al
int 21h
cmp RESULT, 0
jnl display_posi ve
int 21h
neg RESULT
display_posi ve:
mov dl, al
int 21h
Exit Program
end_program:
int 21h
OUTPUT:
RESULT:To perform 8086 ALP program to subtract N set of decimal numbers has been done
successfully.
EX NO : 5 OCCURENCES OF CHARACTER IN THE STRING
20.1.25
AIM:
To write a program to find the occurrence(s) of two different characters in a given string.
TABLE:
.data
charPrompt2 db 0Dh,
0Ah,'Enter the second
character to search for: $'
Program
.code Set up code segment and
Ini aliza on
ini alize DS with the data
main:
segment address.
mov ax, @data
mov ds, ax
int 21h
int 21h
int 21h
int 21h
mov bl, al
int 21h
int 21h
mov bh, al
countFirst:
cmp al, 0
je doneCoun ng
cmp al, bl
je incrementFirstCount
inc si
jmp countFirst
incrementFirstCount:
inc cx
inc si
jmp countFirst
doneCoun ng:
int 21h
mov ax, cx
call PrintNum
Reset pointer and counter; loop
Count Second lea si, inputStr + 2
through the string to count
Character
xor cx, cx occurrences of the second
search char.
countSecond:
je doneSecondCoun ng
cmp al, bh
je incrementSecondCount
inc si
jmp countSecond
incrementSecondCount:
inc cx
inc si
jmp countSecond
doneSecondCoun ng:
int 21h
mov ax, cx
call PrintNum
int 21h
mov dl, al
int 21h
ret Convert number in AX to ASCII
and display it; then return from
PrintNum endp
the procedure.
end main
OUTPUT :
RESULT :
To perform a program to find the occurrence(s) of two different characters in a given string
has been done successfully.
EX NO : 6 PALINDROME CHECKER
22.1.25
AIM:
To read a string from the keyboard and find whether the input string is a palindrome or not.
TABLE:
.data
palindrome_msg db
0Dh,0Ah,'The string is a
palindrome.$'
not_palindrome_msg db
0Dh,0Ah, 'The string is not a
palindrome.$'
inputStr db 50,?, 50
dup('$') ; Buffer size (50),
then space for length and
characters
mov ds, ax
mov ah, 09h
int 21h
int 21h
mov ch, 0
add di, cx
dec di
jne not_palindrome
inc si
dec di
cmp si, di
jge is_palindrome
jmp check_palindrome
int 21h
jmp exit
lea dx,
not_palindrome_msg
int 21h
exit:
Exit Program
Terminate the program.
mov ah, 4Ch
int 21h
end main
OUTPUT:
RESULT : To find whether the input string is a palindrome or not has been done successfully.
EX NO : 7 COUNT OF 0’S AND 1’S
26.1.25
AIM:
To write a code to count the number of 1’s and 0’s in the byte.
TABLE :
byteInput DB ?
onesCount DB 0
zerosCount DB 0
input DB 4, ?, 4 DUP('$')
.CODE
Program
Ini alize the data segment.
Ini aliza on MAIN PROC
MOV DS, AX
LEA DX, inputMsg
INT 21H
INT 21H
MOV onesCount, 0
MOV zerosCount, 0
MOV CH, 0
INC SI
MOV DX, 8
MOV BL, AL
COUNT_LOOP:
SHR BL, 1
JC INCREMENT_ONES
INC zerosCount
JMP NEXT_BIT
INCREMENT_ONES:
INC onesCount
NEXT_BIT:
DEC DX
JNZ COUNT_LOOP
LOOP DIGIT_LOOP
INT 21H
INT 21H
Exit Program MOV AH, 4CH Terminate the program.
INT 21H
MAIN ENDP
END MAIN
OUTPUT :
RESULT :
To perform code to count the number of 1’s and 0’s in the byte has been done successfully.
EX NO :8 LARGEST AND SMALLEST NUMBER
27.1.25
AIM:
To write an ALP code to find the largest number and smallest number in a given array.
TABLE :
jmp start
arr db 10 dup(0)
count db 0
largest db 0
smallest db 0
start:
mov ah, 9
int 21h
mov ah, 1
int 21h
mov count, al
mov cl, al
mov ch, 0
mov si, 0
int 21h
mov arr[si], al
inc si
loop input_loop
mov si, 0
mov bl, al
dec cl
inc si
find_loop:
cmp cl, 0 Loop through the array to
update the largest (AL) and
je done
smallest (BL) values.
cmp al, dl
jge check_smallest
mov al, dl
check_smallest:
cmp bl, dl
jle next_iter
mov bl, dl
next_iter:
inc si
dec cl
jmp find_loop
done:
mov largest, al
mov smallest, bl
mov ah, 9
Display the "Largest:"
int 21h message and OUTPUT the
largest number (converted to
ASCII).
mov dl, largest
add dl, '0'
mov ah, 2
int 21h
mov ah, 9
int 21h
Program hlt
Termina on
Halt the prg.
msg1 db 'Enter the number of
elements: $'
OUTPUT:
RESULT : To find the largest number and smallest number in a given array has been done
sucesfully
EX NO : 9 MIDDLE VALUE OF AN ARRAY
3.2.25
AIM :
To create an odd sized array and write a code to find the middle value of the given set of
numbers.
TABLE :
ARRAY DB 100
DUP(?)
SIZE DB ?
MIDDLE DB ?
Program
Ini aliza on .CODE
Ini alize the data segment.
MAIN PROC
INT 21H
INT 21H
MOV SIZE, AL
INT 21H
READ_LOOP:
INT 21H
MOV [SI], AL
INC SI
LOOP READ_LOOP
MOV AH, 0
ADD SI, AX
INT 21H
MOV DL, BL
INT 21H
OUTPUT:
RESULT : To create an odd sized array and write a code & to find the middle value of the
given set of numbers has been done successfully.
EX NO : 10 ARRANGING AN ARRAY IN ASCENDING & DESC ORDER
5.2.25
AIM:
To write an alp program to sort the given numbers in 1) ascending order and 2) descending
order.
TABLE :
.DATA
msg_size DB 0Dh,
0Ah, 'Enter the number
of elements: $'
msg_element DB
0Dh, 0Ah, 'Enter
element $'
msg_sorted_asc DB
0Dh, 0Ah, 'Sorted in
Ascending Order: $'
msg_sorted_desc DB
0Dh, 0Ah, 'Sorted in
Descending Order: $'
array DW 100
DUP(?)
size DW ?
Program .CODE
Ini aliza on
.STARTUP Ini alize the data segment.
MOV DS, AX
CMP AX, 0
JLE END_PROGRAM
MOV CX, AX
MOV SI, 0
MOV DI, 1
READ_LOOP:
PUSH CX
INT 21H
MOV AX, DI
CALL PRINT_NUM
MOV DX, OFFSET
msg_colon
INT 21H
CALL READ_NUM
MOV array[SI], AX
ADD SI, 2
INC DI
POP CX
LOOP READ_LOOP
CALL
BUBBLE_SORT_ASC
CALL
BUBBLE_SORT_DESC
END_PROGRAM:
INT 21H
BUBBLE_SORT_ASC
PROC
PUSH CX
PUSH DX
PUSH SI
Sort the array in ascending
PUSH DI order using bubble sort
(nested loops to swap
adjacent elements as
MOV CX, size needed).
DEC CX
SORT_OUTER_ASC:
MOV SI, 0
MOV DI, CX
SORT_INNER_ASC:
CMP AX, DX
JLE NO_SWAP_ASC
MOV array[SI], DX
MOV array[SI+2], AX
NO_SWAP_ASC:
ADD SI, 2
DEC DI
JNZ SORT_INNER_ASC
LOOP
SORT_OUTER_ASC
POP DI
POP SI
POP DX
POP CX
RET
BUBBLE_SORT_ASC
ENDP
BUBBLE_SORT_DESC
PROC Sort the array in descending
order using bubble sort
PUSH CX
(nested loops to swap
PUSH DX adjacent elements as neede
PUSH SI
PUSH DI
DEC CX
SORT_OUTER_DESC:
MOV SI, 0
MOV DI, CX
SORT_INNER_DESC:
CMP AX, DX
JGE NO_SWAP_DESC
MOV array[SI], DX
MOV array[SI+2], AX
NO_SWAP_DESC:
ADD SI, 2
LOOP
SORT_OUTER_DESC
POP DI
POP SI
POP DX
POP CX
RET
BUBBLE_SORT_DESC
ENDP
PRINT_ARRAY PROC
PUSH CX
PUSH DX
PUSH SI
MOV SI, 0
PRINT_ARRAY_LOOP:
CALL PRINT_NUM
INT 21H
ADD SI, 2
LOOP
PRINT_ARRAY_LOOP
POP SI
POP DX
POP CX
RET
PRINT_ARRAY ENDP
Read a mul -digit number
from the keyboard,
handling signs and
READ_NUM PROC
conver ng ASCII digits to a
PUSH BX numeric value.
PUSH CX
PUSH DX
XOR BX, BX
XOR CX, CX
INT 21H
JE NEGATIVE
JE POSITIVE
JMP DIGIT_CHECK
NEGATIVE:
MOV CX, 1
POSITIVE:
INT 21H
DIGIT_CHECK:
JE END_READ
JB DIGIT_CHECK
JA DIGIT_CHECK
SUB AL, 30H
MOV AH, 0
PUSH AX
MOV AX, BX
MOV DX, 10
MUL DX
MOV BX, AX
POP AX
ADD BX, AX
INT 21H
JMP DIGIT_CHECK
END_READ:
CMP CX, 0
JE DONE_READ
NEG BX
DONE_READ:
MOV AX, BX
POP DX
POP CX
POP BX
RET
READ_NUM ENDP
PRINT_NUM PROC
PUSH BX
MOV CX, 0
MOV BX, 10
CMP AX, 0
JGE POSITIVE_NUM
NEG AX
PUSH AX
INT 21H
POP AX
POSITIVE_NUM:
XOR DX, DX
DIV BX
PUSH DX
INC CX
CMP AX, 0
JNE POSITIVE_NUM
PRINT_NUM_LOOP:
POP DX
INT 21H
LOOP
PRINT_NUM_LOOP
POP DX
POP CX
POP BX
End of the program.
RET
ENDP
END
OUTPUT:
RESULT :
To perform an alp program to sort the given numbers in 1) ascending order and 2)
descending order has been done successfully.
EX NO : 11 REPLACEMENT OF STRINGS
5.2.25
AIM :
To Input a string from keyboard and replace any two characters of the string with symbols *
and #.
TABLE :
msg_RESULT DB 0Dh,
0Ah, 'Modified String: $'
msg_skipped DB 0Dh,
0Ah, 'Skipped String: $'
msg_star_count DB 0Dh,
0Ah, 'Count of "*": $'
msg_hash_count DB 0Dh,
0Ah, 'Count of "#": $'
str DB 50 DUP('$')
skipped_str DB 50
DUP('$')
char1 DB ?
char2 DB ?
star_count DB 0
hash_count DB 0
.CODE
Program
Ini aliza on .STARTUP
MOV DS, AX
Display input prompt, read
the string into buffer, and
mark the end of the string
MOV DX, OFFSET
with '$'.
msg_input
INT 21H
INT 21H
FOUND_ENTER:
INT 21H
INT 21H
INT 21H
MOV char2, AL
JE DONE_REPLACE
JNE CHECK_SECOND
JMP NEXT_CHAR
CHECK_SECOND:
JNE SKIP_CHAR
JMP NEXT_CHAR
SKIP_CHAR:
MOV [DI], AL
INC DI
INC SI
JMP REPLACE_LOOP
DONE_REPLACE:
MOV BYTE PTR [DI], '$'
INT 21H
INT 21H
INT 21H
INT 21H
MOV DL, AL
INT 21H
MOV DX, OFFSET
msg_hash_count
INT 21H
MOV DL, AL
INT 21H
INT 21H
END
OUTPUT :
RESULT :
To Input a string from keyboard and replace any two characters of the string with symbols *
and # has been done successfully.
EX NO : 12 TRANSFER OF STRING FROM MEMORY BLOCK
10.2.25
AIM :
TABLE :
BUFFER_SIZE
EQU 20
SRC DB
BUFFER_SIZE, 0
DB
BUFFER_SIZE
DUP('$')
DST DB
BUFFER_SIZE
DUP('$')
MSG1 DB "ENTER
A STRING: $"
MSG2 DB 0DH,
0AH, "COPIED
STRING: $"
.CODE
Program MAIN PROC
Ini aliza on
MOV AX, @DATA Ini alize DS with the data
segment.
MOV DS, AX
INT 21H
COPY LOOP
MOV BL, SRC+1
MOV BH, 0
MOV [DI], AL
Display Copied
String INC SI
INC DI
LOOP
Copy each character from
COPY_LOOP
SRC (star ng at offset +2)
to DST, then append a '$'
terminator.
MOV BYTE PTR
[DI], '$'
INT 21H
INT 21H
Program
Termina on
MOV AH, 4CH
Terminate the program.
INT 21H
MAIN ENDP
END MAIN
OUTPUT:
RESULT :
To transfer a s ng from a memory block to a new loca on has been done successfully.