ALP Programs
ALP Programs
8 Bit: 16 Bit:
.model small .model small
.data .data
Num1 db 2h Num1 dw 2h
Num2 db 4h Num2 dw 4h
Result dw ? Result dw ?
.code .code
ends ends
end end
2) Write ALP to subtract two given 8 bit and 16 bit numbers.
8 Bit: 16 Bit:
.model small .model small
.data .data
Result dw ? Result dw ?
.code .code
ends ends
end end
3) Write ALP to multiply two given 8 bit and 16 bit unsigned numbers.
8 Bit: 16 Bit:
.model small .model small
.data .data
Result dw ? Result dw ?
.code .code
mul al mul ax
ends ends
end end
4) Write ALP to multiply two given 8 bit and 16 bit signed numbers.
8 Bit: 16 Bit:
.model small .model small
.data .data
Result dw ? Result dw ?
.code .code
imul al imul ax
ends ends
end end
5) Write ALP to perform block transfer of data.
.model small
.data
Block1 db 10dup(20h)
Block2 db 10dup(30h)
.code
mov ax,@data
mov ds,ax
mov si,Block1 ; Initiallize memory pointer For Source block
mov di,Block2 ;Initiallize memory pointer For destination block
Mov cx,0A ;Initiallize Counter
Up:
Ends
end
6) Write ALP to divide two given 8 bit and 16 bit unsigned numbers.
8 Bit: 16 Bit:
.model small .model small
.data .data
Result dw ? Result dw ?
.code .code
div al div ax
ends ends
end end
7) Write ALP to divide two given 8 bit and 16 bit signed numbers.
8 Bit: 16 Bit:
.model small .model small
.data .data
Result dw ? Result dw ?
.code .code
idiv al idiv ax
ends ends
end end
8) Write ALP to add two BCD numbers.
ADDITION: SUBTRACTION:
.data .data
Num1 db 2h Num1 db 2h
Num2 db 4h Num2 db 4h
Result dw ? Result dw ?
.code .code
DAA DAS
ends ends
end end
10) Write A Program To Multiply two BCD Numbers:
11) Write A Program To Divide two BCD Numbers:
MULTIPLICATION: DIVISION:
.data .data
Num1 db 2h Num1 db 2h
Num2 db 4h Num2 db 4h
Result dw ? Result dw ?
.code .code
mul al div al
DAM DAD
ends ends
end end
12) Write ALP to find smallest number.
.model small
.data
Arr db 12h,31h,02h,45h,65h
Small db 0
.code
Mov ax,@data
Mov ds,ax
Mov cx,5
Mov al,[SI]
Dec cx
Up:
Inc SI
Cmp al,[SI]
Jc next
Mov al,[SI]
Next:
Loop Up
Mov Small,al
Ends
End
13) Write ALP to find smallest number.
.model small
.data
Arr db 12h,31h,02h,45h,65h
Large db 0
.code
Mov ax,@data
Mov ds,ax
Mov cx,5
Mov al,[SI]
Dec cx
Up:
Inc SI
Cmp al,[SI]
Jnc next
Mov al,[SI]
Next:
Loop Up
Mov Large,al
Ends
End
14) Write ALP to arrange numbers from array in the ascending order.
.model small
.data
arr db 12h,11h,21h,09h,19h
.code
mov ax,@data
mov ds,ax
mov bx,5
a:
mov cx,4
b:
mov ax,[SI]
cmp ax[SI+2]
jc c
xchg ax,[SI+2]
xchg ax,[SI]
c:
add SI,2
loop b
dec bx
jnz a
ends
end
15) Write ALP to arrange numbers from array in the descending order.
.model small
.data
arr db 12h,11h,21h,09h,19h
.code
mov ax,@data
mov ds,ax
mov bx,5
a:
mov cx,4
b:
mov ax,[SI]
cmp ax[SI+2]
jnc c
xchg ax,[SI+2]
xchg ax,[SI]
c:
add SI,2
loop b
dec bx
jnz a
ends
end
16) Write ALP to count number of 1's in the given number.
.model small
.data
Number dw 0008h
Zero_count db 00h
One_count db 00h
.code
Mov ax,@data
Mov ds ,ax
Mov cx,16
Mov ax,Number
Next:
ROR AX,1
Jc Down
Inc Zero_count
Jmp Down1
Down:
Inc One_count
Down1:
Loop Next
Ends
End
18) Write ALP to find positive number.
.model small
.data
Num db 89h
Pos db 0
Neg db 0
.code
Mov ax,@data
Mov ds ,ax
Mov al,Num
ROL al,1
Jnc Dn
ROR al,1
Mov neg,al
Jmp exit
Dn:
ROR al,1
Mov Pos,al
Exit:
Ends
End
20) Write a Program To Find Length of String:
.model small
.data
Str db ‘computer$’
Len db 0
.code
Mov ax,@data
Mov ds,ax
Mov SI,offset str
Next:
Mov al,[SI]
Cmp al,$
Je exit
Inc SI
Inc len
Jmp next
Exit:
Ends
End
21) Write ALP to Display reverse of given String
22) Write ALP For Count of Even And Odd Numbers In Given Array