MC logo

Save And Restore

^  Dr. Bennet

Tswitch

Main Page
F06 Assignment
Download Library
CCSC '07 Paper

Clients for Tswitch

Save And Restore
Restack
Multiple Stacks

Clients for the F06 Assignment

Simple
Thread Demolition Derby
Graph Search
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

tssimp.c Restack With Save And Restore>>
#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);

}
Restack With Save And Restore>>