Tuesday, September 7, 2010

8086 assembly language programming::four digit hex to bcd in

write an alp in 8086 to convert 4 digit hexadecimal no to decimal no?
//program to convert 4 digit hex no to decimal
//target data in 0250,final result in 0300+

//load data
e 0250 ff ff

//main program
a 0100
mov ax,[0250]; load the target data
and ax,f000; filter the 1st nibble
mov cl,0c; load cl with rotate count
ror ax,cl; rotate to al
mov si,ax; load count value to si
mov dx,4096; load sum value,then call the fun
call 0400;
mov di,ax; load the sum in di
mov ax,[0250]; load the target data
and ax,0f00; filter the 2nd nibble
mov cl,08; load cl with rotate count
ror ax,cl; rotate to al
mov si,ax; load count value to si
mov dx,0256; load sum value,then call the fun
call 0400;
mov bx,di; load di on bx,and call 4 bit bcd mul function
call 0200
mov di,ax; load the sum back to di
mov ax,[0250]; load the target data
and ax,00f0; filter the 3rd nibble
mov cl,04; load cl with rotate count
ror ax,cl; rotate to al
mov si,ax; load count value to si
mov dx,0016; load sum value,then call the fun
call 0400;
mov bx,di;
call 0200
mov di,ax; load the sum in di
mov ax,[0250]; load the target data
and ax,000f; filter the last nibble
daa; decimal adjust al
mov bx,di;
call 0200
mov di,ax; save
mov [0300],bp; bp goes to 0300
mov ax,di; load di back on ax
mov cl,08; rotate count loaded
ror ax,cl; rotate right 08 times
mov di,ax; reload di
mov [0301],di; save to 0301
int 20

// sub routine for si*dx=bp:ax
a 0400
cmp si,0000; sub routine for si*dx=bp:ax
jnz 0409
mov ax,0000
ret
cmp si,0001
jnz 0411
mov ax,dx
ret
mov ax,dx;
dec si
jz 041d
mov bx,dx;
call 0200
jmp 0413
ret

// sub routine for ax*bx=bp:ax
a 0200
add al,bl;
daa
mov cl,al
mov bl,bh
mov al,ah
adc al,bl
daa
mov ch,al
mov ax,cx
jc 0213
ret
inc bp;
ret
//run the program
g

//final result is displayed
d 0300
sample output
//load data
e 0250 ff ff
-g
Program terminated normally
-d 0300 l3
138F:0300 06 55 35 .U5
note:this program is developed using debug

No comments:

Post a Comment

read more

Related Posts Plugin for WordPress, Blogger...

ShareThis