MMDB_Group#8_lab_report#7 (1)
MMDB_Group#8_lab_report#7 (1)
SOFTWARE ENGINEERING
SUBMITTED TO:
Dr. Sagheer Khan
SUBMITTED BY:
Shafla Rehman; 412780
Areesha Batool ; 413055
Shaheer Mukhtiar ; 432017
CE-44, Syndicate B
Task#1:
Code:
org 100h
.stack 100h
.model small
.data
array db 1,2,3,4,5
array1 db , 0,0,0,0,0
.code
; Direct addressing mode to modify array elements
xor ax, ax
xor bx,bx
xor cx, cx
xor dx,dx
mov cl, 0d
mov bl , 10d
modify:
mov [array] , 10d
mov [array+1] , 20d
mov [array+2] , 30d
mov [array+3] , 40d
mov [array+4] , 50d
mov bx, 0
mov dx, 0
adder:
cmp bx, 5d
je terminate
mov al, array[bx]
add dx, ax
inc bx
jmp adder
terminate:
ret
Output:
Task#2:
Code:
org 100h
.stack 100h
.model small
.data
buffer db 50 , 50 dup(1)
buffer1 db 50 , 50 dup(1)
message db 'Enter first string : $ '
message1 db 'Enter second string : $'
.code
; Direct addressing mode to modify array elements
xor ax, ax
xor bx,bx
xor cx, cx
xor dx,dx
lea dx, message
mov ah, 09h
int 21h
mov al , buffer[si]
mov bl, buffer1[di]
cmp al , bl
jl first
jg second
inc si
inc di
cmp al , 0dh
je dollar
jmp again
dollar:
cmp al,bl
je equal_display
jmp again
equal_display:
lea dx, crlf
mov ah, 09h
int 21h
lea dx, equal_message
mov ah, 09h
int 21h
lea dx, crlf
mov ah, 09h
int 21h
mov ah, 09h
mov bh, 00h
mov bl , buffer[1]
mov buffer[bx+2] , '$'
lea dx, buffer[2]
int 21h
mov ah, 09h
mov bh, 00h
mov bl , buffer1[1]
mov buffer1[bx+2] , '$'
lea dx, buffer1[2]
int 21h
jmp terminate
first:
lea dx, crlf
mov ah, 09h
int 21h
lea dx, First_message
mov ah, 09h
int 21h
lea dx, crlf
mov ah, 09h
int 21h
mov ah, 09h
mov bh, 00h
mov bl , buffer[1]
mov buffer[bx+2] , '$'
lea dx, buffer[2]
int 21h
mov ah, 09h
mov bh, 00h
mov bl , buffer1[1]
mov buffer1[bx+2] , '$'
lea dx, buffer1[2]
int 21h
jmp terminate
second:
lea dx, crlf
mov ah, 09h
int 21h
lea dx, Second_message
mov ah, 09h
int 21h
lea dx, crlf
mov ah, 09h
int 21h s
mov ah, 09h
mov bh, 00h
mov bl , buffer1[1]
mov buffer1[bx+2] , '$'
lea dx, buffer1[2]
int 21h
mov ah, 09h
mov bh, 00h
mov bl , buffer[1]
mov buffer[bx+2] , '$'
lea dx, buffer[2]
int 21h
jmp terminate
terminate:
ret
Output:
Task#3:
Take four numbers from user. Calculate their mean, median, mode and
range (Difference between maximum and minimum values).
Code:
org 100h
.model small
.stack 100H
.data
numbers DB 4 DUP(0)
mean DB 0
median DB 0
mode DB 0
range DB 0
msg DB 'Enter 4 numbers: $'
msg1 DB 0Dh, 0Ah, 'Mean: $'
msg2 DB 0Dh, 0Ah, 'Median: $'
msg3 DB 0Dh, 0Ah, 'Mode: $'
msg4 DB 0Dh, 0Ah, 'Range: $'
newline DB 0Dh, 0Ah, '$'
.code
main:
MOV CX, 4
LEA DI, numbers
input:
CALL read
MOV [DI], AL
INC DI
LOOP input
; Calculate mean
XOR AX, AX
MOV CX, 4
LEA DI, numbers
sum:
CALL sort
; median
; mode
CALL CalcMode
; range
MOV CX, 4
LEA DI, numbers
MOV AL, [DI]
MOV BL, AL
range1:
INC DI
MOV AL, [DI]
CMP AL, BL
JG new_max
CMP AL, [numbers]
JL new_min
JMP next_num_range
new_max:
MOV BL, AL
JMP next_num_range
new_min:
MOV [numbers], AL
next_num_range:
LOOP range1
; Calculate the range
SUB BL, [numbers]
MOV range, BL
read PROC
MOV AH, 01h
INT 21h
SUB AL, '0'
RET
read ENDP
print PROC
ADD AL, '0'
MOV DL, AL
MOV AH, 02h
INT 21h
RET
print ENDP
sort PROC
LEA DI, numbers
MOV CX, 4
outer_loop:
MOV BX, 0
MOV DI, OFFSET numbers
MOV AX, [DI]
MOV DX, [DI + 1]
CMP AX, DX
JBE no_swap
MOV [DI], DX
MOV [DI + 1], AX
INC BX
no_swap:
ADD DI, 1
LOOP outer_loop
CMP BX, 0
JNZ outer_loop
RET
sort ENDP
CalcMode PROC
LEA DI, numbers
MOV CX, 4
XOR BX, BX
XOR DX, DX
MOV AL, [DI]
MOV AH, 0
next_number_outer:
MOV BL, [DI]
MOV CL, 1
MOV SI, 0
count:
CMP SI, 4
JAE check
CMP BL, numbers[SI]
JNE not_a_match
INC CL
not_a_match:
INC SI
JMP count
check:
CMP CL, AH
JBE next
MOV AH, CL
MOV AL, BL
next:
INC DI
DEC CX
JNZ next_number_outer
MOV mode, AL
RET
CalcMode ENDP
END main
Output:
Task#4:
Create a program to test whether 2 phrases entered by the user are
Anagrams or not.
Code:
ORG 100h
.MODEL SMALL
.STACK 100H
.DATA
PROMPT1 DB 'Enter first string: $'
PROMPT2 DB 'Enter second string: $'
STR1 DB 20, 20 DUP(0)
STR2 DB 20, 20 DUP(0)
RESULT3 DB 'Both strings are anagrams.$', 0
NOT_ANAGRAM DB 'Strings are not anagrams.$', 0
.CODE
START:
MOV AH, 09h
LEA DX, PROMPT1
INT 21h
UPPER_LOOP:
MOV AL, [SI]
CMP AL, 13
JE STRINGS_IDENTICAL
INC DI
LOOP INNER_LOOP
JMP NOT_ANAGRAM_FOUND
MATCH_FOUND:
MOV [DI], 0
INC SI
JMP UPPER_LOOP
STRINGS_IDENTICAL:
MOV AH, 09h
LEA DX, RESULT3
INT 21h
JMP EXIT_PROGRAM
NOT_ANAGRAM_FOUND:
MOV AH, 09h
LEA DX, NOT_ANAGRAM
INT 21h
EXIT_PROGRAM:
MOV AX, 4C00h
INT 21h
Output: