67% found this document useful (3 votes)
230 views4 pages

TASM Code for BCD Conversion

This document contains assembly language code examples for: 1) Converting packed BCD to unpacked BCD and ASCII 2) Sorting an array of numbers in ascending and descending order 3) Finding the smallest and largest numbers in an array

Uploaded by

SaideepChembuli
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
67% found this document useful (3 votes)
230 views4 pages

TASM Code for BCD Conversion

This document contains assembly language code examples for: 1) Converting packed BCD to unpacked BCD and ASCII 2) Sorting an array of numbers in ascending and descending order 3) Finding the smallest and largest numbers in an array

Uploaded by

SaideepChembuli
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd

PACKED TO UNPACKED BCD

data segment
bcdip db 56h
ubcdop dw 0
data ends
code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
xor ax,ax
mov al, bcdip
mov dl,al
and al,0f0h
mov cl,4
ror al,cl
mov bh,al
and dl,0fh
mov bl,dl
mov ubcdop,bx
mov ah,4ch
int 21h
code ends

BCD to ASCII
data segment
bcdip db 56h
ubcdop dw 0
data ends
code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
xor ax,ax
mov al, bcdip
mov dl,al
and al,0f0h
mov cl,4
ror al,cl
mov bh,al

and dl,0fh
mov bl,dl
mov ubcdop,bx
add bx,3030h
mov ah,4ch
int 21h

Ascending
data segment
org 2000h
list1 db 23h,34h x ,98h,25h,20h,21h
count equ 06h
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov bx,count-1
l1:
mov si,offset list1
mov cx,bx
l2:
mov al,[si]
cmp al,[si+1]
jc l3
xchg al,[si+1]
xchg [si],al
l3:
inc si
loop l2
dec bx
jnz l1
mov ah,4ch
int 21h
code ends
end start

Descending
data segment
org 2000h
list1 db 23h,34h,98h,25h,20h,21h
count equ 06h
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax

l1:

mov bx,count-1
mov si,offset list1
mov cx,bx

l2:

mov al,[si]
cmp al,[si+1]
jnc l3
xchg al,[si+1]
xchg [si],al

l3:

inc si
loop l2
dec bx
jnz l1
mov ah,4ch
int 21h
code ends
end start

Smallest
data segment
list db 52h,23h,56h,04h
count equ 04h
org 2000h
smallest db ?
data ends
assume cs:code,ds:data
code segment
start: mov ax,data
mov ds,ax
mov si,offset list
mov cx,0000h
mov cl,count
mov al,[si]
again: cmp al,[si]
jc next
mov al,[si]
next: inc si
loop again
mov si,offset smallest
mov [si],al
mov ah,4ch
int 21h
code ends
end start

Largest
data segment
list db 52h,23h,56h,04h

count equ 04h


org 2000h
smallest db ?
data ends
assume cs:code,ds:data
code segment
start: mov ax,data
mov ds,ax
mov si,offset list
mov cx,0000h
mov cl,count
mov al,[si]
again: cmp al,[si]
jnc next
mov al,[si]
next: inc si
loop again
mov si,offset smallest
mov [si],al
mov ah,4ch
int 21h
code ends
end start

You might also like