Q.
Count number of 1’s and 0’s in a 16-bit number (AX)
Q. Find largest number from array (stored from 5000H onward, result at 5010H)
.model small
.data
; No initialized array here since we assume data is already at 5000H
.code
mov ax, @data
mov ds, ax
mov si, 5000h ; SI points to start of array
mov cx, 05h ; Number of elements
mov al, [si] ; Load first element
mov bl, al
next:
inc si ; Move to next element
dec cx
jz done ; If all elements checked, exit
mov al, [si]
cmp al, bl
jbe next ; If AL <= BL, skip
mov bl, al ; Update largest
jmp next
done:
mov [5010h], bl ; Store result at 5010H
mov ah, 4ch
int 21h
ends
end
.model small
.data
even db 0
odd db 0
.code
mov ax, @data
mov ds, ax
mov si, 5000h ; Starting address of array
mov cx, 0Fh ; 15 elements
check:
mov al, [si] ; Load number
and al, 01h ; Check LSB
jz is_even ; If 0 → even
inc odd
jmp next
is_even:
inc even
next:
inc si
loop check
mov ah, 4ch
int 21h
ends
end
.model small
.data
pos db 0
neg db 0
.code
mov ax, @data
mov ds, ax
mov si, 5000h ; starting address
mov cx, 15 ; 15 numbers
check:
mov al, [si] ; get number
cmp al, 00h
jl negative ; if < 0 → negative
inc pos
jmp next
negative:
inc neg
next:
inc si
loop check
mov ah, 4ch
int 21h
ends
end
.model small
.data
num1 db 55h
num2 db 0Fh
and_res db ?
or_res db ?
xor_res db ?
not_res db ?
.code
mov ax, @data
mov ds, ax
mov al, num1
mov bl, num2
mov al, num1
and al, bl
mov and_res, al
mov al, num1
or al, bl
mov or_res, al
mov al, num1
xor al, bl
mov xor_res, al
mov al, num1
not al
mov not_res, al
mov ah, 4ch
int 21h
ends
end
Q. String Length (Count)
.model small
.data
str db 'HELLO$',0
len db ?
.code
mov ax, @data
mov ds, ax
lea si, str
mov cx, 0
count_loop:
mov al, [si]
cmp al, '$'
je done
inc cx
inc si
jmp count_loop
done:
mov len, cl
mov ah, 4ch
int 21h
ends
end
Q. Concatenate Two Strings
.model small
.data
str1 db 'HELLO','$'
str2 db 'WORLD','$'
.code
mov ax, @data
mov ds, ax
lea si, str1
find_end:
mov al, [si]
cmp al, '$'
je concat
inc si
jmp find_end
concat:
lea di, str2
copy_loop:
mov al, [di]
mov [si], al
cmp al, '$'
je done
inc si
inc di
jmp copy_loop
done:
mov ah, 4ch
int 21h
ends
end
Q. Block Transfer (Copy Array)
.model small
.data
src db 1,2,3,4,5
dest db 5 dup(?)
count db 5
.code
mov ax, @data
mov ds, ax
lea si, src
lea di, dest
mov cl, count
transfer:
mov al, [si]
mov [di], al
inc si
inc di
dec cl
jnz transfer
mov ah, 4ch
int 21h
ends
end
Q. Block Exchange (Swap Two Arrays)
.model small
.data
arr1 db 1,2,3,4,5
arr2 db 6,7,8,9,0
count db 5
.code
mov ax, @data
mov ds, ax
lea si, arr1
lea di, arr2
mov cl, count
exchange:
mov al, [si]
mov bl, [di]
mov [si], bl
mov [di], al
inc si
inc di
dec cl
jnz exchange
mov ah, 4ch
int 21h
ends
end