Searching \ for 'Code suggestions' in subject line. ()
Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=code+suggestions
Search entire site for: 'Code suggestions'.

Truncated match.
'Code suggestions'
2000\04\18@111842 by

Hi Group,

I have a memory location I need to break up into two different register.

If MEM1 = \$32 then MEM2 gets \$03 and MEM3 gets \$20 for \$0320
if MEM1 + \$14 then MEM2 gets \$01 and MEM3 gets \$40 for \$0140

I am basically multiplying by 16 (decimal), I see several ways myself but
would
like to see what the group can come up with.

Paul

On Tue, 18 Apr 2000 PDRUNENAOL.COM wrote:

> Hi Group,
>
> I have a memory location I need to break up into two different register.
>
> If MEM1 = \$32 then MEM2 gets \$03 and MEM3 gets \$20 for \$0320
> if MEM1 + \$14 then MEM2 gets \$01 and MEM3 gets \$40 for \$0140
>
> I am basically multiplying by 16 (decimal), I see several ways myself but
> would
> like to see what the group can come up with.
>
> Paul
>

swapf  mem1,w
movwf  mem2
andlf  0xf0
xorwf  mem2,f
movwf  mem3

Scott

PDRUNEN@AOL.COM <PICLISTMITVMA.MIT.EDU> wrote:

> If MEM1 = \$32 then MEM2 gets \$03 and MEM3 gets \$20 for \$0320
> if MEM1 + \$14 then MEM2 gets \$01 and MEM3 gets \$40 for \$0140
>
> I am basically multiplying by 16 (decimal), I see several ways myself
> but would like to see what the group can come up with.

Paul:

SWAPF    MEM1,W
ANDLW    B'00001111'
MOVWF    MEM2
SWAPF    MEM1,W
ANDLW    B'11110000'
MOVWF    MEM3

-Andy

=== Andrew Warren - fastfwdix.netcom.com
=== Fast Forward Engineering - San Diego, California
=== http://www.geocities.com/SiliconValley/2499

part 0 2919 bytes
</P>

<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#0000FF" SIZE=2 FACE="Arial">swapf&nbsp;&nbsp; MEM1,w</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#0000FF" SIZE=2 FACE="Arial">andlw&nbsp;&nbsp; 0x0f</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#0000FF" SIZE=2 FACE="Arial">movwf&nbsp;&nbsp; MEM2</FONT>
</P>

<P><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">Can't think of anything much quicker, but then, I'm not a Picgod (tm) :o)</FONT>
</P>

<P><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">Mike</FONT>
</P>
<BR>
<UL>
<P><FONT SIZE=1 FACE="Arial">{Original Message removed}
Scott Dattalo <PICLISTMITVMA.MIT.EDU> wrote:

> swapf  mem1,w
> movwf  mem2
> andlf  0xf0
> xorwf  mem2,f
> movwf  mem3

Nice, Scott.

-Andy

P.S.  That "andlf" should be an "andlw", no?

=== Andrew Warren - fastfwdix.netcom.com
=== Fast Forward Engineering - San Diego, California
=== http://www.geocities.com/SiliconValley/2499

My first thought was to rotate MEM1 into w, then copy it to MEM2 and rotate it
three more times, then rotate MEM1 four times.  That takes 9 instructions.  I
then remembered the SWAPF instruction, and used it to remove one instruction for
the above.  My second inclination is to:

MEM1    MEM2    W
0xAB    unk     unk
MOVF    MEM1,W  ; W = MEM1                              0xAB    unk     0xAB
ANDLW   0xf0    ; W = W[7:4]                            0xAB    unk     0xA0
MOVWF   MEM2    ; Move that to MEM2.  MEM2 = MEM1[7:4]  0xAB    0xA0    0xA0
SWAPF   MEM2,f  ; MEM2[3:0] = MEM1[7:4]                 0xAB    0x0A    0xA0
MOVF    MEM1,W  ; W = MEM1                              0xAB    0x0A    0xAB
ANDLW   0xf     ; W = W[3:0]                            0xAB    0x0A    0x0B
MOVWF   MEM1    ; Move that to MEM1.                    0x0B    0x0A    0x0B
SWAPF   MEM1,f  ; MEM1 = MEM1[3:0] << 4                 0xB0    0x0A    0x0B

Actually, let's use the swapf instruction to put MEM1 into w, instead of a
seperate instruction:

MEM1    MEM2    W
0xAB    unk     unk
SWAPF   MEM1, W         0xAB    unk     0xBA
ANDLW   0x0F            0xAB    unk     0x0A
MOVWF   MEM2            0xAB    0x0A    0x0A
SWAPF   MEM1, W         0xAB    0x0A    0xBA
ANDLW   0xF0            0xAB    0x0A    0xB0
MOVWF   MEM1            0xB0    0x0A    0xB0

I think that would be the shortest routine one could use to do what you are
trying to do, unless you can somehow load w at the beginning, and use ANDWF to
replace to two ANDLW/MOVWF combinations.  I've thought about it and can't see
the way, but perhaps it is possible.  You'd only gain one instruction cycle by
doing that, anyway.

PDRUNENAOL.COM wrote:
{Quote hidden}

Very nice.  I took too long to work on my version, but you still beat it by one
instruction...

Scott Dattalo wrote:
{Quote hidden}

On Tue, 18 Apr 2000, Andrew Warren wrote:

> Scott Dattalo <PICLISTMITVMA.MIT.EDU> wrote:
>
> > swapf  mem1,w
> > movwf  mem2
> > andlf  0xf0
> > xorwf  mem2,f
> > movwf  mem3
>
>     Nice, Scott.
>
>     -Andy
>
>     P.S.  That "andlf" should be an "andlw", no?

oops. You're right.

More... (looser matching)
- Last day of these posts
- In 2000 , 2001 only
- Today
- New search...