Implemented moving integer (only positive for now) to register
This commit is contained in:
parent
90b495d03a
commit
f929c99b04
20
src/shardware.adb
Normal file
20
src/shardware.adb
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
with Interfaces; use Interfaces;
|
||||||
|
|
||||||
|
package body Shardware is
|
||||||
|
|
||||||
|
function My_Shift (Value : Byte; Amount : Integer) return Integer is
|
||||||
|
begin
|
||||||
|
if Value > 127 and Amount > 23 then
|
||||||
|
return Integer(Shift_Left(Unsigned_128(Value), 23));
|
||||||
|
else
|
||||||
|
return Integer(Shift_Left(Unsigned_128(Value), Amount));
|
||||||
|
end if;
|
||||||
|
end My_Shift;
|
||||||
|
|
||||||
|
|
||||||
|
procedure Mov (Register : in out Integer; Value : Integer) is
|
||||||
|
begin
|
||||||
|
Register := Value;
|
||||||
|
end Mov;
|
||||||
|
|
||||||
|
end Shardware;
|
15
src/shardware.ads
Normal file
15
src/shardware.ads
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
with Ada.Sequential_IO;
|
||||||
|
|
||||||
|
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 RegArr is array (Integer range <>) of Integer;
|
||||||
|
|
||||||
|
function My_Shift (Value : Byte; Amount : Integer) return Integer;
|
||||||
|
|
||||||
|
procedure Mov (Register : in out Integer; Value : Integer);
|
||||||
|
|
||||||
|
end Shardware;
|
@ -1,13 +1,10 @@
|
|||||||
|
with Shardware; use Shardware;
|
||||||
|
|
||||||
with Ada.Text_IO; use Ada.Text_IO;
|
with Ada.Text_IO; use Ada.Text_IO;
|
||||||
with Ada.Sequential_IO;
|
|
||||||
with Ada.Command_Line; use Ada.Command_Line;
|
with Ada.Command_Line; use Ada.Command_Line;
|
||||||
with Ada.Directories;
|
with Ada.Directories;
|
||||||
with Interfaces; use Interfaces;
|
|
||||||
|
|
||||||
procedure sillymachine is
|
procedure sillymachine is
|
||||||
type Byte is mod 256;
|
|
||||||
package Bin_IO is new Ada.Sequential_IO (Byte);
|
|
||||||
type ByteArr is array (Integer range <>) of Byte;
|
|
||||||
|
|
||||||
F : Bin_IO.File_Type;
|
F : Bin_IO.File_Type;
|
||||||
FileName : String (1 .. 255) := (others => ascii.nul);
|
FileName : String (1 .. 255) := (others => ascii.nul);
|
||||||
@ -23,6 +20,8 @@ procedure sillymachine is
|
|||||||
PC : Integer := 0; -- Program Counter
|
PC : Integer := 0; -- Program Counter
|
||||||
Instruction : ByteArr (0 .. 15);
|
Instruction : ByteArr (0 .. 15);
|
||||||
|
|
||||||
|
Register : RegArr (0 .. 27);
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
|
||||||
ValidHeader (0) := 6;
|
ValidHeader (0) := 6;
|
||||||
@ -57,7 +56,7 @@ begin
|
|||||||
Bin_IO.Read(F, Value);
|
Bin_IO.Read(F, Value);
|
||||||
|
|
||||||
if ValidHeader (I) = Value then
|
if ValidHeader (I) = Value then
|
||||||
Value := Value; -- useless line so compiler does not complain
|
null;
|
||||||
else
|
else
|
||||||
New_Line(1);
|
New_Line(1);
|
||||||
Put_Line("Error: Please use a valid sm binary file");
|
Put_Line("Error: Please use a valid sm binary file");
|
||||||
@ -84,6 +83,10 @@ begin
|
|||||||
declare
|
declare
|
||||||
MemoryArr : ByteArr (0 .. MemorySize);
|
MemoryArr : ByteArr (0 .. MemorySize);
|
||||||
begin
|
begin
|
||||||
|
for i in 0 .. 27 loop -- zero initialise registers
|
||||||
|
Register (i) := 0;
|
||||||
|
end loop;
|
||||||
|
|
||||||
for i in 0 .. MemorySize loop -- zero initialise memory
|
for i in 0 .. MemorySize loop -- zero initialise memory
|
||||||
MemoryArr (i) := 0;
|
MemoryArr (i) := 0;
|
||||||
end loop;
|
end loop;
|
||||||
@ -103,13 +106,21 @@ begin
|
|||||||
Instruction (i) := MemoryArr (PC + i);
|
Instruction (i) := MemoryArr (PC + i);
|
||||||
end loop;
|
end loop;
|
||||||
|
|
||||||
case Shift_Left(Unsigned_128(Instruction (0)), 8) + Unsigned_128(Instruction (1)) is -- execute the instruction
|
case My_Shift(Instruction (0), 8) + Integer(Instruction (1)) is -- execute the instruction
|
||||||
when 0 => Put_Line("-- japko --");
|
when 0 => Mov(Register(Integer(Instruction (2))), -- Move Int to Register (Only positive values for now)
|
||||||
when 1 => Put_Line("-- banan --");
|
Integer(My_Shift(Instruction (7), 24)
|
||||||
|
+ My_Shift(Instruction (8), 16)
|
||||||
|
+ My_Shift(Instruction (9), 8)
|
||||||
|
+ Integer(Instruction (10)))
|
||||||
|
);
|
||||||
|
when 1 => Mov(Register(Integer(Instruction (2))), -- Move Register to Register
|
||||||
|
Register(Integer(Instruction (3))));
|
||||||
when 65535 => goto THE_END; -- exit opcode
|
when 65535 => goto THE_END; -- exit opcode
|
||||||
when others => New_Line(1);
|
when others => null;
|
||||||
end case;
|
end case;
|
||||||
|
|
||||||
|
Put_Line(Integer'Image(Register(0)));
|
||||||
|
|
||||||
PC := PC + 16; -- increment program counter to next instruction
|
PC := PC + 16; -- increment program counter to next instruction
|
||||||
end loop;
|
end loop;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user