Comparing Bytes Anywhere in RAM
JDOhio
Posts: 72
I wrote a subroutine to compare bytes in two arrays. The intent of the comparison is to compare the bytes at each location until there is no match. If Idx reaches zero, then all of the bytes matched.
In stepping through this DO loop, I found that the comparison for the first byte always fails even when the data at the two locations described by the SX/B are the same (as verified by reviewing the locations in RAM on the debugger screen).
When I reviewed the assembly, it appears that it retrieves the value for the specified byte in TimeDate correctly. Before retrieving the value of the specified byte in MyDate, it assigns FSR to $10. In my program, the two arrays are not located in the $10 memory bank. When the code after the FSR assignment executes, it looks like it retrieves values from the $10 bank and the comparison fails.
I have also tried using
with the same results. Any ideas?
Joe
Idx=7 DO UNTIL TimeDate(Idx)<>MyDate(Idx) DEC Idx IF Idx=0 THEN EXIT LOOP
In stepping through this DO loop, I found that the comparison for the first byte always fails even when the data at the two locations described by the SX/B are the same (as verified by reviewing the locations in RAM on the debugger screen).
When I reviewed the assembly, it appears that it retrieves the value for the specified byte in TimeDate correctly. Before retrieving the value of the specified byte in MyDate, it assigns FSR to $10. In my program, the two arrays are not located in the $10 memory bank. When the code after the FSR assignment executes, it looks like it retrieves values from the $10 bank and the comparison fails.
__DO_4: ; DO UNTIL TimeDate(Idx)<>MyDate(Idx) MOV W,#TimeDate ADD W,Idx MOV FSR,W MOV __PARAM1,IND MOV FSR,#$10 MOV W,#MyDate ADD W,Idx MOV FSR,W MOV __PARAM2,IND MOV FSR,#$10 CJNE __PARAM1,__PARAM2,@__LOOP_4
I have also tried using
MyDateIndex=MyDate DO UNTIL TimeDate(Idx)<>__RAM(MyDateIndex)
with the same results. Any ideas?
Joe
Comments
Are your arrays defined as Byte (8) ?
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
"You're braver than you believe, stronger than you seem, and smarter than you think" Christopher Robin to Pooh
·
Since my program is made up of 14 SXB files, I'd rather attempt to faithfully reproduce the code in a single file showing the error rather than have someone trace the 14 files (this is why you see the large array and the declaration of many byte variables in the SX/B code below). In so doing, I think I resolved the error which raised more of a guidelines question for me.
The assembly code below demonstrates the error. In the SX/B, I populate some memory and then copy that memory using MoveBytes (you may recognize this from a previous post). Then, I call CompareBytes.
When the processor enters into the CompareBytes subroutine, FSR is set for the memory location of TimeDate and MyDate. This causes the processor to assign the wrong place in memory the value of Idx (MOV Idx,#6).
In setting up for the initial compare (TimeDate(Idx)<>MyDate(Idx)), the code assigns __PARAM1 the correct value from TimeDate (__PARAM1 has the correct value because FSR did not change during the retrieval of the TimeDate value) and then assigns FSR the value of $10.
When the code attempts to assign __PARAM2 from MyDate, the value is incorrect because the location of Idx is not the same as when it entered the subroutine (i.e., the value of FSR has changed).
To correct this, I added
to the end of MoveBytes (see below). The DO loop in CompareBytes executes correctly after the change to MoveBytes.
I reviewed some other assembly code around my program, and there is a pattern indicating that after every use of FSR for indirection, it is assigned $10.
Would this be a general guideline in working with SX/B?
This reproduces the error.
Joe
Yes but only for the SX48.
It's better to use the SX/B command "BANK" with no parameters. This will set FSR correctly for the SX28 or SX48.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
"You're braver than you believe, stronger than you seem, and smarter than you think" Christopher Robin to Pooh
·