🚧 Starts working on switch
This commit is contained in:
parent
0146432afe
commit
cbedaa7f06
71
main.asm
71
main.asm
@ -6,22 +6,28 @@ STDIN equ 0x0
|
||||
STDOUT equ 0x1
|
||||
STDERR equ 0x2
|
||||
|
||||
; R15 is reserved for action
|
||||
ACTION_LOOP equ 0x0
|
||||
ACTION_CHAR equ 0x1
|
||||
ACTION_BACK_TO_OPENING equ 0x2
|
||||
|
||||
section .data
|
||||
space db " "
|
||||
endl db 10
|
||||
backslash db "\\"
|
||||
quote db "\""
|
||||
quote db 0x22 ; "
|
||||
opening_curly db "{"
|
||||
opening_bracket db "["
|
||||
closing_curly db "}"
|
||||
closing_bracket db "]"
|
||||
comma db ","
|
||||
colon db ":"
|
||||
indent dq 2 ; dq (64 bits) because we are working with 64 bit registers
|
||||
|
||||
section .bss
|
||||
char resb 1
|
||||
exitCode resb 1
|
||||
scope resb 1
|
||||
scope resq 1
|
||||
in_string resb 1
|
||||
escape_next resb 1
|
||||
|
||||
@ -39,27 +45,78 @@ _start:
|
||||
mov rdx, 1
|
||||
int 0x80
|
||||
|
||||
; is at EOF?
|
||||
cmp rax, 0
|
||||
jle end
|
||||
|
||||
mov al, [char]
|
||||
cmp al, [quote]
|
||||
je case_quote
|
||||
cmp al, [backslash]
|
||||
je case_backslash
|
||||
cmp al, [opening_curly]
|
||||
je case_opening
|
||||
cmp al, [opening_bracket]
|
||||
je case_opening
|
||||
|
||||
mov r15, ACTION_LOOP
|
||||
jmp print_char
|
||||
|
||||
case_quote:
|
||||
mov al, [escape_next]
|
||||
cmp al, 1
|
||||
je print_char
|
||||
|
||||
not byte[in_string]
|
||||
jmp print_char
|
||||
|
||||
case_backslash:
|
||||
mov byte[escape_next], 1
|
||||
jmp print_char
|
||||
|
||||
case_opening:
|
||||
mov r5, ACTION_BACK_TO_OPENING
|
||||
jmp print_char
|
||||
|
||||
inc byte[scope]
|
||||
|
||||
;je ln_start
|
||||
;jmp loop
|
||||
|
||||
print_char:
|
||||
mov rax, SYS_WRITE
|
||||
mov rbx, STDOUT
|
||||
mov rcx, char
|
||||
mov rdx, 1
|
||||
int 0x80
|
||||
|
||||
cmp byte[char], 0x61
|
||||
je indent
|
||||
cmp r15, ACTION_LOOP
|
||||
je loop
|
||||
|
||||
jmp loop
|
||||
ln_start:
|
||||
xor r8, r8
|
||||
xor r9, r9
|
||||
xor rax, rax
|
||||
|
||||
indent:
|
||||
mov rax, [indent]
|
||||
mov rbx, [scope]
|
||||
imul rax, rbx
|
||||
mov r9, rax
|
||||
|
||||
cmp qword[scope], 0
|
||||
je loop
|
||||
|
||||
ln_loop:
|
||||
mov rax, SYS_WRITE
|
||||
mov rbx, STDOUT
|
||||
mov rcx, space
|
||||
mov rdx, 1
|
||||
int 0x80
|
||||
jmp loop
|
||||
|
||||
inc r8
|
||||
cmp r8, r9
|
||||
jne ln_loop
|
||||
je loop
|
||||
|
||||
end:
|
||||
mov rax, SYS_EXIT
|
||||
|
Loading…
x
Reference in New Issue
Block a user