diff options
| -rw-r--r-- | asm.peg | 10 | ||||
| -rw-r--r-- | main.c | 8 | ||||
| -rw-r--r-- | minias.h | 23 | ||||
| -rw-r--r-- | test/test.sh | 7 |
4 files changed, 18 insertions, 30 deletions
@@ -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); } @@ -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, @@ -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" + |
