aboutsummaryrefslogtreecommitdiff
path: root/as.h
blob: a67e15f449377117e0a64e24daa2e462cbb3f0ef (plain)
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
#define bool char
#define true 1
#define false 0

typedef enum {
  NOP, SUBLEQ, SUB, ADD, JMP, MOV, BEQ, NOT, HALT, DATA
} INSTRUCTION;

typedef struct {
  INSTRUCTION i;
  int a, b, c;
  int args;
  bool eof;
  bool valid;
} TOKEN;

void out(FILE* file, int a, int b, int c) {
  fwrite(&a, sizeof(int), 1, file);
  fwrite(&b, sizeof(int), 1, file);
  fwrite(&c, sizeof(int), 1, file);
  fflush(file);
}

#define PLEN 6
#define Z 3

void preamble(FILE* file) {
  // Jump over Z
  out(file, 1, 1, PLEN);
  // Z
  out(file, 0, 0, 0);
}

void postamble(FILE* file) {
  // Halt
  out(file, -1, -1, -1);
}