Tswitch
Clients for Tswitch
Clients for the F06 Assignment
This is a simple test driver which shows how the
regsave
and
regrest
transfer control. Notice how the
regrest
call transfers
control back to
regsave
, and how return values are used to
get different behavior after
regsave
returns from different places.
The output is
A: t = 1, rs = 0
B: t = 1
A: t = 14, rs = 1
D: t = 14
A: t = 55, rs = 2
C: t = 55
A: t = -4, rs = 3
E: t = -4
#include <stdio.h>
#include <tswitch.h>
regbuf_t rb;
main()
{
int t = 1;
int rs = regsave(rb);
printf("A: t = %d, rs = %d\n", t, rs);
if(rs == 0) {
printf("B: t = %d\n", t);
t = 14;
regrest(rb, 1);
} else if(rs == 2) {
printf("C: t = %d\n", t);
t = -4;
regrest(rb, 3);
} else if(rs == 1) {
printf("D: t = %d\n", t);
t = 55;
regrest(rb, 2);
}
printf("E: t = %d\n", t);
}