Filippo - ELMARC
(stranger)
Wed Apr 23 2008 04:57 AM
BUG BUG BUG!!! in array index operation

look this code:

;input_drv.c: 513: SM.Output.LedStatus = ManualTest_Led_Table[SM.ProgramStatus.PhaseStepIndex];
51 20 mov a, [(_SM+10)^0]
64 asl a
01 00 add a, <_ManualTest_Led_Table
5C mov x, a
50 1E mov a, >_ManualTest_Led_Table
08 push a
28 romx

ManualTest_Led_Table is defined as follow:
const u_int16 ManualTest_Led_Table[]
and as you can see is placed at 0x1E00

then we want substract 1 in the table index index:

;input_drv.c: 515: else SM.Output.LedStatus = ManualTest_Led_Table[(SM.ProgramStatus.PhaseStepIndex - 1)];
51 20 mov a, [(_SM+10)^0]
64 asl a
01 FE add a, <(_ManualTest_Led_Table+-2)
5C mov x, a
50 1D mov a, >(_ManualTest_Led_Table+-2)
08 push a
28 romx

The MSB of ManualTest_Led_Table is always 0x1D and is wrong!

if we try to cast the result:

;input_drv.c: 515: else SM.Output.LedStatus = ManualTest_Led_Table[(u_int08) (SM.ProgramStatus.Phase
StepIndex - 1)];
51 20 mov a, [(_SM+10)^0]
64 asl a
01 FE add a, <(_ManualTest_Led_Table+254)
5C mov x, a
50 1E mov a, >(_ManualTest_Led_Table+254)
08 push a
28 romx

that is wrong with SM.ProgramStatus.PhaseStepIndex = 0



Contact Us | Privacy statement HI-TECH Software

Powered by UBB.threads™ 6.5.5