News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

packed BCD conversion

Started by pro3carp3, March 28, 2005, 10:29:41 PM

Previous topic - Next topic

pro3carp3

I'm working on a project where I need to convert an array of BCD digits into packed BCD.  As the array may be quite long, I looked into using SSE to pack the digits but I don't see how this can be done as it seems you can't work with elements smaller than a byte.  Am I limited to rotating bits one dword at a time?:

(Air code)

mov eax, source
rol al, 4
ror ax, 4
mov bl, al
ror eax, 16
rol al, 4
ror ax, 4
mov bh, al
rol ebx, 16
mov eax, source + 4
rol al, 4
ror ax, 4
mov bl, al
ror eax, 16
rol al, 4
ror ax, 4
mov bh, al
mov dest, ebx


... or am i missing something?

Thanks.
LGC

dioxin

Try something like the following, it's a little quicker and gives 16 digits at a time. First, set mask=00ff00ff00ff00ff  and then:

movq mm0,source    ;get number 8 least significant digits first
movq mm1,mm0       ;take a copy
psrlq mm0,4        ;shift 4 bits right (1 digit)
por mm0,mm1        ;merge digits
pand mm0,mask      ;remove unwanted bits

movq mm2,source+8  ;get next 8 most significant digits
movq mm1,mm2       ;take a copy
psrlq mm2,4        ;shift 4 bits right (1 digit)
por mm2,mm1        ;merge digits
pand mm2,mask      ;remove unwanted bits

packuswb mm0,mm2   ;merge bytes
movq dest,mm0      ;mm0 now contains 16 packed BCD digits, store them


Paul.

raymond

Quote... or am i missing something?

If you want to continue with your algo, add the following instruction before the last one where you are storing the dword.

rol ebx, 16

This will shift the first packed BCD into the low byte, the 2nd into the second low byte, etc. so that they are stored in memory in the correct order.

Raymond
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

pro3carp3

Thank you.  I'm working on implementing your suggestion.  Unfortunately I don't have a lot of time to work on my asm project, but I'll let you know how I make out.
LGC