diff options
| author | Xavier ASUS <xavi92psx@gmail.com> | 2019-10-18 00:31:54 +0200 |
|---|---|---|
| committer | Xavier ASUS <xavi92psx@gmail.com> | 2019-10-18 00:31:54 +0200 |
| commit | 268a53de823a6750d6256ee1fb1e7707b4b45740 (patch) | |
| tree | 42c1799a9a82b2f7d9790ee9fe181d72a7274751 /src/regression/nestfor.c | |
| download | sdcc-gas-268a53de823a6750d6256ee1fb1e7707b4b45740.tar.gz | |
sdcc-3.9.0 fork implementing GNU assembler syntax
This fork aims to provide better support for stm8-binutils
Diffstat (limited to 'src/regression/nestfor.c')
| -rw-r--r-- | src/regression/nestfor.c | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/src/regression/nestfor.c b/src/regression/nestfor.c new file mode 100644 index 0000000..654efe8 --- /dev/null +++ b/src/regression/nestfor.c @@ -0,0 +1,139 @@ +#include "gpsim_assert.h" +#include "picregs.h" + +unsigned char failures=0; + +unsigned int uint0 = 0; +unsigned int uint1 = 0; +unsigned char uchar0 = 0; +unsigned char uchar1 = 0; + +void dput(unsigned char val) +{ + PORTB = val; + PORTA = 0x01; + PORTA = 0x00; +} + +void +done() +{ + ASSERT(MANGLE(failures) == 0); + PASSED(); +} + +/* both loops use the loop variable inside the inner loop */ +void for1(void) +{ + unsigned char i, j; + + uchar0 = 0; + uchar1 = 0; + for(i = 0; i < 3; i++) { + uchar0++; + for(j = 0; j < 4; j++) { + uchar1++; + dput(i); + dput(j); + } + } + if(uchar0 != 3) + failures++; + if(uchar1 != 12) + failures++; +} + +/* only the outer loop's variable is used inside, inner can be optimized into a repeat-loop */ +void for2(void) +{ + unsigned char i, j; + + uchar0 = 0; + uchar1 = 0; + for(i = 0; i < 3; i++) { + uchar0++; + for(j = 0; j < 4; j++) { + uchar1++; + dput(i); + } + } + if(uchar0 != 3) + failures++; + if(uchar1 != 12) + failures++; +} + +/* only the inner loop's variable is used inside */ +void for3(void) +{ + unsigned char i, j; + + uchar0 = 0; + uchar1 = 0; + for(i = 0; i < 3; i++) { + uchar0++; + for(j = 0; j < 4; j++) { + uchar1++; + dput(j); + } + } + if(uchar0 != 3) + failures++; + if(uchar1 != 12) + failures++; + +} + +/* neither loop variable used inside the loops */ +void for4(void) +{ + unsigned char i, j; + + uchar0 = 0; + uchar1 = 0; + for(i = 0; i < 3; i++) { + uchar0++; + for(j = 0; j < 4; j++) { + uchar1++; + dput(uchar0); + dput(uchar1); + } + } + if(uchar0 != 3) + failures++; + if(uchar1 != 12) + failures++; + +} + +/* like for1 but different condition in inner loop */ +void for5(void) +{ + unsigned char i, j; + + uchar0 = 0; + uchar1 = 0; + for(i = 0; i < 3; i++) { + uchar0++; + for(j = 10; j >= 5; j--) { + uchar1++; + dput(i); + dput(j); + } + } + if(uchar0 != 3) + failures++; + if(uchar1 != 18) + failures++; +} + +void main(void) +{ + for1(); + for2(); + for3(); + for4(); + for5(); + + done(); +} |
