0% found this document useful (0 votes)
2 views

MIC

Mi

Uploaded by

shruticpatil07
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)
2 views

MIC

Mi

Uploaded by

shruticpatil07
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/ 26

8-BIT MULTIPLICATION (SIGNED)

.model small
.stack 100H
.data
num1 DB -12H
num2 DB 10H
res DB ?
.code
Main PROC
mov AX,@data
mov DS,AX
mov AL,num1
IMUL num2
mov res,AL
mov AH,4CH
INT 21H
Main ENDP
END

OUTPUT:
16-BIT MULTIPLICATION (UNSIGNED)
.model small
.stack 100H
.data
num1 DW 1234H
num2 DW 1111H
res DW ?
res1 Dw ?
.code
Main PROC
mov AX,@data
mov DS,AX
mov AX,num1
IMUL num2
mov res,AX
mov res1,DX
mov AH,4CH
INT 21H
Main ENDP
END

OUTPUT:
8-BIT DIVISION
.model small
.stack 100H
.data
dividend DB -25
divisor DB 5
quotient DB ?
remainder DB ?
.code
Main PROC
mov AX,@data
MOV DS,AX
mov AL,dividend
CBW
IDIV divisor
mov quotient,AL
mov remainder,AH
mov AH,4CH
INT 21H
Main ENDP
END

OUTPUT:
16-BIT DIVISION
.model small
.stack 100H
.data
dividend DW -2500
divisor DW 50
quotient DW ?
remainder DW ?
.code
Main PROC
mov AX,@data
MOV DS,AX
mov AX,dividend
CWD
IDIV divisor
mov quotient,AX
mov remainder,DX
mov AH,4CH
INT 21H
Main ENDP
END

OUTPUT:

PRACTICAL 7
Method 1: Using string instructions (MOVSB/MOVSW)
DATA SEGMENT
SOURCE DB 10H, 20H, 30H, 40H, 50H
DEST DB 5 DUP(?)
LENGTH EQU 5
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE, DS:DATA

START:
MOV AX, DATA
MOV DS, AX
MOV ES, AX

MOV SI, OFFSET SOURCE


MOV DI, OFFSET DEST
MOV CX, LENGTH
CLD

REP MOVSB

HLT

CODE ENDS
END START

OUTPUT:

Method 2: Using General-Purpose Registers


DATA SEGMENT
SOURCE DB 10H, 20H, 30H, 40H, 50H
DEST DB 5 DUP(?)
LENGTH EQU 5
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE, DS:DATA

START:
MOV AX, DATA
MOV DS, AX
MOV ES, AX

MOV SI, OFFSET SOURCE


MOV DI, OFFSET DEST
MOV CX, LENGTH

TRANSFER_LOOP:
MOV AL, [SI]
MOV [DI], AL
INC SI
INC DI
LOOP TRANSFER_LOOP

HLT

CODE ENDS
END START

OUTPUT:
PRACTICAL 8
Q1]
DATA SEGMENT
NUMBERS DB 05H, 0AH, 0FH, 02H, 08H
COUNT DB 05H
SUM DW 0000H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
MOV AL, COUNT ; Load 8-bit COUNT into AL
MOV AH, 00H ; Clear AH to ensure 16-bit value
MOV CX, AX ; Move full 16-bit value into CX
MOV SI, OFFSET NUMBERS
XOR AX, AX
SUM_LOOP:
MOV BL, [SI]
ADD AL, BL
ADC AH, 00H
INC SI
LOOP SUM_LOOP
MOV SUM, AX
HLT
CODE ENDS
END START
OUTPUT:
Q2]
DATA SEGMENT
NUMBERS DB 12H, 25H, 37H, 19H, 45H
COUNT DB 05H
SUM DB 00H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
MOV CL, COUNT ; Load COUNT (8-bit) into CL (lower byte of CX)
MOV CH, 00H ; Clear CH to ensure CX has correct value
MOV SI, OFFSET NUMBERS
XOR AL, AL
SUM_LOOP:
ADD AL, [SI]
DAA
INC SI
LOOP SUM_LOOP
MOV SUM, AL
HLT
CODE ENDS
END START
OUTPUT:
PRACTICAL 9
DATA SEGMENT
N DB 06H ; Number of elements in the array
NUMBERS DB 25H, 63H, 12H, 89H, 07H, 45H ; Array of numbers
LARGEST DB 00H ; Variable to store the largest number
SMALLEST DB 00H ; Variable to store the smallest number
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX ; Load data segment
MOV AL, N ; Load 8-bit value into AL
MOV CX, AX ; Move AL into CX with zero extension
MOV SI, OFFSET NUMBERS ; SI points to the first element
MOV AL, [SI] ; Load first element into AL (Largest)
MOV BL, [SI] ; Load first element into BL (Smallest)
INC SI ; Move SI to the next element
DEC CX ; Decrement CX as first element is already considered
FIND_LOOP:
MOV DL, [SI] ; Load the current number into DL
; Check for Largest
CMP AL, DL ; Compare AL (Largest so far) with DL
JAE SKIP_LARGEST ; If AL >= DL, skip updating largest
MOV AL, DL ; Else, update AL as new largest
SKIP_LARGEST:
; Check for Smallest
CMP BL, DL ; Compare BL (Smallest so far) with DL
JBE SKIP_SMALLEST ; If BL <= DL, skip updating smallest
MOV BL, DL ; Else, update BL as new smallest
SKIP_SMALLEST:
INC SI ; Move to the next number
LOOP FIND_LOOP ; Repeat until CX = 0
MOV LARGEST, AL ; Store largest number in memory
MOV SMALLEST, BL ; Store smallest number in memory
HLT ; Halt execution
CODE ENDS
END START

