Searching \ for '[PIC]: Confusing code - 12c671' 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/microchip/devices.htm?key=pic
Search entire site for: 'Confusing code - 12c671'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Confusing code - 12c671'
2001\03\15@131600 by Jess Hancock

flavicon
face
This is more of the code I downloaded from internet project (hex format),
disassembled and trying to figure out.  All comments are my interpretation.
The lines pointed to below seem to be unnecessarily complicated and cryptic.
This code is executed only during startup, is not in a loop and I don't see
any advantage to indirect addressing.  Would it not be simpler and more
efficient to used the REVISED code below?  What am I missing?

;ORIGINAL CODE

MAIN        CLRF FSR            ;Clear FSR
           CLRF STATUS         ;Clear STATUS, Z set
-->       MOVLW 0x9F          ;ADCON1 is Reg 0x9F (Bank 1)
-->       MOVWF FSR           ;Setup indirect addressing
-->       MOVLW 0x07          ;b'0000 0111'
-->       MOVWF INDF          ;INITIALIZE ADCON1 TO 0x07
                               ;GP4,2,1,0 AS Digital I/O and
                               ;Vdd as VREF
           BSF STATUS,RP0      ;BANK 1
           BCF TRISIO,4             ;GP4/Pin3 as OUTPUT
           BCF STATUS,RP0      ;BANK 0
           BSF GPIO,4                ;Pin 3 set Hi
    ;

;REVISED CODE

MAIN        CLRF FSR            ;Clear FSR    (Don't think this is
necessary)
           CLRF STATUS           ;Clear STATUS, Z set
           BSF STATUS,RP0      ;BANK 1
-->       MOVLW 0x07            ;b'0000 0111'
-->       MOVWF ADCON1    ;INITIALIZE ADCON1 TO 0x07
           BCF TRISIO,4             ;GP4/Pin3 as OUTPUT
           BCF STATUS,RP0      ;BANK 0
           BSF GPIO,4                ;Pin 3 set Hi

Thanks in advance.

Jess

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\03\15@133827 by Barry Gershenfeld

picon face
At 12:56 PM 3/15/01 -0500, you wrote:
>This is more of the code I downloaded from internet project (hex format),
>disassembled and trying to figure out.
>...Would it not be simpler and more
>efficient to used the REVISED code below?  What am I missing?
>Thanks in advance.
>
>Jess

I went and took a look at the original reference at
http://www.qsl.net/ke4hor/polar.htm

I can think of three possibilities right off:
(1) He has a favorite macro for doing certain things.
(2) He used a C compiler to make the code
(3) He has some not-too specific startup code that he
    likes to reuse for every project.

Any of these would give you less-than-completely-efficient code such
as all assembler-hackers are drawn to.

But I also suspect he considers his code "not too significant" meaning
that it's an antenna project and not a PIC project, the PIC being
incidental to getting the thing going.  Which is to say that if
you asked him he might be happy to send you his source code.

Barry

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\03\15@141222 by O'Reilly John E NORC

flavicon
face
The original code avoids bank switching.

On another note, I thought I read in the Mid-Range Reference Manual that it
is not a good idea to use CLRF STATUS, and use BSF STATUS, Z or BCF STATUS,
Z instead.  Can anyone shed some light on this?

John

{Original Message removed}

2001\03\15@143722 by Andrew Warren

flavicon
face
O'Reilly John E NORC <spam_OUTPICLISTTakeThisOuTspamMITVMA.MIT.EDU> wrote:

> The original code avoids bank switching.

   Yeah, but two lines later, the code does an explicit bank-switch
   to write to the TRISIO register... So I have a feeling that the
   code's author (or his compiler) has a generic "write to a Bank1
   register" macro that uses FSR, and a "setup the ports" macro
   that flips the register-page bits.

> On another note, I thought I read in the Mid-Range Reference Manual
> that it is not a good idea to use CLRF STATUS, and use BSF STATUS, Z
> or BCF STATUS, Z instead.  Can anyone shed some light on this?

   Sure.  If you put a CLRF STATUS instruction in your code, you
   presumably want to clear all the bits in the STATUS register to
   0, right?

   Unfortunately, the CLRF instruction always sets the Z flag after
   it executes... And the Z flag is in the STATUS register... So a
   CLRF STATUS instruction will never clear all the bits in the
   STATUS register to zero.

   -Andy


=== Andrew Warren --- .....aiwKILLspamspam@spam@cypress.com
=== Staff Systems Engineer, IPD
=== Cypress Semiconductor Corporation

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\03\16@130617 by Jess Hancock

flavicon
face
Hopefully, correctly tagged this time.


Thanks Barry, John, and Andy for your comments.

Barry, you were correct about the compiler - in the web site, he said he
used the CCS  C compiler.  Yes, the project is a hobby project.  He offered
and I requested the source code, but that's been a while ago.  I think he's
a busy guy.  So I'm doing what's necessary to both learn about PICs and get
the project working.

John, Andy, others?

1. What is the Mid Range Reference Manual and where might I find it?
2. How does one clear the status? - use CLRF  STATUS followed by BCF
STATUS, Z ???
3. Is it customary to clear the status early in the code, or is it only
necessary prior to an instruction whose status outcome is important?

No one shot down my revised version of the code so I'll assume it would
work.

Thanks  Jess

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body


2001\03\16@134050 by Barry Gershenfeld

picon face
>1. What is the Mid Range Reference Manual and where might I find it?

It's one of the PIC manuals on the Microchip site and has (had?)
the number 33023a when I downloaded it.  It talks about all
things that you *might* find in your PIC.  For instance I had
a hard time finding out about the TRIS register, which way
the "1" verus "0" went.  This manual had a lot of detail that the
one for the specific part didn't.  And so it's a good place
to go when you think they're skimping on the information
in your datasheet.

>2. How does one clear the status? - use CLRF  STATUS followed by BCF
>STATUS, Z ???
>3. Is it customary to clear the status early in the code, or is it only
>necessary prior to an instruction whose status outcome is important?

Those two go together.  My first thought was that maybe you would
want to clear it only when the program started up.  But even then
I think there are some rather important bits in there.  They can
tell you if you are starting up after a power failure or watchdog
timeout.  So you really don't want to clear anything except
specific bits (like the bank).  And your number 3 is correct.
You don't really *care* what Z is set to, until you do some
operation and then want to test the result.

If you really, really, have to clear Z, then just do some
operation that you know will fail.  I think an IORLW with
anything other than 0 will give you a "nonzero" result.

Barry

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam.....mitvma.mit.edu with SET PICList DIGEST in the body


2001\03\17@055709 by Alan B. Pearce

face picon face
>2. How does one clear the status? - use CLRF  STATUS followed by BCF
>STATUS, Z ???
>3. Is it customary to clear the status early in the code, or is it only
>necessary prior to an instruction whose status outcome is important?

I suspect that in the code sample you supplied the state of the other bits in
the status register did not matter, and so clearing the register was an easy way
of ensuring the bank select registers were zero. The fact that the Z flag bit
gets set as a result of the operation is not a problem in the way the result was
used.

--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestspam_OUTspamTakeThisOuTmitvma.mit.edu


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