diff options
Diffstat (limited to 'twasm/asm/main.asm')
| -rw-r--r-- | twasm/asm/main.asm | 27 |
1 files changed, 19 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 |
