flat assembler
Message board for the users of flat assembler.

Index > Main > looking for bin2bcd

Author
Thread Post new topic Reply to topic
spo



Joined: 21 Apr 2004
Posts: 2
Location: Opole, Poland
spo
Hi! I'm looking for a sample code which would convert a 32bit integer value (stored in 2 separate words - 2 x 16 bits) into a BCD array (unpacked).
thank's for any suggestions.
Post 21 Apr 2004, 21:40
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
just wondering - what are you going to use BCDs for?
Post 22 Apr 2004, 08:31
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
spo



Joined: 21 Apr 2004
Posts: 2
Location: Opole, Poland
spo
Well, my brother has to do a homework using BCD arithmetics. I know BCD isn't being much used these days, but sometimes someone has to deal with it. anyway, thanks for asking
Post 22 Apr 2004, 14:44
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
general algorithm is something like this (in C):

//store n as BCD at buffer at dest
//unsigned int n;
//unsigned int *dest;
do{
low = n % 10;
n = n / 10;
high = n % 10;
n = n / 10;
*dest = (high << 16) | low;
dest++;
} while (n>0)

size of buffer pointed by dest depends on size of "int". If int is 16bit, buffer must hold 5 decimal digits (65535), that means 3 bytes. For 32bits, it must hold 10 digits (4294967296), that means 5 bytes.

I hope this code is right and you can code in C, i don't have enough time to write & test ASM code.
Post 22 Apr 2004, 18:17
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.