Searching \ for 'Beginner Question' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/index.htm?key=beginner+question
Search entire site for: 'Beginner Question'.

Truncated match.
PICList Thread
'Beginner Question'
1997\03\08@202905 by James and Iliana Holbrook

flavicon
face
Good Evening,
       I'm trying to incorporate some code from another program into some of my
own and I came across something that I don't understand. I've looked in the
'84 data sheet, the Easy PIC'n book and the MPASM user's manual but can't
find any examples that explain what is going on.
       The snippet of code is:

       movlw   Idle
       movwf   SState
< later >
       movf    SState,W
       movwf   pcl

       Idle is not defined as data or a register but is a label later in the pr
ogram
       My idea is that the memory address of the label is place in W and then
moved to " SState " then later SState is moved back into W and then loaded
into the program counter and then the program counter will skip to the
memory location of the label. Is this possible ??
       Also.. what is " 2's compliment " ? I understand that " 1's compliment "
means that 0's are changed to 1's and vice-versa.
       Any help is appreciated.

James and Iliana Holbrook
Austin Texas

1997\03\08@211135 by Michael N. Steen

flavicon
face
At 19.26 08-03-1997 -0600, you wrote:
>Good Evening,
>        I'm trying to incorporate some code from another program into some
of my
{Quote hidden}

the program
>        My idea is that the memory address of the label is place in W and then
>moved to " SState " then later SState is moved back into W and then loaded
>into the program counter and then the program counter will skip to the
>memory location of the label. Is this possible ??

Yes, I think you are right, it will work that way. The 2 instructions after
<later> would work like an indirect jump.
If SState is not altered elsewhere in the program, then you could just as
well use a simple
       goto Idle

>        Also.. what is " 2's compliment " ? I understand that " 1's
compliment "
>means that 0's are changed to 1's and vice-versa.
>        Any help is appreciated.
2's complement is a way of representing negative numbers. It is just 1's
complement + 1, that is all bits changed to the opposite, then add 1.


Regards
Michael

1997\03\09@212804 by Steve Hardy

flavicon
face
> From: "Michael N. Steen" <spam_OUTm_steenTakeThisOuTspamVIP.CYBERCITY.DK>
>
> At 19.26 08-03-1997 -0600, you wrote:
> >Good Evening,
> >        I'm trying to incorporate some code from another program into some
> of my
> >own and I came across something that I don't understand.
> >....
> >        The snippet of code is:
> >
> >        movlw   Idle
> >        movwf   SState
> >< later >
> >        movf    SState,W
> >        movwf   pcl
> >
> >        Idle is not defined as data or a register but is a label later in
> the program
> >        My idea is that the memory address of the label is place in W and
then
> >moved to " SState " then later SState is moved back into W and then loaded
> >into the program counter and then the program counter will skip to the
> >memory location of the label. Is this possible ??
>
> Yes, I think you are right, it will work that way. The 2 instructions after
> <later> would work like an indirect jump.
> If SState is not altered elsewhere in the program, then you could just as
> well use a simple
>         goto Idle

The name of the variable, sstate, indicates that this piece of code
is implementing a state machine.  Quite a common thing in microcontroller
code -- a trick well worth remembering and understanding.  For example,
in a previous thread relating to binary-BCD conversion, a state variable
was used to split a subroutine into small chunks that could be called
in sequence.


>
> >        Also.. what is " 2's compliment [sic]"  ? I understand that " 1's
> compliment [sic]"
> >means that 0's are changed to 1's and vice-versa.
> >        Any help is appreciated.
> 2's complement is a way of representing negative numbers. It is just 1's
> complement + 1, that is all bits changed to the opposite, then add 1.

2's complement is used because it is the most 'natural' way of
representing signed binary numbers on a machine with a bitwise adder.
The adder can treat all bits in exactly the same way, including the
'sign' bit.  The only possible deficiency of 2's complement is that
there is one more negative number than there are positive numbers.
This rarely turns out to be more than a trifling problem.  In fact, out
of all the CPU architectures which I have ever seen, not one of them
used anything other than 2's complement arithmetic.


Regards,
SJH
Canberra, Australia

1997\03\09@235504 by Lee Jones

flavicon
face
>>> What is " 2's compliment [sic]" ?

>> 2's complement is a way of representing negative numbers. It is just 1's
>> complement + 1, that is all bits changed to the opposite, then add 1.

> 2's complement is used because it is the most 'natural' way of
> representing signed binary numbers on a machine with a bitwise adder.
> The only possible deficiency of 2's complement is that there is one
> more negative number than there are positive numbers.

On the flip side, 1's complement is symmetrical and has the same
number of values on each side of zero.  Downside is that there are
2 representations of zero.  Postive zero has all bits clear;
negative zero has all bits set.

> In fact, out of all the CPU architectures which I have ever seen,
> not one of them used anything other than 2's complement arithmetic.

Then you just don't go back far enough. :-)  I recall some early
machine used 1's complement.  CDC feels right but maybe it was Univac
or RCA or GE; I'm sure someone else will correct me on this.  Anyway,
a manufacturer that's not in business any more).  But all the machines
I've ever worked on were based on 2's complement as well.

                                               Lee Jones

1997\03\10@105655 by David Moisan

picon face
At 08:53 PM 3/9/97 -0800, you wrote:
>
>Then you just don't go back far enough. :-)  I recall some early
>machine used 1's complement.  CDC feels right but maybe it was Univac

CDC machines were 1's complement.  My favorite machines to code!

Dave
| David Moisan, N1KGH                        Email: .....dmoisanKILLspamspam@spam@shore.net  |
| WWW: http://www.shore.net/~dmoisan                n1kghspamKILLspamamsat.org    |
| Invisible Disabilities Page:                                         |
| http://www.shore.net/~dmoisan/invisible_disability.html              |
| GE Superradio FAQ:                                                   |
| http://www1.shore.net/~dmoisan/faqs/superradio/gesr_faq.html         |

1997\03\11@021815 by Shel Michaels

picon face
SJH wrote:

<< In fact, out of all the CPU architectures which I have ever seen, not one
of them
used anything other than 2's complement arithmetic.
>>

Digital Equipment's very first computer line, the PDP-1, was 1's complement
(with an 18 bit word length!) 8^)

Shel Michaels

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