summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--twasm/asm/main.asm27
-rw-r--r--twasm/asm/tests.asm9
2 files changed, 28 insertions, 8 deletions
diff --git a/twasm/asm/main.asm b/twasm/asm/main.asm
index fe08d48..b0e7cad 100644
--- a/twasm/asm/main.asm
+++ b/twasm/asm/main.asm
@@ -773,13 +773,27 @@ evaluate_operand:
pop rdi ; rdi -> first byte of operand
mov rsi, rax ; rsi = size of operand w/o trailing whitespace
- cmp [rdi + 1], '['
+ cmp rsi, 0 ; case: 0 length
+ je .unrecognised ; unrecognised
+
+ cmp byte [rdi], '[' ; case: memory addressing
je .address
- jmp .register
+ jmp .register ; otherwise: register
.address:
- jmp halt
+ cmp byte [rdi + rsi - 1], ']' ; check if address is closed correctly
+ jne .unrecognised ; if not, fail
+ inc rdi ; rdi -> enclosed operand
+ sub rsi, 2 ; rsi = length of enclosed operand
+ call evaluate_operand
+ ; rax = binary data
+ ; dl = return code
+ cmp dl, 0x10 ; make sure return code isn't another memory reference
+ je .unrecognised ; if it is, fail
+
+ or dl, 0x10 ; flip bit for address return
+ ret
.register:
cmp rsi, 4
@@ -799,10 +813,6 @@ evaluate_operand:
je .register1
.register1:
and edi, 0xFF
- push rsi
- mov rsi, .msg
- call print.debug
- pop rsi
.register2:
and edi, 0xFFFF
.register3:
@@ -822,6 +832,7 @@ evaluate_operand:
.unrecognised:
mov dl, 0xFF
ret
+
.msg db "evaluate_operand", 0x0A, 0x00
; ------------------------------------------------------------------------------
@@ -1549,6 +1560,6 @@ program:
db "xor eax, eax", 0x0A
db "inc rax ; inline comment", 0x0A
db "; one line comment", 0x0A
- db "mov [ rax ], rdx", 0x0A
+ db "mov [rax], rdx", 0x0A
db "hlt", 0x00 ; for the sake of being able to print it, I made it a string
.size db $ - program
diff --git a/twasm/asm/tests.asm b/twasm/asm/tests.asm
index e2dd79e..5df2152 100644
--- a/twasm/asm/tests.asm
+++ b/twasm/asm/tests.asm
@@ -535,6 +535,14 @@ test_evaluate_operand:
cmp ax, 0x0003
jne .fail
+ mov rdi, .case3
+ mov rsi, 5
+ call evaluate_operand
+ cmp dl, 0x10
+ jne .fail
+ cmp ax, 0x0003
+ jne .fail
+
.pass:
mov rsi, msg_pass
call print
@@ -546,6 +554,7 @@ test_evaluate_operand:
.case0 db "rax"
.case1: ; intentionally blank
.case2 db "rdx"
+ .case3 db "[rdx]"
.msg db "test_evaluate_operand...", 0x00
msg_pass: