2018-02-02 21:50:58 +00:00
|
|
|
/************************************
|
|
|
|
* LOOPS - Test C02 Loop Structures *
|
|
|
|
************************************/
|
|
|
|
|
2018-08-19 22:24:02 +00:00
|
|
|
//Specify System Header using -H option
|
|
|
|
#include <stddef.h02>
|
2018-02-02 21:50:58 +00:00
|
|
|
#include <stdio.h02>
|
|
|
|
|
2019-11-20 06:08:09 +00:00
|
|
|
char aa,ii; //Function Variables
|
|
|
|
char b; //Comparison Variable
|
|
|
|
char i; //Loop Counter
|
|
|
|
|
|
|
|
void putlin() {putstr(); newlin();}
|
|
|
|
void failed() {putlin(" FAILED");}
|
|
|
|
void passed() {putlin(" PASSED");}
|
2018-02-02 21:50:58 +00:00
|
|
|
|
|
|
|
main:
|
2019-11-20 06:08:09 +00:00
|
|
|
putlin("TESTING LOOPS");
|
2018-02-02 21:50:58 +00:00
|
|
|
|
2019-11-20 06:08:09 +00:00
|
|
|
/* Test If/Goto Loop */
|
|
|
|
putstr("IF ");
|
|
|
|
i = 0;
|
|
|
|
ifloop:
|
|
|
|
putchr('0'+i);
|
|
|
|
i++;
|
|
|
|
if (i < 8) goto ifloop;
|
|
|
|
if (i=8) passed(); else failed();
|
2018-02-02 21:50:58 +00:00
|
|
|
|
2019-11-20 06:08:09 +00:00
|
|
|
/* Test Block If */
|
|
|
|
putstr("BLOCK ");
|
|
|
|
b = 1;
|
|
|
|
if (b>0) {
|
|
|
|
prhex(b);
|
|
|
|
putstr(" > ");
|
|
|
|
prhex(0);
|
|
|
|
passed();
|
|
|
|
}
|
|
|
|
else failed();
|
2018-02-02 21:50:58 +00:00
|
|
|
|
2019-11-20 06:08:09 +00:00
|
|
|
putstr(" IF ");
|
|
|
|
b = 0;
|
|
|
|
if (b>0) failed();
|
|
|
|
else {
|
|
|
|
putchr('0'+i);
|
|
|
|
putstr(" = ");
|
|
|
|
prhex(0);
|
|
|
|
passed();
|
|
|
|
}
|
2018-02-02 21:50:58 +00:00
|
|
|
|
2019-11-20 06:08:09 +00:00
|
|
|
/* Test While Loop */
|
|
|
|
putstr("WHILE ");
|
|
|
|
i = 0;
|
|
|
|
while (i < 8) {
|
|
|
|
putchr('0'+i);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (i=8) passed(); else failed();
|
2018-02-02 21:50:58 +00:00
|
|
|
|
2019-11-20 06:08:09 +00:00
|
|
|
/* Test Do Loop */
|
|
|
|
putstr("DO ");
|
|
|
|
i = 0;
|
|
|
|
do {
|
|
|
|
putchr('0'+i);
|
|
|
|
i++;
|
|
|
|
} while (i<8);
|
|
|
|
if (i=8) passed(); else failed();
|
2018-07-19 03:49:39 +00:00
|
|
|
|
2019-11-20 06:08:09 +00:00
|
|
|
/* Test For Loop */
|
|
|
|
putstr("FOR ");
|
|
|
|
i = 0;
|
|
|
|
for (i=0;i<8;i++) {
|
|
|
|
putchr('0'+i);
|
|
|
|
}
|
|
|
|
if (i=8) passed(); else failed();
|
2018-07-19 03:49:39 +00:00
|
|
|
|
2019-11-20 06:08:09 +00:00
|
|
|
/* While with Break */
|
|
|
|
putstr("BREAK ");
|
|
|
|
i = 0;
|
|
|
|
while ($FF) {
|
|
|
|
if (i = 8) break;
|
|
|
|
putchr('0'+i);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (i=8) passed(); else failed();
|
2018-02-02 21:50:58 +00:00
|
|
|
|
2019-11-20 06:08:09 +00:00
|
|
|
/* For with Continue */
|
|
|
|
putstr("CONT ");
|
|
|
|
for (i=0;i<16;i++) {
|
|
|
|
if (i & 1) { continue; i=$FF;}
|
|
|
|
putchr('A'+i);
|
|
|
|
}
|
|
|
|
if (i=16) passed(); else failed();
|
2018-02-02 21:50:58 +00:00
|
|
|
|
2019-11-20 06:08:09 +00:00
|
|
|
/* Test Do with Break and Continue*/
|
|
|
|
i = 0;
|
|
|
|
putstr("DO BC ");
|
|
|
|
do {
|
|
|
|
i++;
|
|
|
|
if (!i&1) {continue; i=$FF;}
|
|
|
|
if (i>16) break;
|
|
|
|
putchr('A'+i);
|
|
|
|
} while ($FF);
|
|
|
|
if (i=17) passed(); else failed();
|
2018-02-02 21:50:58 +00:00
|
|
|
|
2019-11-20 06:08:09 +00:00
|
|
|
/* Test If/Else, Select in For Loop */
|
|
|
|
for(i = 0;i<4;i++) {
|
|
|
|
select (i) {
|
|
|
|
case 0: putstr("FOR "); b=0;
|
|
|
|
case 1: putstr(" IF "); b=1;
|
|
|
|
case 2: putstr(" ELSE "); b=2;
|
|
|
|
case 3: putstr(" SELECT "); b=3;
|
|
|
|
default: putstr(" ERROR! "); b=$FF;
|
|
|
|
}
|
|
|
|
putchr('0'+i);
|
|
|
|
if (i & 1) putstr("-ODD "); else putstr("-EVEN");
|
|
|
|
if (i=b) passed(); else failed();
|
|
|
|
}
|
|
|
|
|
|
|
|
putlin("ALL TESTS COMPLETE");
|
|
|
|
goto exit;
|