From 6adf85be15e923c761180054630db07834b9f53f Mon Sep 17 00:00:00 2001 From: pavelyakov Date: Mon, 19 Nov 2018 09:04:24 +0000 Subject: [PATCH] Brainfuck interpreter update git-svn-id: svn://kolibrios.org@7557 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/cmm/BrainFuck/brainfuck.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/programs/cmm/BrainFuck/brainfuck.c b/programs/cmm/BrainFuck/brainfuck.c index d2c8f5a244..0ae7011bca 100644 --- a/programs/cmm/BrainFuck/brainfuck.c +++ b/programs/cmm/BrainFuck/brainfuck.c @@ -16,11 +16,13 @@ dword buffer = 0; word bufferSymbol = 0; dword memory = 0; byte initConsole = 0; +dword stack = 0; void consoleInit() { IF(!initConsole) { + load_dll(libConsole, #con_init, 0); con_init stdcall (-1, -1, -1, -1, "BrainF*ck interpreter"); initConsole = 0xFF; } @@ -44,6 +46,7 @@ void evalBrainFuckCode(dword code) //-------- offsetMemory = memory + countOffset; + countStack = stack; WHILE(1) { @@ -56,11 +59,12 @@ void evalBrainFuckCode(dword code) DSBYTE[offsetMemory]--; break; case '[': - $push code; + DSDWORD[countStack] = code; + countStack += 4; break; case ']': - IF (DSBYTE[offsetMemory]) code = DSDWORD[ESP]; - ELSE $pop EAX; + IF (DSBYTE[offsetMemory]) code = DSDWORD[countStack - 4]; + ELSE countStack -= 4; break; case ',': consoleInit(); @@ -93,8 +97,7 @@ void main() buffer = malloc(bufferSize); memory = malloc(memoryBrainfuck); - - load_dll(libConsole, #con_init, 0); + stack = malloc(stackBrainFuck); IF(DSBYTE[I_Param]) { @@ -103,17 +106,16 @@ void main() ELSE { consoleInit(); - con_printf stdcall ("BrainF*ck interpreter v1.1\r\n"); + con_printf stdcall ("BrainF*ck interpreter v1.01\r\n"); loop() { con_printf stdcall ("\r\nEnter BrainF*ck code:\r\n"); - con_printf stdcall ("Output BrainF*ck:\r\n"); con_gets stdcall(buffer, bufferSize); evalBrainFuckCode(EAX); - con_printf stdcall ("\r\n"); + con_printf stdcall ("\r\nOutput BrainF*ck:\r\n"); } } - IF(initConsole) con_exit stdcall (0); ExitProcess(); + IF(initConsole) con_exit stdcall (0); }