Pull Up resistor wiring

Frederick C. Wilt said:
Sorry I wasn't clear. According to the docs you need a 0x at the beginning to identify a hexadecimal number, so 0x7FFFFFFF.
yeap that worked, keeps switching between -1 and a the equivalent in numbers of 0x7FFFFFFF
 
Maybe you can't access the first bit?  Otherwise, I can't tell why this wouldn't work.
 
START
SET VAR1 -1
DELAY 1000
ANDB 0x7FFFFFFF VAR1 VAR1
DELAY 2000
END
 
It's likely 2s complement format. Consider starting from zero (0x00000000). You increment by one and get 0x00000001. But start from zero and decrement by one you get 0xFFFFFFFF which should be negative 1.
 
In 2s complement format 0x7FFFFFFF is the largest 32 bit positive number and 0x80000000 is the "largest" negative number.
 
After thinking about for a bit, there is no way the first bit can be accessed in the normal fashion if it is determining sign.  It would totally screw up all the math.  So this was a bust.  I'll have to go back to using multiple lines of code to do absolute values.
 
Is this what you are doing for absolute value?
 
 
Code:
MYSUB:
    SET RAM1 VAR1
    CALLSUB ABS
    SET VAR1 RAM1
    RET

ABS:
    TSTGE RAM1 0
    RET
    XORB RAM1 -1 RAM1
    ADD RAM1 1 RAM1
    RET
 
 
az1324 said:
Is this what you are doing for absolute value?
 
 

MYSUB:
SET RAM1 VAR1
CALLSUB ABS
SET VAR1 RAM1
RET

ABS:
    TSTGE RAM1 0
    RET
    XORB RAM1 -1 RAM1
    ADD RAM1 1 RAM1
    RET
 
AZ, I ran this but nothing happened, I mean no value changes that I noticed.
 
az1324 said:
Is this what you are doing for absolute value?
 
 

MYSUB:
SET RAM1 VAR1
CALLSUB ABS
SET VAR1 RAM1
RET

ABS:
    TSTGE RAM1 0
    RET
    XORB RAM1 -1 RAM1
    ADD RAM1 1 RAM1
    RET
 
 
 
I forget what I did exactly. But it was different.  If I recall, the main thing that was the issue was that because I couldn't just test one value against the absolute value of another value, I had to convert it first.  This meant that I had to use branching/subroutines that otherwise wouldn't have been necessary.
 
It would be nice if there was a function like
 
TSTEQ VAR1 AVAR2
 
where the A denotes the absolute value.  I didn't want the sign of the number to change, I just wanted one line to test the absolute value.
 
siafu -- stop running random codes, man.  just leave your WC alone.  :p   You should spend time writing out comments of what each line does until you become an expert.
 
Lou -- that subroutine is the function.  Put your value in RAM1, call ABS and the absolute value will be in RAM1 then you can use it to compare.
 
Code:
SET RAM1 VAR2
CALLSUB ABS
TSTEQ VAR1 RAM1
Reuse it for other values as much as you want. Just make sure RAM1 is free in whatever scope you are calling ABS.
 
az1324 said:
siafu -- stop running random codes, man.  just leave your WC alone.  :p   You should spend time writing out comments of what each line does until you become an expert.
 
Lou -- that subroutine is the function.  Put your value in RAM1, call ABS and the absolute value will be in RAM1 then you can use it to compare.
 

SET RAM1 VAR2
CALLSUB ABS
TSTEQ VAR1 RAM1

Reuse it for other values as much as you want. Just make sure RAM1 is free in whatever scope you are calling ABS.
 
I understand how it works.  It just bugges things up having to call a subroutine.  You use 3 lines of code instead of 1, then you have to have a subroutine also.  And it blocks a RAM value from holding any values for other things during the time this code runs.
 
It would seem to be a simple thing for the CAI firmware to add something like
 
TSTEQ VAR1 AVAR2 where the "A" simply tells it to drop the signage bit during the comparison (effectively making it 0)
 
And I think Siafu is just having fun.  It does no harm in playing with the code.  As long as you keep a working copy saved it only takes 10 seconds to reload it.  I'm all for it.  I went from a theoretical understanding of bitwise to a working knowledge playing with it here.
 
That is true, but are you close to the code size limit? It is good to dedicate some RAM to working registers anyway, but if you have nested routines you may need more. If you are running out of memory you could start splitting them up into structs w/ packed 1-bit, 8-bit, 16-bit values. Of course then you need to write the packing/unpacking functions.
 
Back
Top