Add information on the initial program loader to the readme, reorganise and otherwise clarify the readme, and change instruction pointer to byte pointer in the disassembler

This commit is contained in:
CrazyEttin 2022-07-24 22:47:37 +03:00
parent da55d3b7cf
commit ddce9abba1
2 changed files with 43 additions and 35 deletions

View File

@ -5,7 +5,7 @@ uses Crt, Sysutils;
var var
Op, Regs: 0 .. $f; //Opcode, and register arguments in a single variable Op, Regs: 0 .. $f; //Opcode, and register arguments in a single variable
X, Y: 0 .. 3; //Register arguments in separate variables X, Y: 0 .. 3; //Register arguments in separate variables
Addr, IP, EP: word; //Address argument and instruction and end pointers Addr, BP, EP: word; //Address argument and byte and end pointers
Opcodes: array [0 .. $f] of string; //Opcodes in human readable form Opcodes: array [0 .. $f] of string; //Opcodes in human readable form
Bin: array [0 .. $ffef] of byte; //Program in binary form Bin: array [0 .. $ffef] of byte; //Program in binary form
Prog: file of byte; //Program file Prog: file of byte; //Program file
@ -30,8 +30,8 @@ begin
Opcodes [$e] := 'CLEQ '; Opcodes [$e] := 'CLEQ ';
Opcodes [$f] := 'CLNEQ '; Opcodes [$f] := 'CLNEQ ';
//Initialise the instruction pointer //Initialise the byte pointer
IP := 0; BP := 0;
//Read a program file and check for errors //Read a program file and check for errors
if ParamCount <> 1 then begin if ParamCount <> 1 then begin
@ -47,38 +47,38 @@ begin
exit; exit;
end; end;
repeat repeat
read (Prog, Bin [IP]); read (Prog, Bin [BP]);
IP := IP + 1; BP := BP + 1;
until (eof (Prog)) or (IP = $fff0); until (eof (Prog)) or (BP = $fff0);
//Save the end point and reinitialise the instruction pointer //Save the end point and reinitialise the instruction pointer
EP := IP; EP := BP;
IP := 0; BP := 0;
//Begin the main loop //Begin the main loop
repeat repeat
//Print the memory location //Print the memory location
if IP < $1000 then write (' '); if BP < $1000 then write (' ');
if IP < $100 then write (' '); if BP < $100 then write (' ');
if IP < $10 then write (' '); if BP < $10 then write (' ');
write (IntToHex (IP, 1), ' '); write (IntToHex (BP, 1), ' ');
//Fetch the instruction and increment the instruction pointer //Fetch the instruction and increment the instruction pointer
//Opcode //Opcode
Op := Bin [IP] and $f0 shr 4; Op := Bin [BP] and $f0 shr 4;
//Register arguments //Register arguments
Regs := Bin [IP] and $f; Regs := Bin [BP] and $f;
X := Bin [IP] and $c shr 2; X := Bin [BP] and $c shr 2;
Y := Bin [IP] and 3; Y := Bin [BP] and 3;
IP := IP + 1; BP := BP + 1;
//Address argument //Address argument
if Op >= $a then begin if Op >= $a then begin
Addr := Bin [IP]; Addr := Bin [BP];
Addr := Addr shl 8; Addr := Addr shl 8;
IP := IP + 1; BP := BP + 1;
Addr := Addr + Bin [IP]; Addr := Addr + Bin [BP];
IP := IP - 1; BP := BP - 1;
end; end;
//Print the data //Print the data
@ -100,6 +100,6 @@ begin
until (IP >= EP); until (BP >= EP);
end. end.

View File

@ -1,8 +1,8 @@
Thingamajig Thingamajig
=========== ===========
Thingamajig is a RISC-y and MISC-y hobbyist instruction set Thingamajig is a RISC-y and MISC-y hobbyist computer architecture. Its
architecture. Its git repository can be found at git repository can be found at
https://ahti.space/git/crazyettin/Thingamajig. https://ahti.space/git/crazyettin/Thingamajig.
Registers and Memory Registers and Memory
@ -15,17 +15,9 @@ Registers and Memory
Multi-byte values are big-endian. Memory addresses FFF0-FFFF are Multi-byte values are big-endian. Memory addresses FFF0-FFFF are
reserved for memory mapped devices. The instruction and return pointers reserved for memory mapped devices. The instruction and return pointers
should not have values higher than FFEF and FFF0 respectively to avoid cannot have values higher than FFEF and FFF0 respectively to avoid the
the reserved addresses. The instruction and return pointers are reserved addresses. The instruction and return pointers are initialised
initialised as 0 and FFF0 respectively; other registers and memory are as 0 and FFF0 respectively; other registers and memory are unitialised.
unitialised.
Memory-Mapped Devices
---------------------
Input (when read from) and output (when written to) are mapped to
address FFFF. Arbitrary devices can be mapped to the other reserved
addresses.
Instructions Instructions
------------ ------------
@ -56,3 +48,19 @@ C BREQ RX, RY, ADDR if (RX == RY) IP = ADDR
D BRNEQ RX, RY, ADDR if (RX != RY) IP = ADDR D BRNEQ RX, RY, ADDR if (RX != RY) IP = ADDR
E CLEQ RX, RY, ADDR if (RX == RY) {RP -= 1; *RP = IP; IP = ADDR} E CLEQ RX, RY, ADDR if (RX == RY) {RP -= 1; *RP = IP; IP = ADDR}
F CLNEQ RX, RY, ADDR if (RX != RY) {RP -= 1; *RP = IP; IP = ADDR} F CLNEQ RX, RY, ADDR if (RX != RY) {RP -= 1; *RP = IP; IP = ADDR}
Memory-Mapped Devices
---------------------
Input (when read from) and output (when written to) are mapped to
address FFFF. The emulator implements this by emulating a dumb serial
terminal.
Arbitrary devices can be mapped to the other reserved addresses.
Initial Program Loader
----------------------
At boot the initial program loader loads a program to the memory
starting from address 0 after which is cedes control to the processor.
The emulator loads the program from a file.