aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--asm.peg10
-rw-r--r--main.c8
-rw-r--r--minias.h23
-rw-r--r--test/test.sh7
4 files changed, 18 insertions, 30 deletions
diff --git a/asm.peg b/asm.peg
index aed5fad..76918fd 100644
--- a/asm.peg
+++ b/asm.peg
@@ -35,10 +35,18 @@ instr =
| i:xchg { $$ = i; }
| i:add { $$ = i; }
| i:and { $$ = i; }
+ | i:lea { $$ = i; }
| i:or { $$ = i; }
| i:sub { $$ = i; }
| i:xor { $$ = i; }
-
+
+lea =
+ 'lea' (
+ 'w'? ws s:m ws? ',' ws? d:r16 { $$ = INSTR(0, s, d); }
+ | 'l'? ws s:m ws? ',' ws? d:r32 { $$ = INSTR(1, s, d); }
+ | 'q'? ws s:m ws? ',' ws? d:r64 { $$ = INSTR(2, s, d); }
+ ) { $$.instr.kind = ASM_LEA; }
+
xchg =
'xchg' (
'w'? ws s:ax ws? ',' ws? d:r16 { $$ = INSTR(0, s, d); }
diff --git a/main.c b/main.c
index eda2818..51272cc 100644
--- a/main.c
+++ b/main.c
@@ -398,11 +398,9 @@ static void assemble() {
case ASM_RET:
sb(0xc3);
break;
- /*
- case ASM_MOVZX:
- case ASM_MOVSX:
- case ASM_LEA:
- */
+ case ASM_LEA:
+ assemblerrm(&v->instr, 0x8d);
+ break;
case ASM_ADD: {
static uint8_t variant2op[24] = {
0x04, 0x05, 0x05, 0x05, 0x00, 0x00, 0x00, 0x00,
diff --git a/minias.h b/minias.h
index ac14154..24eacfb 100644
--- a/minias.h
+++ b/minias.h
@@ -189,16 +189,6 @@ typedef struct {
Parsev *dst;
} Instr;
-/*
-typedef Instr Add;
-typedef Instr And;
-typedef Instr Lea;
-typedef Instr Mov;
-typedef Instr Movzx;
-typedef Instr Or;
-typedef Instr Sub;
-typedef Instr Xor;
-*/
typedef Instr Xchg;
union Parsev {
@@ -208,19 +198,6 @@ union Parsev {
Balign balign;
Memarg memarg;
Instr instr;
- /*
- Add add;
- And and;
- Lea lea;
- Mov mov;
- Movzx movzx;
- Or or;
- */
- Xchg xchg;
- /*
- Xor xor;
- Sub sub;
- */
Jmp jmp;
Byte byte;
Imm imm;
diff --git a/test/test.sh b/test/test.sh
index bf085e4..8d0255a 100644
--- a/test/test.sh
+++ b/test/test.sh
@@ -23,7 +23,7 @@ t () {
then
echo ""
echo "want: $1 -> $want"
- echo "got: $1 -> $got"
+ echo "got:"
objdump -d "$tmpo"
exit 1
fi
@@ -82,3 +82,8 @@ t "xchg (%rax), %rax"
t "xchg (%rax), %eax"
t "xchg (%rax), %ax"
t "xchg (%rax), %al"
+
+t "leaq (%rax), %rax"
+t "leal (%rax), %eax"
+t "leaw (%rax), %ax"
+