OUTPUT:
PRACTICAL 10
DATA SEGMENT
N DB 06H ; Number of elements in the array
NUMBERS DB 25H, 63H, 12H, 89H, 07H, 45H ; Array of numbers
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX ; Load Data Segment
MOV CL, N ; Load count into CL
DEC CL ; Outer loop runs (N-1) times
ITERATIVE_SORT:
MOV SI, OFFSET NUMBERS ; SI points to the first element
MOV DL, CL ; Inner loop counter (DL = CL)
COMPARE_SWAP:
MOV AL, [SI] ; Load current element into AL
MOV BL, [SI+1] ; Load next element into BL
CMP AL, BL ; Compare AL and BL
JNA NO_SWAP ; If AL <= BL, no swap needed
; Swap AL and BL
MOV [SI], BL ; Store BL in current position
MOV [SI+1], AL ; Store AL in next position
NO_SWAP:
INC SI ; Move SI to next pair
DEC DL ; Decrement inner loop counter
JNZ COMPARE_SWAP ; Repeat inner loop if DL != 0
DEC CL ; Decrement outer loop counter
JNZ ITERATIVE_SORT ; Repeat outer loop if CL != 0
MOV AH, 4CH ; DOS terminate program
INT 21H
CODE ENDS
END START

OUTPUT:
PRACTICAL 11
DATA SEGMENT
STR1 DB 'HELLO$', 0 ; First string (Null-terminated using '$')
STR2 DB ' WORLD$', 0 ; Second string (Null-terminated using '$')
LENGTH DB 00H ; Variable to store string length
CONCAT DB 20 DUP('$') ; Buffer for concatenated string (Large enough)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX ; Load Data Segment
; FIND LENGTH OF STR1
MOV SI, OFFSET STR1 ; Point SI to STR1
XOR CX, CX ; Clear CX (Counter)
FIND_LENGTH:
CMP BYTE PTR [SI], '$' ; Check for end of string
JE STORE_LENGTH ; If '$' found, store length
INC SI ; Move to next character
INC CX ; Increment length count
JMP FIND_LENGTH ; Repeat
STORE_LENGTH:
MOV LENGTH, CL ; Store length of STR1
; CONCATENATE STR1 + STR2
MOV DI, OFFSET CONCAT ; Destination buffer for concatenation
MOV SI, OFFSET STR1 ; Source: STR1
COPY_STR1:
MOV AL, [SI] ; Load character from STR1
MOV [DI], AL ; Store it in CONCAT
INC SI ; Move to next char in STR1
INC DI ; Move to next position in CONCAT
CMP AL, '$' ; Check for end of STR1
JNE COPY_STR1 ; If not, continue copying
DEC DI ; Remove '$' before concatenation
MOV SI, OFFSET STR2 ; Source: STR2
COPY_STR2:
MOV AL, [SI] ; Load character from STR2
MOV [DI], AL ; Store it in CONCAT
INC SI ; Move to next char in STR2
INC DI ; Move to next position in CONCAT
CMP AL, '$' ; Check for end of STR2
JNE COPY_STR2 ; If not, continue copying
HLT ; Halt execution
CODE ENDS
END START

