summaryrefslogtreecommitdiff
path: root/src/regression/nestfor.c
blob: 654efe80d5229e49fef24fb9c2d3dc3a1013dcda (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
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();
}