From 96386d56e3d78e2402083812a45e729f0c798719 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Szostak?= Date: Sat, 8 Jun 2024 17:56:45 +0200 Subject: [PATCH] Implemented instruction to dump data from registers to memory --- Makefile | 26 +++++++++++--------------- src/shardware.adb | 16 ++++++++++++---- src/sillymachine.adb | 21 +++++++++++++++++++++ 3 files changed, 44 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index b782c0d..bd1a255 100644 --- a/Makefile +++ b/Makefile @@ -1,27 +1,23 @@ default: sillymachine -floattobitshelper: ./src/floattobitshelper.c ./src/floattobitshelper.h - gcc -c src/floattobitshelper.c -o floattobitshelper.o - ar -crs floattobitshelper.a floattobitshelper.o - -floatwin: ./src/floattobitshelper.c ./src/floattobitshelper.h - x86_64-w64-mingw32-gcc -c src/floattobitshelper.c -o floatwin.o -lwinmm -lgdi32 - ar -crs floattobitshelper.a floatwin.o - - -sillymachine: ./src/sillymachine.adb ./src/*.adb ./src/*.ads floattobitshelper +sillymachine: ./src/sillymachine.adb ./src/*.adb ./src/*.ads ./src/floattobitshelper.h ./src/floattobitshelper.c + gcc -c src/floattobitshelper.c -o floattobitshelper.o + ar -crs floattobitshelper.a floattobitshelper.o gnatmake ./src/sillymachine.adb -largs -L./ -l:floattobitshelper.a -debug: ./src/sillymachine.adb ./src/*.adb ./src/*.ads floattobitshelper +debug: ./src/sillymachine.adb ./src/*.adb ./src/*.ads ./src/floattobitshelper.h ./src/floattobitshelper.c + gcc -g -c src/floattobitshelper.c -o floattobitshelper.o + ar -crs floattobitshelper.a floattobitshelper.o gnatmake ./src/sillymachine.adb -o sillymachine-debug -g -largs -L./ -l:floattobitshelper.a -win: ./src/sillymachine.adb ./src/*.adb ./src/*.ads floatwin - - x86_64-w64-mingw32-gnatmake src/sillymachine.adb -lwinmm -lgdi32 -largs -L./ -l:floattobitshelper.a +win: ./src/sillymachine.adb ./src/*.adb ./src/*.ads ./src/floattobitshelper.h ./src/floattobitshelper.c + x86_64-w64-mingw32-gcc -c src/floattobitshelper.c -o floatwin.o -lwinmm -lgdi32 + ar -crs floatwin.a floatwin.o + x86_64-w64-mingw32-gnatmake src/sillymachine.adb -lwinmm -lgdi32 -largs -L./ -l:floatwin.a all: sillymachine win clean: - rm *.o *.ali *.a sillymachine.exe sillymachine sillymachine-debug + rm *.o *.ali *.a sillymachine sillymachine.exe sillymachine-debug diff --git a/src/shardware.adb b/src/shardware.adb index 6d82cae..9cc320c 100644 --- a/src/shardware.adb +++ b/src/shardware.adb @@ -262,10 +262,18 @@ package body Shardware is Length : Integer := Integer(Registers (3)); CharBuff : String (1 .. Length); begin - for i in 1 .. Length loop - CharBuff (i) := Character'Val(Memory (Pointer + Unsigned_32(i))); - end loop; - Put(CharBuff); + if InputTypeFlag = LEString then + for i in 1 .. Length loop + CharBuff (i) := Character'Val(Memory (Pointer + Unsigned_32(i))); + end loop; + Put(CharBuff); + elsif InputTypeFlag = LEUint then + Put(Unsigned_32'Image(Registers (26))); + elsif InputTypeFlag = LEInt then + Put(Integer'Image(UnToSignedInt(Registers (26)))); + elsif InputTypeFlag = LEFloat then + Put(Float'Image(BytesToF(UToBytes(Registers (26))))); + end if; end; when others => null; end case; diff --git a/src/sillymachine.adb b/src/sillymachine.adb index d515df2..9a27aa6 100644 --- a/src/sillymachine.adb +++ b/src/sillymachine.adb @@ -213,6 +213,27 @@ begin when 3 => InputTypeFlag := LEFloat; when others => InputTypeFlag := LEString; end case; + when 44 => -- Dump Register to Memory (Unsigned) + declare + Buffer : ByteArr(1 .. 4); + begin + Buffer := UToBytes(RegisterU(Integer(Instruction(3)))); + WriteMem(MemoryArr, BytesToU(TempBytes(Instruction)), Buffer, True); + end; + when 45 => -- Dump Register to Memory (Int) + declare + Buffer : ByteArr(1 .. 4); + begin + Buffer := IToBytes(RegisterI(Integer(Instruction(3)))); + WriteMem(MemoryArr, BytesToU(TempBytes(Instruction)), Buffer, True); + end; + when 46 => -- Dump Register to Memory (Float) + declare + Buffer : ByteArr(1 .. 4); + begin + Buffer := FToBytes(RegisterF(Integer(Instruction(3)))); + WriteMem(MemoryArr, BytesToU(TempBytes(Instruction)), Buffer, True); + end; when 65535 => goto THE_END; -- exit opcode when others => null;