Skip to content

Commit

Permalink
feat: Add Stack BusActivations
Browse files Browse the repository at this point in the history
  • Loading branch information
furesoft committed Oct 27, 2024
1 parent be56f27 commit 894cb25
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/MimaSim/MimaSim/MIMA/Components/Stack.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace MimaSim.MIMA.Components;
using MimaSim.Core;

namespace MimaSim.MIMA.Components;

public class Stack(CPU cpu)
{
Expand All @@ -9,10 +11,18 @@ public void Push()
var sp = cpu.ControlUnit.SP.GetValue();
var value = cpu.Accumulator.GetValue();

if (sp < 0)
{
cpu.ControlUnit.SetError(ErrorCodes.StackOverflow);
return;
}

Data[sp] = value;
sp--;

cpu.ControlUnit.SP.SetValue(sp);

BusRegistry.Activate("cu->stack");
}

public void Pop()
Expand All @@ -24,5 +34,7 @@ public void Pop()

sp++;
cpu.ControlUnit.SP.SetValue(sp);

BusRegistry.Activate("cu->stack");
}
}
3 changes: 2 additions & 1 deletion src/MimaSim/MimaSim/MIMA/ErrorCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
public enum ErrorCodes
{
Unknown,
SysCallNotFound = 0x01,
SysCallNotFound,
StackOverflow
}

0 comments on commit 894cb25

Please sign in to comment.