rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
Strange variable reaction |
Posted: Wed Aug 25, 2004 4:58 pm |
|
|
I have a section of my code that is acting a bit qirky.
This is just a code snippet, of course.
Code: |
#define MAX_TRAVEL 201000
unsigned int32 travel = 0;//global
unsigned int32 distance = 0;//global
unsigned int16 shimmy = 400;//global
main()
{
unsigned int32 skoot = 0;
skoot = MAX_TRAVEL;
travel = skoot - shimmy;// <-- this assignment works correctly
travel = MAX_TRAVEL - shimmy;// <-- this assignment does NOT work correctly
while(1)
;
} |
Maybe somebody can tell me why one statement works and why one doesn't.
Compiler ver. 3.206
PIC18F452
Here's a snippet of the LST file for each statement. I don't know assembly and I'm really not too excited to learn it either.
Code: |
.................... travel = skoot - shimmy;
1A8C: MOVF 7C,W
1A8E: SUBWF x9D,W
1A90: MOVWF 70
1A92: MOVF 7D,W
1A94: SUBWFB x9E,W
1A96: MOVWF 71
1A98: MOVLW 00
1A9A: SUBWFB x9F,W
1A9C: MOVWF 72
1A9E: MOVLW 00
1AA0: SUBWFB xA0,W
1AA2: MOVWF 73
.................... travel = MAX_TRAVEL - shimmy;
1A8C: MOVLW 28
1A8E: BSF FD8.0
1A90: SUBFWB 7C,W
1A92: MOVWF 70
1A94: MOVLW 11
1A96: SUBFWB 7D,W
1A98: MOVWF 71
1A9A: MOVLW 00
1A9C: SUBWFB 03,W
1A9E: MOVWF 72
1AA0: MOVLW 00
1AA2: SUBWFB 00,W
1AA4: MOVWF 73
|
I haven't tried to find out what the actual value is being assigned for the statement that doesn't work, I just know that the statement that compares it:
if(distance > travel)// and so on....
never enters the if() statement.
Anybody enlighten me?
Ronald |
|