Implemented writing to standard output
This commit is contained in:
parent
43c2543a95
commit
d088328294
@ -1,4 +1,5 @@
|
||||
with Interfaces; use Interfaces;
|
||||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
|
||||
package body Shardware is
|
||||
|
||||
@ -34,7 +35,7 @@ package body Shardware is
|
||||
Buff (i) := False;
|
||||
end loop;
|
||||
for i in 1 .. 4 loop
|
||||
CurByte := TheBytes (i);
|
||||
CurByte := TheBytes (Unsigned_32(i));
|
||||
for j in reverse 1 .. 8 loop
|
||||
if CurByte mod 2 > 0 then
|
||||
Buff (j + Counter) := True;
|
||||
@ -67,7 +68,7 @@ package body Shardware is
|
||||
end if;
|
||||
end loop;
|
||||
Counter := Counter - 8;
|
||||
Buff (i) := CurByte;
|
||||
Buff (Unsigned_32(i)) := CurByte;
|
||||
end loop;
|
||||
return Buff;
|
||||
end BitsToBytes;
|
||||
@ -141,6 +142,25 @@ package body Shardware is
|
||||
return Result;
|
||||
end BytesToF;
|
||||
|
||||
procedure Trap (Registers : RegArrU; Memory : in out ByteArr; MemorySize : in out Unsigned_32) is
|
||||
begin
|
||||
case Registers(0) is
|
||||
when 0 => null;
|
||||
when 1 =>
|
||||
declare
|
||||
Pointer : Unsigned_32 := Registers (4) - 1;
|
||||
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_Line(CharBuff);
|
||||
end;
|
||||
when others => null;
|
||||
end case;
|
||||
end Trap;
|
||||
|
||||
procedure MovU (Register : in out Unsigned_32; Value : Unsigned_32) is
|
||||
begin
|
||||
Register := Value;
|
||||
|
@ -5,7 +5,7 @@ package Shardware is
|
||||
|
||||
type Byte is mod 256;
|
||||
package Bin_IO is new Ada.Sequential_IO (Byte);
|
||||
type ByteArr is array (Integer range <>) of Byte;
|
||||
type ByteArr is array (Unsigned_32 range <>) of Byte;
|
||||
|
||||
type BitArr is array (Integer range <>) of Boolean;
|
||||
|
||||
@ -26,6 +26,8 @@ package Shardware is
|
||||
function BytesToI (TheBytes : ByteArr) return Integer;
|
||||
function BytesToF (TheBytes : ByteArr) return Float;
|
||||
|
||||
procedure Trap (Registers : RegArrU; Memory : in out ByteArr; MemorySize : in out Unsigned_32);
|
||||
|
||||
procedure MovU (Register : in out Unsigned_32; Value : Unsigned_32);
|
||||
procedure MovI (Register : in out Integer; Value : Integer);
|
||||
procedure MovF (Register : in out Float; Value : Float);
|
||||
|
@ -13,11 +13,11 @@ procedure sillymachine is
|
||||
FileNameLength : Integer := 0;
|
||||
ValidHeader : ByteArr (0 .. 15);
|
||||
Arr : ByteArr (0 .. 15);
|
||||
I : Integer := 0;
|
||||
I : Unsigned_32 := 0;
|
||||
Value : Byte;
|
||||
|
||||
ExecSize : Integer := 0;
|
||||
MemorySize : Integer := 0;
|
||||
ExecSize : Unsigned_32 := 0;
|
||||
MemorySize : Unsigned_32 := 0;
|
||||
|
||||
PC : Unsigned_32 := 0; -- Program Counter
|
||||
Instruction : ByteArr (0 .. 15);
|
||||
@ -78,9 +78,9 @@ begin
|
||||
end loop;
|
||||
<< END_VALID >>
|
||||
Bin_IO.Close(F);
|
||||
Put_Line("Header passed");
|
||||
--Put_Line("Header passed");
|
||||
|
||||
ExecSize := Integer(Ada.Directories.Size(FileName));
|
||||
ExecSize := Unsigned_32(Ada.Directories.Size(FileName));
|
||||
MemorySize := ExecSize;
|
||||
|
||||
declare
|
||||
@ -108,12 +108,12 @@ begin
|
||||
PC := 64; -- initialise program counter to entry point
|
||||
while True loop
|
||||
for i in 0 .. 15 loop -- load the instruction
|
||||
Instruction (i) := MemoryArr (Integer(PC) + i);
|
||||
Instruction (Unsigned_32(i)) := MemoryArr (PC + Unsigned_32(i));
|
||||
end loop;
|
||||
|
||||
case MyShiftU(Instruction (0), 8) + Unsigned_32(Instruction (1)) is -- execute the instruction
|
||||
when 0 => null; -- NOP
|
||||
when 1 => null; -- TODO: TRAP
|
||||
when 1 => Trap(RegisterU, MemoryArr, MemorySize); -- TRAP
|
||||
when 2 => MovU(RegisterU(Integer(Instruction (2))), -- Move Unsigned_32 to Register
|
||||
BytesToU(TempBytes(Instruction)));
|
||||
when 3 => MovU(RegisterU(Integer(Instruction (2))), -- Move Register to Register (Unsigned_32)
|
||||
@ -205,13 +205,6 @@ 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(Integer'Image(RegisterI(1)));
|
||||
--Put_Line(Float'Image(RegisterF(0)));
|
||||
--Put_Line(Float'Image(RegisterF(1)));
|
||||
|
||||
PC := PC + 16; -- increment program counter to next instruction
|
||||
end loop;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user