PDA

View Full Version : Some assembly help



Dutch
03-20-2009, 02:34 AM
Cant get my head around this at the moment, so if someone can help. I need to expand a WORD to a LONG. So for example bit 0 of the WORD becomes bit 0 of the LONG and bit 1 of the LONG can be left as zero. Then bit 1 of the WORD becomes bit 2 of the LONG and bit 3 of the LONG can be left as zero, for all 16 bits of the WORD. So finally bit 15 of the WORD becomes bit 30 of the LONG and bit 31 can be left as zero. I am thinking maybe using RCL instructions, but I cannot get my head around assembly. This needs to be converted in the shortest possible time. If anyone can help it would be appreciated.

Kye
03-20-2009, 03:10 AM
Ah this is a nice question. For graphics?

Anyway, here's what you shoud do:




expand mov buffer, #1
mov counter, #16
mov output, #0

expandLoop shr input, #1 wc
muxc output, buffer
shl buffer, #2
djnz counter, #expandLoop

expand_ret ret

input res 1
output res 1

buffer res 1
counter res 1


The word goes into the (input) the long comes out in the (output).

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,

Kye
03-20-2009, 03:12 AM
Love that mux command, makes life so easy.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,

Dutch
03-20-2009, 03:15 AM
Cheers Kye, this is what I came up with

rdword xword, addr
mov count, #16

:expand_loop shl xlong , #1
shl xword, #1 wc
rcl xlong, #1
djnz count, #:expand_loop

Will this work ???????? Looks as though you have same number of instructions, will try your way, many thanks.

Ale
03-20-2009, 03:17 AM
Both seem to work. Useful to expand the fonts in rom for direct use as bitmapped fonts http://forums.parallax.com/images/smilies/smile.gif

kuroneko
03-20-2009, 08:26 AM
rdword xword, addr
mov count, #16

:expand_loop shl xlong , #1
shl xword, #1 wc
rcl xlong, #1
djnz count, #:expand_loop


Just note that your word must occupy the upper half of xword for this to work.

If you don't care about the odd bits then this should work as well:




rdword xword, addr
mov count, #16

:loop shr xword, #1 wc
rcr xlong, #2
djnz count, #:loop

and xlong, mask ' optional mask

mask long 0x55555555

Post Edited (kuroneko) : 3/20/2009 1:03:34 AM GMT