summaryrefslogtreecommitdiff
path: root/as
diff options
context:
space:
mode:
Diffstat (limited to 'as')
-rw-r--r--as/Makefile11
-rw-r--r--as/as.l25
-rw-r--r--as/as.y36
-rw-r--r--as/x86.h38
4 files changed, 110 insertions, 0 deletions
diff --git a/as/Makefile b/as/Makefile
new file mode 100644
index 0000000..99fe9de
--- /dev/null
+++ b/as/Makefile
@@ -0,0 +1,11 @@
+as: as.yy.o as.tab.o
+ c99 -o $@ as.yy.o as.tab.o -ly -ll
+
+as.yy.c: as.l as.tab.h
+ lex -t as.l > $@
+
+as.tab.h as.tab.c: as.y
+ yacc -d -b as as.y
+
+clean:
+ rm -f as *.o as.yy.c as.tab.c as.tab.h
diff --git a/as/as.l b/as/as.l
new file mode 100644
index 0000000..059b7c3
--- /dev/null
+++ b/as/as.l
@@ -0,0 +1,25 @@
+%{
+#include <inttypes.h>
+#include "as.tab.h"
+%}
+
+NONDIGIT [_a-zA-Z]
+DIGIT [0-9]
+IDENTIFIERS [_a-zA-Z0-9]
+
+%x COMMENT
+
+%%
+
+{DIGIT}+ { yylval.n = strtoumax(yytext, NULL, 10); return NUMBER; }
+
+{NONDIGIT}{IDENTIFIERS}* { yylval.s = yytext; return TOKEN; }
+
+:|,|\. { return yytext[0]; }
+\n { return NEWLINE; }
+
+; { BEGIN COMMENT; }
+<COMMENT>. ;
+<COMMENT>\n { BEGIN INITIAL; return NEWLINE; }
+
+. ;
diff --git a/as/as.y b/as/as.y
new file mode 100644
index 0000000..ed8714f
--- /dev/null
+++ b/as/as.y
@@ -0,0 +1,36 @@
+%{
+#include <inttypes.h>
+%}
+
+%union {
+ char *s;
+ uintmax_t n;
+};
+
+%token<n> NUMBER
+%token<s> TOKEN
+%token NEWLINE
+
+%%
+
+program
+ : /* empty */
+ | instruction NEWLINE
+;
+
+instruction
+ : bare_instruction
+ | TOKEN ':' bare_instruction
+;
+
+bare_instruction
+ : TOKEN
+ | TOKEN operand
+ | TOKEN operand ',' operand
+ | TOKEN operand ',' operand ',' operand
+;
+
+operand
+ : TOKEN
+ | NUMBER
+;
diff --git a/as/x86.h b/as/x86.h
new file mode 100644
index 0000000..56bf639
--- /dev/null
+++ b/as/x86.h
@@ -0,0 +1,38 @@
+struct {
+const char *mnemonic;
+const char *opcode;
+char x32;
+char x64;
+} x86_opcodes[] = {
+{ "aaa", "37", 1, 0 },
+
+{ "aad", "d5 0a", 1, 0 },
+{ "aad imm8", "db ib", 1, 0 },
+
+{ "aam", "d4 0a", 1, 0 },
+{ "aam imm8", "d4 ib", 1, 0 },
+
+{ "aas", "3f" , 1, 0 },
+
+{ "adc al, imm8", "14 ib", 1, 1 },
+{ "adc ax, immm16", "15 iw", 1, 1 },
+{ "adc eax, imm32", "15 id", 1, 1 },
+{ "adc rax, imm32", "rex.w 15 id", 0, 1 },
+{ "adc r/m8, imm8", "80 /2 ib", 1, 1 },
+{ "adc r/m8*, imm8", "rex 80 /2 ib", 0, 1 },
+{ "adc r/m16, imm16", "81 /2 iw", 1, 1 },
+{ "adc r/m32, imm32", "81 /2 id", 1, 1 },
+{ "adc r/m64, imm32", "rex.w 81 /2 id", 0, 1 },
+{ "adc r/m16, imm8", "83 /2 ib", 1, 1 },
+{ "adc r/m32, imm8", "83 /2 ib", 1, 1 },
+{ "adc r/m64, imm8", "rex.w 83 /2 ib", 0, 1 },
+{ "adc r/m8, r8", "10 /r", 1, 1 },
+{ "adc r/m8*, r8*", "rex 10 /r", 0, 1 },
+{ "adc r/m16, r16", "11 /r", 1, 1 },
+{ "adc r/m32, r32", "11 /r", 1, 1 },
+{ "adc r/m64, r64", "rex.w 11 /r", 0, 1 },
+{ "adc r8, r/m8", "12 /r", 1, 1 },
+{ "adc r8*, r/m8*", "rex 12 /r", 0, 1 },
+{ "adc r16, r/m16", "13 /r", 1, 1 },
+{ "adc r32, r/m32", "13 /r", 1, 1 },
+{ "adc r64, r/m64", "rex.w 13 /r", 0, 1 },