💀 Adds constants

This commit is contained in:
Daniel Svitan 2025-05-07 21:21:08 +02:00
parent 0190a14bd8
commit 0146432afe
3 changed files with 68 additions and 39 deletions

View File

@ -2,6 +2,6 @@
gcc main.c -o a.out
nasm -f elf64 main.s -o b.o
nasm -f elf64 main.asm -o b.o
ld b.o -o b.out
rm b.o

67
main.asm Normal file
View File

@ -0,0 +1,67 @@
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

38
main.s
View File

@ -1,38 +0,0 @@
SYS_EXIT equ 0x1
SYS_READ equ 0x3
SYS_WRITE equ 0x4
STDIN equ 0x0
STDOUT equ 0x1
STDERR equ 0x2
section .data
inputMsg db "> ", 0x0
inputLen equ $ - inputMsg
section .bss
char resb 1
exitCode resb 1
section .text
global _start
_start:
mov r8, 0
mov [exitCode], r8
mov rax, SYS_READ
mov rbx, STDIN
mov rcx, input
mov rdx, 64
int 0x80
;mov rax, SYS_WRITE
;mov rbx, STDOUT
;mov rcx, inputMsg
;mov rdx, inputLen
;int 0x80
mov rax, SYS_EXIT
mov rbx, [exitCode]
int 0x80