Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / bug-2221.c
blobceaf8ec171a192fa39e06960afd1fc713b5b7251
1 /*
2 bug-2221.c
3 */
5 #include <testfwk.h>
7 #ifdef __SDCC_mcs51
8 #pragma nooverlay
9 #include <8052.h>
11 //two functions that use the same registers (but should be in different banks)
13 unsigned char calculate(unsigned char v1,unsigned char v2)
15 unsigned char v3;
16 TF2 = 1; //trigger the interrupt
17 v3 = v1 / 2;
18 return v3 + v1 + v2;
22 unsigned char calculateISR(unsigned char v1,unsigned char v2) __using(1)
24 unsigned char v3;
25 TF2 = 0; //clear the interrupt
26 v3 = v1 / 2;
27 return v3 + v1 + v2;
31 unsigned char r1;
32 unsigned char r2;
34 void T2_isr(void) __interrupt(5) __using(1)
36 r1 = calculateISR(4,40);
38 //sdcc eliminates mov psw,0x080
39 //which is necessary to ensure that calculateISR uses registers from bank 1 to not
40 //corrupt calculate in main loop
42 #endif
44 void testBug(void)
46 #if 0 //defined(__SDCC_mcs51) && defined(__SDCC_STACK_AUTO) // TODO:remove STACK_AUTO CONDITION when division support routine becomes reentrant or sdcc optimizes out the call.
47 TF2 = 0; //clear timer 2 interrupt
48 ET2 = 1; //enable timer 2 interrupt
49 EA = 1; //enable interrupts
51 r2 = calculate(8,30);
52 ASSERT(r1 == 46);
53 ASSERT(r2 == 42);
54 #endif