OUTPUT:
PRACTICAL 12
DATA SEGMENT
STR1 DB 'HELLO$', 0 ; Input string (Null-terminated using '$')
STR_COPY DB 20 DUP('$') ; Buffer to store copied string
STR_REV DB 20 DUP('$') ; Buffer to store reversed string
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX ; Load Data Segment
; ======= STRING COPY =======
MOV SI, OFFSET STR1 ; Source: STR1
MOV DI, OFFSET STR_COPY ; Destination: STR_COPY
COPY_LOOP:
MOV AL, [SI] ; Load character from STR1
MOV [DI], AL ; Store it in STR_COPY
INC SI ; Move to next character
INC DI ; Move to next position
CMP AL, '$' ; Check for end of string
JNE COPY_LOOP ; If not '$', continue copying
; ======= FIND STRING LENGTH =======
MOV SI, OFFSET STR1 ; Point to the start of STR1
XOR CX, CX ; Clear CX (Counter)
FIND_LENGTH:
CMP BYTE PTR [SI], '$' ; Check for end of string
JE STORE_LENGTH ; If found, store length
INC SI ; Move to next character
INC CX ; Increment length count
JMP FIND_LENGTH ; Repeat
STORE_LENGTH:
DEC CX ; Adjust length (to exclude '$')
MOV SI, OFFSET STR1 ; Point to STR1 (Start)
ADD SI, CX ; Move SI to last character of STR1
MOV DI, OFFSET STR_REV ; Destination for reversed string
; ======= STRING REVERSE =======
REVERSE_LOOP:
MOV AL, [SI] ; Load character from STR1 (last char)
MOV [DI], AL ; Store in STR_REV
DEC SI ; Move backward in STR1
INC DI ; Move forward in STR_REV
LOOP REVERSE_LOOP ; Repeat until CX = 0
MOV BYTE PTR [DI], '$' ; Add null-terminator ('$') at end of STR_REV
HLT ; Halt execution
CODE ENDS
END START

OUTPUT:
PRACTICAL 13
Compare Two Strings (Without String Instructions)
DATA SEGMENT
STR1 DB 'HELLO$', 0 ; First string (Null-terminated with '$')
STR2 DB 'HELLO$', 0 ; Second string (Modify to test differences)
MSG_EQUAL DB 'STRINGS ARE EQUAL$', 0
MSG_NOT_EQUAL DB 'STRINGS ARE NOT EQUAL$', 0
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX ; Load Data Segment
MOV SI, OFFSET STR1 ; SI points to STR1
MOV DI, OFFSET STR2 ; DI points to STR2
COMPARE_LOOP:
MOV AL, [SI] ; Load character from STR1
MOV BL, [DI] ; Load character from STR2
CMP AL, BL ; Compare characters
JNE NOT_EQUAL ; If mismatch found, jump to NOT_EQUAL
CMP AL, '$' ; Check for end of string
JE EQUAL ; If end reached and no mismatch, strings are equal
INC SI ; Move to next character in STR1
INC DI ; Move to next character in STR2
JMP COMPARE_LOOP ; Repeat comparison
EQUAL:
MOV DX, OFFSET MSG_EQUAL ; Load message "STRINGS ARE EQUAL"
JMP DISPLAY_MSG
NOT_EQUAL:
MOV DX, OFFSET MSG_NOT_EQUAL ; Load message "STRINGS ARE NOT EQUAL"
DISPLAY_MSG:
; Simulate printing the message (for emulator)
HLT ; Halt execution
CODE ENDS
END START

OUTPUT:

Compare Two Strings Using CMPSB


DATA SEGMENT
STR1 DB 'HELLO$', 0 ; First string (Null-terminated with '$')
STR2 DB 'HELLO$', 0 ; Second string (Modify to test differences)
MSG_EQUAL DB 'STRINGS ARE EQUAL$', 0
MSG_NOT_EQUAL DB 'STRINGS ARE NOT EQUAL$', 0
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX ; Load Data Segment
MOV ES, AX ; Load Extra Segment (for STR2)
MOV SI, OFFSET STR1 ; SI points to STR1 (source)
MOV DI, OFFSET STR2 ; DI points to STR2 (destination)
COMPARE_LOOP:
LODSB ; Load AL with byte from STR1 (SI increments)
SCASB ; Compare AL with byte in STR2 (DI increments)
JNE NOT_EQUAL ; If mismatch found, jump to NOT_EQUAL
CMP AL, '$' ; Check for end of string
JNE COMPARE_LOOP ; If not end, continue comparing
EQUAL:
MOV DX, OFFSET MSG_EQUAL ; Load message "STRINGS ARE EQUAL"
JMP DISPLAY_MSG
NOT_EQUAL:
MOV DX, OFFSET MSG_NOT_EQUAL ; Load message "STRINGS ARE NOT EQUAL"
DISPLAY_MSG:
; Simulate printing the message (for emulator)
HLT ; Halt execution
CODE ENDS
END START

OUTPUT:
PRACTICAL 14
DATA SEGMENT
NUM DB 5 ; Change this value to test different numbers
MSG_EVEN DB 'NUMBER IS EVEN$', 0
MSG_ODD DB 'NUMBER IS ODD$', 0
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX ; Load Data Segment
MOV AL, NUM ; Load the number into AL
TEST AL, 01H ; Check the least significant bit (LSB)
JZ EVEN ; If LSB is 0, number is even
ODD:
MOV DX, OFFSET MSG_ODD ; Load "NUMBER IS ODD"
JMP DISPLAY_MSG
EVEN:
MOV DX, OFFSET MSG_EVEN ; Load "NUMBER IS EVEN"
DISPLAY_MSG:
; Simulate printing the message (for emulator)
HLT ; Halt execution
CODE ENDS
END START

OUTPUT:

You might also like