From 7d7509e8528c5f3998a5127c4622058655c7ed78 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Tue, 16 Apr 2024 12:56:14 +0200 Subject: [PATCH] Checkpoint --- app/src/main/java/hatelace/IntMemory.java | 7 ++----- app/src/main/java/hatelace/IntWord.java | 18 +++++++++++++----- app/src/main/java/hatelace/Main.java | 4 ++-- app/src/main/java/hatelace/Memory.java | 2 +- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/hatelace/IntMemory.java b/app/src/main/java/hatelace/IntMemory.java index 99fb96c..3be2faa 100644 --- a/app/src/main/java/hatelace/IntMemory.java +++ b/app/src/main/java/hatelace/IntMemory.java @@ -19,11 +19,8 @@ public class IntMemory extends Memory { return this.memory.length; } - public void write(int address, Word data) { - if (address < 0 || address >= this.memory.length) { - throw new IllegalArgumentException("Invalid memory address"); - } - this.memory[address] = data.getValue(); + public void write(Address address, Word data) { + this.memory[address.getAddress()] = data.getValue(); } /** Dump as IHEX-like format (see https://en.wikipedia.org/wiki/Intel_HEX) */ diff --git a/app/src/main/java/hatelace/IntWord.java b/app/src/main/java/hatelace/IntWord.java index 286e337..7473907 100644 --- a/app/src/main/java/hatelace/IntWord.java +++ b/app/src/main/java/hatelace/IntWord.java @@ -7,8 +7,16 @@ public class IntWord extends Word { this.value = value; } - public T getValue() { - return (T) value; + // public T getValue() { + // return value; + // } + + public Integer getValue() { + return value; + } + + public IntWord multiply(Word value) { + return new IntWord(this.value * (Integer) value.getValue()); } public T add(Word other) { @@ -19,9 +27,9 @@ public class IntWord extends Word { return (T) new IntWord(value - (Integer) other.getValue()); } - public T multiply(Word other) { - return (T) new IntWord(value * (Integer) other.getValue()); - } + // public T multiply(Word other) { + // return (T) new IntWord(value * (Integer) other.getValue()); + // } public T divide(Word other) { return (T) new IntWord(value / (Integer) other.getValue()); diff --git a/app/src/main/java/hatelace/Main.java b/app/src/main/java/hatelace/Main.java index dfaa036..85b8503 100644 --- a/app/src/main/java/hatelace/Main.java +++ b/app/src/main/java/hatelace/Main.java @@ -9,8 +9,8 @@ public class Main { Memory memory = new IntMemory(64); // 64 words of memory Computer computer = new Computer(memory); Program program = new Program(new Instruction[] { - new Add(1, 1, 0), // Store 1 + 1 in address 0 - new Mul(2, 2, 1), // Store 2 * 2 in address 1 + new Add(new IntWord(1), new IntWord(1), new Address(0)), // Store 1 + 1 in address 0 + new Mul(new IntWord(2), new IntWord(2), new Address(1)), // Store 2 * 2 in address 1 new Copy(new IntWord(3), new Address(2)) // Store 3 in address 2 }); computer.load(program); diff --git a/app/src/main/java/hatelace/Memory.java b/app/src/main/java/hatelace/Memory.java index b4aaa41..541a0d8 100644 --- a/app/src/main/java/hatelace/Memory.java +++ b/app/src/main/java/hatelace/Memory.java @@ -3,7 +3,7 @@ package hatelace; public abstract class Memory { public abstract int read(int address); public abstract int size(); - public abstract void write(int address, Word data); + public abstract void write(Address address, Word data); /** Dump as IHEX-like format (see https://en.wikipedia.org/wiki/Intel_HEX) */ public abstract void dump();