;)
This commit is contained in:
@@ -184,9 +184,9 @@ assemble:
|
|||||||
.operator_1_memory_access:
|
.operator_1_memory_access:
|
||||||
push rsi
|
push rsi
|
||||||
mov rsi, .msg_operator_1_memory_access
|
mov rsi, .msg_operator_1_memory_access
|
||||||
call print.error
|
call print.debug
|
||||||
pop rsi
|
pop rsi
|
||||||
jmp halt
|
jmp .unsupported_memory_access
|
||||||
|
|
||||||
.operator_1_register:
|
.operator_1_register:
|
||||||
push rsi
|
push rsi
|
||||||
@@ -254,9 +254,9 @@ assemble:
|
|||||||
.operator_2_memory_access:
|
.operator_2_memory_access:
|
||||||
push rsi
|
push rsi
|
||||||
mov rsi, .msg_operator_2_memory_access
|
mov rsi, .msg_operator_2_memory_access
|
||||||
call print.error
|
call print.debug
|
||||||
pop rsi
|
pop rsi
|
||||||
jmp halt
|
jmp .unsupported_memory_access
|
||||||
|
|
||||||
.operator_2_register:
|
.operator_2_register:
|
||||||
push rsi
|
push rsi
|
||||||
@@ -299,9 +299,38 @@ assemble:
|
|||||||
.operator_2_register_memory_access:
|
.operator_2_register_memory_access:
|
||||||
push rsi
|
push rsi
|
||||||
mov rsi, .msg_operator_2_register_memory_access
|
mov rsi, .msg_operator_2_register_memory_access
|
||||||
call print.error
|
call print.debug
|
||||||
pop rsi
|
pop rsi
|
||||||
jmp halt
|
|
||||||
|
cmp di, 0x1000 ; check if token is addressing to a register
|
||||||
|
jne .unsupported_memory_access ; if not, unsupported :/
|
||||||
|
|
||||||
|
pop rax
|
||||||
|
pop rdi
|
||||||
|
inc rax
|
||||||
|
cmp rax, rdi
|
||||||
|
jge .break
|
||||||
|
push rdi
|
||||||
|
push rax
|
||||||
|
xor edi, edi
|
||||||
|
mov di, [rax * TOKEN_TABLE_ENTRY_SIZE + TOKEN_TABLE_ADDR] ; di = next tte
|
||||||
|
|
||||||
|
; si = `R/M` tte
|
||||||
|
; di = `reg` tte
|
||||||
|
push rsi
|
||||||
|
mov si, di
|
||||||
|
pop rdi
|
||||||
|
mov dl, 00b ; dl = mod bits
|
||||||
|
call get_ModRM
|
||||||
|
; al = Mod R/M byte
|
||||||
|
call .output_byte
|
||||||
|
|
||||||
|
pop rax ; rax = number of tokens processed
|
||||||
|
pop rdi ; rdi = total number of tokens
|
||||||
|
inc rax
|
||||||
|
cmp rax, rdi
|
||||||
|
jge .break
|
||||||
|
jmp .loop
|
||||||
|
|
||||||
.operator_2_register_register:
|
.operator_2_register_register:
|
||||||
push rsi
|
push rsi
|
||||||
@@ -311,6 +340,9 @@ assemble:
|
|||||||
|
|
||||||
; si = `R/M` tte
|
; si = `R/M` tte
|
||||||
; di = `reg` tte
|
; di = `reg` tte
|
||||||
|
push rsi
|
||||||
|
mov si, di
|
||||||
|
pop rdi
|
||||||
mov dl, 11b ; dl = mod bits
|
mov dl, 11b ; dl = mod bits
|
||||||
call get_ModRM
|
call get_ModRM
|
||||||
; al = Mod R/M byte
|
; al = Mod R/M byte
|
||||||
@@ -331,6 +363,11 @@ assemble:
|
|||||||
call print.error
|
call print.error
|
||||||
jmp halt
|
jmp halt
|
||||||
|
|
||||||
|
.unsupported_memory_access:
|
||||||
|
mov rsi, .msg_unsupported_memory_access
|
||||||
|
call print.error
|
||||||
|
jmp halt
|
||||||
|
|
||||||
; procedures
|
; procedures
|
||||||
|
|
||||||
; al = byte to write
|
; al = byte to write
|
||||||
@@ -343,7 +380,8 @@ assemble:
|
|||||||
.next_output_byte dd OUTPUT_ADDR ; next empty byte in output
|
.next_output_byte dd OUTPUT_ADDR ; next empty byte in output
|
||||||
; TODO get rid of this sketchy bit of state
|
; TODO get rid of this sketchy bit of state
|
||||||
|
|
||||||
.msg_unexpected_token db "unexpected token while assembling, aborting", 0x0A, 0x00
|
.msg_unexpected_token db "unexpected token, aborting", 0x0A, 0x00
|
||||||
|
.msg_unsupported_memory_access db "unsupported memory access, aborting", 0x0A, 0x00
|
||||||
.msg_operator_0 db "operator_0", 0x0A, 0x00
|
.msg_operator_0 db "operator_0", 0x0A, 0x00
|
||||||
.msg_operator_1 db "operator_1", 0x0A, 0x00
|
.msg_operator_1 db "operator_1", 0x0A, 0x00
|
||||||
.msg_operator_1_memory_access db "operator_1_memory_access", 0x0A, 0x00
|
.msg_operator_1_memory_access db "operator_1_memory_access", 0x0A, 0x00
|
||||||
@@ -1677,7 +1715,7 @@ opcodes:
|
|||||||
db 0x00 ; reserved
|
db 0x00 ; reserved
|
||||||
|
|
||||||
dw 0x0056 ; mov
|
dw 0x0056 ; mov
|
||||||
db 0x89
|
db 0x8B
|
||||||
db 0x00 ; reserved
|
db 0x00 ; reserved
|
||||||
|
|
||||||
dw 0x004F ; hlt
|
dw 0x004F ; hlt
|
||||||
@@ -1695,6 +1733,7 @@ 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 rdx, [rax]", 0x0A
|
||||||
db "mov [rax], rdx", 0x0A
|
db "mov [rax], rdx", 0x0A
|
||||||
db "hlt", 0x0A ; TODO make it so it doesn't need to end with a newline; this
|
db "hlt", 0x0A ; TODO make it so it doesn't need to end with a newline; this
|
||||||
; would mean range checking members in operator/operand/com-
|
; would mean range checking members in operator/operand/com-
|
||||||
|
|||||||
Reference in New Issue
Block a user