68 lines
845 B
NASM
68 lines
845 B
NASM
SYS_EXIT equ 0x1
|
|
SYS_READ equ 0x3
|
|
SYS_WRITE equ 0x4
|
|
|
|
STDIN equ 0x0
|
|
STDOUT equ 0x1
|
|
STDERR equ 0x2
|
|
|
|
section .data
|
|
space db " "
|
|
endl db 10
|
|
backslash db "\\"
|
|
quote db "\""
|
|
opening_curly db "{"
|
|
opening_bracket db "["
|
|
closing_curly db "}"
|
|
closing_bracket db "]"
|
|
comma db ","
|
|
colon db ":"
|
|
|
|
section .bss
|
|
char resb 1
|
|
exitCode resb 1
|
|
scope resb 1
|
|
in_string resb 1
|
|
escape_next resb 1
|
|
|
|
section .text
|
|
global _start
|
|
|
|
_start:
|
|
mov byte[exitCode], 0
|
|
mov byte[scope], 0
|
|
|
|
loop:
|
|
mov rax, SYS_READ
|
|
mov rbx, STDIN
|
|
mov rcx, char
|
|
mov rdx, 1
|
|
int 0x80
|
|
|
|
cmp rax, 0
|
|
jle end
|
|
|
|
mov rax, SYS_WRITE
|
|
mov rbx, STDOUT
|
|
mov rcx, char
|
|
mov rdx, 1
|
|
int 0x80
|
|
|
|
cmp byte[char], 0x61
|
|
je indent
|
|
|
|
jmp loop
|
|
|
|
indent:
|
|
mov rax, SYS_WRITE
|
|
mov rbx, STDOUT
|
|
mov rcx, space
|
|
mov rdx, 1
|
|
int 0x80
|
|
jmp loop
|
|
|
|
end:
|
|
mov rax, SYS_EXIT
|
|
mov rbx, [exitCode]
|
|
int 0x80
|