diff --git a/Makefile b/Makefile index 02160a3..aa60bb9 100644 --- a/Makefile +++ b/Makefile @@ -17,10 +17,10 @@ # SYSTEM_VVP=system/system.vvp -BOOT_CODE=boot_code/brainfuck.txt +BOOT_CODE=boot_code/brainfuck_mandelbrot.txt GTKWSAVE=./gtkwave_savefile.gtkw MICROCODE=system/ucode.txt -BOOTABLES=boot_code/brainfuck_compiled.txt boot_code/brainfuck_mandelbrot.txt ${BOOT_CODE} +BOOTABLES=boot_code/brainfuck_compiled.txt boot_code/brainfuck.txt ${BOOT_CODE} NO_ASM=1 include common.mk diff --git a/boot_code/Makefile b/boot_code/Makefile index 7cebfb1..3fdd14b 100644 --- a/boot_code/Makefile +++ b/boot_code/Makefile @@ -8,8 +8,8 @@ BUILD_FILES+=$(subst .asm,.bin,${SOURCE}) all: ${BINARIES} brainfuck.bin: brainfuck_interpreter_v0.asm -brainfuck_mandelbrot.bin: brainfuck_interpreter_v0.asm brainfuck_compiled.bin: brainfuck_compiler_v1.asm +brainfuck_mandelbrot.bin: brainfuck_compiler_v1.asm NO_ASM=0 include ../common.mk diff --git a/boot_code/brainfuck_compiled.asm b/boot_code/brainfuck_compiled.asm index d4428b2..dadda72 100644 --- a/boot_code/brainfuck_compiled.asm +++ b/boot_code/brainfuck_compiled.asm @@ -5,3 +5,4 @@ prog: .ASCII '+++++++.---.--.<<.>---------------------.>+++++.-----------------.++++++++.+++++.--------.+++++++++++++++.---------------' .ASCII '---.++++++++.<<<.>>>------------------.++++++++++++++++++++++.++++++.---.+.<<.>>+.--.+++.---------.+++++++++++++.<<++++++' .ASCII '++++++.------------.>----------.--------.++++++++.--.<<.' +output_program: diff --git a/boot_code/brainfuck_compiler_v1.asm b/boot_code/brainfuck_compiler_v1.asm index 250beca..717cc56 100644 --- a/boot_code/brainfuck_compiler_v1.asm +++ b/boot_code/brainfuck_compiler_v1.asm @@ -20,12 +20,21 @@ mov sp,#STACK mov bx,#bootup_msg mov ah,#0x02 -bootup_print: +print1: mov dl,[bx] int #0x21 inc bx cmp dl,#0x0A -jne bootup_print +jne print1 + +mov bx,#compiling +mov ah,#0x02 +print2: +mov dl,[bx] +int #0x21 +inc bx +cmp dl,#0 +jne print2 MOV SI,#prog MOV DI,#output_program @@ -33,21 +42,6 @@ MOV DI,#output_program MOV CX,#0 JMP COMPILE ; Moving some functions above the main switch to make shot jumps work -;;;;;;;;; . ;;;;;;;;; -WAS_PRINT: -CALL FLUSH_MOVES -CALL FLUSH_WRITES - -MOV AX,#0x02B4 ; mov $0x2,%ah -STOSW - -MOV AX,#0x178A ; mov (%bx),%dl -STOSW - -MOV AX,#0x21CD ; int $0x21 -STOSW - -JMP COMPILE ;;;;;;;;; ] ;;;;;;;;; WAS_PR: @@ -80,55 +74,6 @@ MOV [BX],DI JMP COMPILE -;;;;;;;;;;; ACTUAL START ;;;;;;;;;;;;;;; -COMPILE: -MOV AL,[SI] -INC SI -CMP AL,#'+ -JZ WAS_PLUS -CMP AL,#'- -JZ WAS_MINUS -CMP AL,#'> -JZ WAS_MR -CMP AL,#'< -JZ WAS_ML -CMP AL,#'[ -JZ WAS_PL -CMP AL,#'] -JZ WAS_PR -CMP AL,#'. -JZ WAS_PRINT - -MOV AL,#0xF4 ; hlt -MOV [DI],AL -MOV BX,#DATA -MOV AX,#output_program -JMP AX - -;;;;;;;;; + ;;;;;;;;; -WAS_PLUS: -CALL FLUSH_MOVES -INC CL -JMP COMPILE - -;;;;;;;;; - ;;;;;;;;; -WAS_MINUS: -CALL FLUSH_MOVES -DEC CL -JMP COMPILE - -;;;;;;;;; > ;;;;;;;;; -WAS_MR: -CALL FLUSH_WRITES -INC CH -JMP COMPILE - -;;;;;;;;; < ;;;;;;;;; -WAS_ML: -CALL FLUSH_WRITES -DEC CH -JMP COMPILE - ;;;;;;;;; [ ;;;;;;;;; WAS_PL: CALL FLUSH_MOVES @@ -171,6 +116,80 @@ STOSW JMP COMPILE +;;;;;;;;;;; ACTUAL START ;;;;;;;;;;;;;;; +COMPILE: +MOV AL,[SI] +INC SI +CMP AL,#'+ +JZ WAS_PLUS +CMP AL,#'- +JZ WAS_MINUS +CMP AL,#'> +JZ WAS_MR +CMP AL,#'< +JZ WAS_ML +CMP AL,#'[ +JZ WAS_PL +CMP AL,#'] +JZ WAS_PR +CMP AL,#'. +JZ WAS_PRINT + +mov bx,#compiled +mov ah,#0x02 +print3: +mov dl,[bx] +int #0x21 +inc bx +cmp dl,#0x0A +jne print3 + +MOV AL,#0xF4 ; hlt +MOV [DI],AL +MOV BX,#DATA +MOV AX,#output_program +JMP AX + +;;;;;;;;; . ;;;;;;;;; +WAS_PRINT: +CALL FLUSH_MOVES +CALL FLUSH_WRITES + +MOV AX,#0x02B4 ; mov $0x2,%ah +STOSW + +MOV AX,#0x178A ; mov (%bx),%dl +STOSW + +MOV AX,#0x21CD ; int $0x21 +STOSW + +JMP COMPILE +;;;;;;;;; + ;;;;;;;;; +WAS_PLUS: +CALL FLUSH_MOVES +INC CL +JMP COMPILE + +;;;;;;;;; - ;;;;;;;;; +WAS_MINUS: +CALL FLUSH_MOVES +DEC CL +JMP COMPILE + +;;;;;;;;; > ;;;;;;;;; +WAS_MR: +CALL FLUSH_WRITES +INC CH +JMP COMPILE + +;;;;;;;;; < ;;;;;;;;; +WAS_ML: +CALL FLUSH_WRITES +DEC CH +JMP COMPILE + + FLUSH_WRITES: CMP CL,#0 @@ -238,7 +257,9 @@ MOVES_FLUSHED: MOV CH,#0 RET -bootup_msg: .ASCII 'Native brainfuck compiler v1\n' +bootup_msg: .ASCII 'Native 8086 brainfuck compiler v1\n' +compiling: .ASCII 'Compiling...\0' +compiled: .ASCII '\rCompiled! \n' DATA: .BLKB 560 .BLKB 200 STACK: