Post by ***@cs.ucr.eduPost by s***@crayne.orgHi every body this is kamalesh,am new to assembly level programming so
i want a help frm u .please give me the solution for the following
question.
write a ALP(assembly level program )to convert 4 digit BCD to HEXA
DECIMAL which includes a sub routine BCD-HEX.
The HLA Standard Library contains such code. Perhaps you should take a
look at that library. You can find it at http://webster.cs.ucr.edu.
Follow the "High-Level Assembly" links.
Maybe I'm following the wrong links, but I don't see any bcd code,
except entwined with floating-point code... which I don't think is what
handsomeandmodestkamalesh was looking for. :)
You'd better start trying stuff, dude!!!
Seems to me that "four digit" bcd suggests 16-bit code... Okay...
(easier in 32-bit). Seems similar to doing ascii to hex (that is, ascii
to number) in a way... We want to multiply the "result so far" by ten,
and add each digit as we process it. The difference is, we don't need to
"sub dl, '0'" - it isn't ascii - and we've got one digit per nibble, not
one digit per byte.
[on the old 8-bit Atari, they used to refer to "unpacked bcd" - one
digit per byte - and "packed bcd" - one digit per nibble. I am assuming
that "packed bcd" is what we're talking about here.]
We've got 4 digits to process, so:
mov cx, 4
might be useful. We want to clear a register for the "result so far".
Probably want to return it in ax, and it's a convenient destination for
the "mul" we'll want...
xor ax, ax ; or "mov ax, 0", if you must
We'll be wanting to multiply that by ten, so:
mov si, 10
Suppose we've got the 4 bcd digits in bx (if not, make it so). We want
it one digit at a time...
commence:
mul si ; multiply result so far by ten
ror bx, 4 ; put the top nibble in the bottom nibble
mov dx, bx ; make a copy to process
and dx, 0Fh ; mask off just the one digit
add ax, dx ; add this digit to result so far
loop commence ; do all 4 digits
That should put the number in ax...
ret
You'll probably want to modify that to preserve bx and si, maybe more
regs, arrange to pass in the bcd value... do you know how to pass a
parameter on the stack? If not, just pass it in bx... (don't need to
"preserve" bx if you do that - it gets rotated around to be what it was)
That (untested... "something like that") should do what you want... if I
understand the question...
Best,
Frank