Re: 8086 ALP TO CONVERT BCD -HEXA DECIMAL



rhyde@xxxxxxxxxx wrote:
On Mar 29, 9:23 pm, spamt...@xxxxxxxxxx wrote:

Hi 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.

the question is :
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

.



Relevant Pages

  • Re: How to hande SAP BCD numrics in RPGLE
    ... program that connects to a remote Unix SAP server to retrieve cost ... BCD data is just like packed except that there is no sign. ... last digit is the next to last digit, ... the zero digit), you will then have the actual number. ...
    (comp.sys.ibm.as400.misc)
  • Re: how do I get more numbers past the decimal?
    ... Other common formats are 64 ... So for the multi precision arithmetic, ... BCD is no more and no less accurate on generic numbers than anything else., its virtue is its exact reproduction of decimal numbers like 12.3456. ... With BCD you generally use one byte per significant digit, so its as precise on the mantissa as the number of bytes allocated. ...
    (comp.lang.php)
  • Re: how do I get more numbers past the decimal?
    ... Other common formats are 64 ... So for the multi precision arithmetic, ... BCD is no more and no less accurate on generic numbers than anything else., its virtue is its exact reproduction of decimal numbers like 12.3456. ... With BCD you generally use one byte per significant digit, so its as precise on the mantissa as the number of bytes allocated. ...
    (comp.lang.php)
  • Re: how do I get more numbers past the decimal?
    ... Other common formats are 64 ... So for the multi precision arithmetic, ... BCD is no more and no less accurate on generic numbers than anything else., its virtue is its exact reproduction of decimal numbers like 12.3456. ... With BCD you generally use one byte per significant digit, so its as precise on the mantissa as the number of bytes allocated. ...
    (comp.lang.php)
  • Re: fast binary to BCD source code
    ... Fast 24-bit binary to packed BCD conversion for AVC51_3 ... is then corrected by adding 6 to the lower nibble. ... mov a, ?_bin24bcd ... xch a, r6 ...
    (comp.arch.embedded)