From a88ebe0b5ca8f4924fa8c4a50a58ef608ee46f63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Szostak?= Date: Mon, 29 Apr 2024 20:12:18 +0200 Subject: [PATCH] Properly implemented support for integers --- src/shardware.adb | 21 ++++++++++++--------- src/shardware.ads | 4 ++-- src/sillymachine.adb | 9 +++++---- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/shardware.adb b/src/shardware.adb index 328bb19..62fee17 100644 --- a/src/shardware.adb +++ b/src/shardware.adb @@ -2,15 +2,18 @@ with Interfaces; use Interfaces; package body Shardware is - function My_ShiftI (Value : Byte; Amount : Integer) return Integer is + function UnToSignedInt (Value : Unsigned_32) return Integer is + Diff1 : Integer := 0; + Diff2 : Integer := 0; begin - return Integer(Shift_Left(Unsigned_128(Value), Amount)); - end My_ShiftI; - - function My_ShiftF (Value : Byte; Amount : Integer) return Float is - begin - return Float(Shift_Left(Unsigned_128(Value), Amount)); - end My_ShiftF; + if Value > 2147483647 then + Diff1 := Integer(Value - 2147483648); + Diff2 := Diff1 - 2147483647; + return Diff2 - 1; + else + return Integer(Value); + end if; + end UnToSignedInt; function My_ShiftU (Value : Byte; Amount : Integer) return Unsigned_32 is begin @@ -19,7 +22,7 @@ package body Shardware is function Bytes_To_I (Instruction : ByteArr) return Integer is begin - return Integer(Bytes_To_U(Instruction)); + return UnToSignedInt(Bytes_To_U(Instruction)); end Bytes_To_I; function Bytes_To_U (Instruction : ByteArr) return Unsigned_32 is diff --git a/src/shardware.ads b/src/shardware.ads index 42bbb88..0de2f73 100644 --- a/src/shardware.ads +++ b/src/shardware.ads @@ -11,8 +11,8 @@ package Shardware is type RegArrF is array (Integer range <>) of Float; type RegArrU is array (Integer range <>) of Unsigned_32; - function My_ShiftI (Value : Byte; Amount : Integer) return Integer; - function My_ShiftF (Value : Byte; Amount : Integer) return Float; + function UnToSignedInt (Value : Unsigned_32) return Integer; + function My_ShiftU (Value : Byte; Amount : Integer) return Unsigned_32; function Bytes_To_I (Instruction : ByteArr) return Integer; diff --git a/src/sillymachine.adb b/src/sillymachine.adb index 21bd9a6..a5859bf 100644 --- a/src/sillymachine.adb +++ b/src/sillymachine.adb @@ -113,7 +113,7 @@ begin Instruction (i) := MemoryArr (PC + i); end loop; - case My_ShiftI(Instruction (0), 8) + Integer(Instruction (1)) is -- execute the instruction + case My_ShiftU(Instruction (0), 8) + Unsigned_32(Instruction (1)) is -- execute the instruction when 0 => null; -- NOP when 1 => null; -- TODO: TRAP when 2 => MovU(RegisterU(Integer(Instruction (2))), @@ -138,9 +138,10 @@ begin when others => null; end case; - Put_Line(Unsigned_32'Image(RegisterU(0))); - Put_Line(Unsigned_32'Image(RegisterU(1))); - --Put_Line(Integer'Image(RegisterI(0))); + --Put_Line(Unsigned_32'Image(RegisterU(0))); + --Put_Line(Unsigned_32'Image(RegisterU(1))); + Put_Line(Integer'Image(RegisterI(0))); + Put_Line(Integer'Image(RegisterI(1))); PC := PC + 16; -- increment program counter to next instruction end loop;