10 char *program
[50]; // sized based on pre-inspecting file
13 get (const char *value
)
16 return regs
[*value
- 'a'];
21 set (const char *reg
, int value
)
23 regs
[*reg
- 'a'] = value
;
26 int main(int argc
, char **argv
)
29 char buf
[200]; // sized based on pre-inspecting file
30 int nread
= fread (buf
, 1, sizeof buf
, stdin
);
32 while (p
< buf
+ nread
) {
37 printf ("program consists of %d instructions\n", instr
);
42 char arg1
[10], arg2
[10];
44 sscanf (program
[pc
], "%*s %9s %9s", arg1
, arg2
);
45 switch (program
[pc
][0]) {
47 set (arg2
, get (arg1
));
51 set (arg1
, get (arg1
) + 1);
55 set (arg1
, get (arg1
) - 1);
68 printf ("after %d operations, final content of register a: %d\n",