> From: "Michael N. Steen" > > 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 > 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