Searching \ for 'Code suggestions' in subject line. ()
Make payments with PayPal - it's fast, free and secure! 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.
PICList Thread
'Code suggestions'
2000\04\18@111842 by PDRUNEN

picon face
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

2000\04\18@113053 by Scott Dattalo

face
flavicon
face
On Tue, 18 Apr 2000 spam_OUTPDRUNENTakeThisOuTspamAOL.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

2000\04\18@114350 by Andrew Warren

face
flavicon
face
PDRUNEN@AOL.COM <.....PICLISTKILLspamspam@spam@MITVMA.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 - fastfwdspamKILLspamix.netcom.com
=== Fast Forward Engineering - San Diego, California
=== http://www.geocities.com/SiliconValley/2499

2000\04\18@114926 by Michael Rigby-Jones

flavicon
face
part 0 2919 bytes
<P><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">How about:</FONT>
</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}

2000\04\18@115556 by Andrew Warren

face
flavicon
face
Scott Dattalo <.....PICLISTKILLspamspam.....MITVMA.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 - EraseMEfastfwdspam_OUTspamTakeThisOuTix.netcom.com
=== Fast Forward Engineering - San Diego, California
=== http://www.geocities.com/SiliconValley/2499

2000\04\18@121430 by M. Adam Davis

flavicon
face
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.

-Adam

PDRUNENspamspam_OUTAOL.COM wrote:
{Quote hidden}

2000\04\18@121759 by M. Adam Davis

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

-Adam

Scott Dattalo wrote:
{Quote hidden}

2000\04\18@132255 by Scott Dattalo

face
flavicon
face
On Tue, 18 Apr 2000, Andrew Warren wrote:

> Scott Dattalo <KILLspamPICLISTKILLspamspamMITVMA.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...