/
example.c
72 lines (54 loc) · 1.04 KB
/
example.c
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
/* cisc.c
* Mock-assembly programming for a CISC-like architecture
*
* Programmer: Mayer Goldberg, 2010
*/
#include <stdio.h>
#include <stdlib.h>
#include "cisc.h"
/* change to 0 for no debug info to be printed: */
#define DO_SHOW 1
/* for debugging only, use SHOW("<some message>, <arg> */
#if DO_SHOW
#define SHOW(msg, x) { printf("%s %s = %ld\n", (msg), (#x), (x)); }
#else
#define SHOW(msg, x) {}
#endif
int main()
{
START_MACHINE;
void print_heap(){
int i;
printf("printing heap\n");
for (i=ADDR(0); i>=0; i--){
printf("\t element %d: ", i);
SHOW(" ",ADDR(i));
}
}
JUMP(CONTINUE);
#include "scheme.lib"
#include "char.lib"
#include "io.lib"
#include "math.lib"
#include "string.lib"
#include "system.lib"
CONTINUE:
PUSH(IMM(9));
CALL(MALLOC);
CALL(MAKE_SOB_VOID);
CALL(MAKE_SOB_NIL);
PUSH(IMM(0));
CALL(MAKE_SOB_BOOL);
PUSH(IMM(1));
CALL(MAKE_SOB_BOOL);
DROP(3);
print_heap();
PUSH(IMM(3));
CALL(MALLOC);
END:
PUSH(R0);
CALL(WRITE_SOB);
DROP(IMM(1));
STOP_MACHINE;
return 0;
}