add addressing to evaluate_operand
This commit is contained in:
@@ -773,13 +773,27 @@ evaluate_operand:
|
|||||||
pop rdi ; rdi -> first byte of operand
|
pop rdi ; rdi -> first byte of operand
|
||||||
mov rsi, rax ; rsi = size of operand w/o trailing whitespace
|
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
|
je .address
|
||||||
|
|
||||||
jmp .register
|
jmp .register ; otherwise: register
|
||||||
|
|
||||||
.address:
|
.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:
|
.register:
|
||||||
cmp rsi, 4
|
cmp rsi, 4
|
||||||
@@ -799,10 +813,6 @@ evaluate_operand:
|
|||||||
je .register1
|
je .register1
|
||||||
.register1:
|
.register1:
|
||||||
and edi, 0xFF
|
and edi, 0xFF
|
||||||
push rsi
|
|
||||||
mov rsi, .msg
|
|
||||||
call print.debug
|
|
||||||
pop rsi
|
|
||||||
.register2:
|
.register2:
|
||||||
and edi, 0xFFFF
|
and edi, 0xFFFF
|
||||||
.register3:
|
.register3:
|
||||||
@@ -822,6 +832,7 @@ evaluate_operand:
|
|||||||
.unrecognised:
|
.unrecognised:
|
||||||
mov dl, 0xFF
|
mov dl, 0xFF
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.msg db "evaluate_operand", 0x0A, 0x00
|
.msg db "evaluate_operand", 0x0A, 0x00
|
||||||
|
|
||||||
; ------------------------------------------------------------------------------
|
; ------------------------------------------------------------------------------
|
||||||
@@ -1549,6 +1560,6 @@ program:
|
|||||||
db "xor eax, eax", 0x0A
|
db "xor eax, eax", 0x0A
|
||||||
db "inc rax ; inline comment", 0x0A
|
db "inc rax ; inline comment", 0x0A
|
||||||
db "; one line 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
|
db "hlt", 0x00 ; for the sake of being able to print it, I made it a string
|
||||||
.size db $ - program
|
.size db $ - program
|
||||||
|
|||||||
@@ -535,6 +535,14 @@ test_evaluate_operand:
|
|||||||
cmp ax, 0x0003
|
cmp ax, 0x0003
|
||||||
jne .fail
|
jne .fail
|
||||||
|
|
||||||
|
mov rdi, .case3
|
||||||
|
mov rsi, 5
|
||||||
|
call evaluate_operand
|
||||||
|
cmp dl, 0x10
|
||||||
|
jne .fail
|
||||||
|
cmp ax, 0x0003
|
||||||
|
jne .fail
|
||||||
|
|
||||||
.pass:
|
.pass:
|
||||||
mov rsi, msg_pass
|
mov rsi, msg_pass
|
||||||
call print
|
call print
|
||||||
@@ -546,6 +554,7 @@ test_evaluate_operand:
|
|||||||
.case0 db "rax"
|
.case0 db "rax"
|
||||||
.case1: ; intentionally blank
|
.case1: ; intentionally blank
|
||||||
.case2 db "rdx"
|
.case2 db "rdx"
|
||||||
|
.case3 db "[rdx]"
|
||||||
.msg db "test_evaluate_operand...", 0x00
|
.msg db "test_evaluate_operand...", 0x00
|
||||||
|
|
||||||
msg_pass:
|
msg_pass:
|
||||||
|
|||||||
Reference in New Issue
Block a user