-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassembler.cpp
More file actions
54 lines (40 loc) · 1.05 KB
/
Copy pathassembler.cpp
File metadata and controls
54 lines (40 loc) · 1.05 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "assembler.h"
#include "processor.h"
void assembler(FILE* command_txt)
{
fopen_m("command.asm", asmcommand, "a");
char cmd[100] = " ";
int found_command = 0;
while (fscanf(command_txt, "%s", cmd) == 1)
{
if (COMPARE(cmd, "push", PUSH))
{
ARGUMENT(command_txt, asmcommand);
found_command = 1;
}
if (COMPARE(cmd, "add", ADD))
found_command = 1;
if (COMPARE(cmd, "pop", POP))
found_command = 1;
if (COMPARE(cmd, "sub", SUB))
found_command = 1;
if (COMPARE(cmd, "jmp", JMP))
{
ARGUMENT(command_txt, asmcommand);
found_command = 1;
}
if (COMPARE(cmd, "mul", MUL))
found_command = 1;
if (COMPARE(cmd, "hlt", HLT))
found_command = 1;
if (!found_command)
{
printf("Unknown command: %s\n", cmd);
}
}
fclose(asmcommand);
}