Latelifecrisis
Member
Hi All
I've just spent a while trying to work out why some code didn't work as expected. The code copies a 16-bit data value (a temperature value with lsn being 1/16ths of degree), from a block in scratchpad, then allows the value to be increased or decreased before placing back into scratchpad. When the original code didn't work as expected, I went through many iterations to try to isolate exactly WHY it didn't work. What it seems to come down to is that the @ptrinc and @ptrdec instructions don't do what I think they should. Is it my misunderstanding, or is the editor/compiler misbehaving ?
I actually started with the instruction w3=@ptr - expecting the compiler to understand from the "W3" that this was a word instruction. I tried adding the keyword "WORD" before, in and after the instruction, but the compiler threw that out. I presume the @ptr instruction can't support words (but the manual doesn't say so and the compiler accepts it).
When it didn't work as expected I changed to byte instructions. However using @ptrinc and @ptrdec instructions also didn't work as expected. This all seems to be about moving the msb and lsb incorrectly, or the @ptrdec and @ptrinc instructions not correctly moving the ptr value as advertised.
I've used the @ptrinc instruction in other parts of the program with no apparent problems. So it's puzzling.
I'm using the latest 6.1.0.0 editor for a 28X2 chip
All suggestions appreciated - full code available if needed for debugging / analysis
;
; **************************************************************************************************************************************
; take 15
;
; try moving the ptr around "manually" instead of using @ptrinc and @ptrdec
;
; this works
;
ptr = wkday_boiler_temp1 ;******************** try forcing the pointer to the "right" place ********************************
;
b6 = @ptr
ptr = ptr + 1
b7 = @ptr
if up_key_moved=1 then
if w3 < %0000010001100000 then ; max temp 70 degrees
inc w3
endif
elseif down_key_moved=1 then
if w3 > %0000000010100000 then ; min temp 10 degrees
dec w3
endif
endif
@ptr = b7
ptr = ptr - 1
@ptr = b6
;
;
; **************************************************************************************************************************************
; take 14
;
; try removing the second force of the ptr, and changing the order of re-writing the data to sratchpad
;
; doesn't work - back to no up count, down in chunks of 16 degrees
;
;
ptr = wkday_boiler_temp1 ;******************** try forcing the pointer to the "right" place ********************************
;
b6 = @ptrinc
b7 = @ptr
if up_key_moved=1 then
if w3 < %0000010001100000 then ; max temp 70 degrees
inc w3
endif
elseif down_key_moved=1 then
if w3 > %0000000010100000 then ; min temp 10 degrees
dec w3
endif
endif
;
@ptrdec = b7
@ptr = b6
;
;
I've just spent a while trying to work out why some code didn't work as expected. The code copies a 16-bit data value (a temperature value with lsn being 1/16ths of degree), from a block in scratchpad, then allows the value to be increased or decreased before placing back into scratchpad. When the original code didn't work as expected, I went through many iterations to try to isolate exactly WHY it didn't work. What it seems to come down to is that the @ptrinc and @ptrdec instructions don't do what I think they should. Is it my misunderstanding, or is the editor/compiler misbehaving ?
I actually started with the instruction w3=@ptr - expecting the compiler to understand from the "W3" that this was a word instruction. I tried adding the keyword "WORD" before, in and after the instruction, but the compiler threw that out. I presume the @ptr instruction can't support words (but the manual doesn't say so and the compiler accepts it).
When it didn't work as expected I changed to byte instructions. However using @ptrinc and @ptrdec instructions also didn't work as expected. This all seems to be about moving the msb and lsb incorrectly, or the @ptrdec and @ptrinc instructions not correctly moving the ptr value as advertised.
I've used the @ptrinc instruction in other parts of the program with no apparent problems. So it's puzzling.
I'm using the latest 6.1.0.0 editor for a 28X2 chip
All suggestions appreciated - full code available if needed for debugging / analysis
;
; **************************************************************************************************************************************
; take 15
;
; try moving the ptr around "manually" instead of using @ptrinc and @ptrdec
;
; this works
;
ptr = wkday_boiler_temp1 ;******************** try forcing the pointer to the "right" place ********************************
;
b6 = @ptr
ptr = ptr + 1
b7 = @ptr
if up_key_moved=1 then
if w3 < %0000010001100000 then ; max temp 70 degrees
inc w3
endif
elseif down_key_moved=1 then
if w3 > %0000000010100000 then ; min temp 10 degrees
dec w3
endif
endif
@ptr = b7
ptr = ptr - 1
@ptr = b6
;
;
; **************************************************************************************************************************************
; take 14
;
; try removing the second force of the ptr, and changing the order of re-writing the data to sratchpad
;
; doesn't work - back to no up count, down in chunks of 16 degrees
;
;
ptr = wkday_boiler_temp1 ;******************** try forcing the pointer to the "right" place ********************************
;
b6 = @ptrinc
b7 = @ptr
if up_key_moved=1 then
if w3 < %0000010001100000 then ; max temp 70 degrees
inc w3
endif
elseif down_key_moved=1 then
if w3 > %0000000010100000 then ; min temp 10 degrees
dec w3
endif
endif
;
@ptrdec = b7
@ptr = b6
;
;