From 20621e073562ee5d423b636fae8b6aa8e38275fa Mon Sep 17 00:00:00 2001 From: stefan Date: Wed, 24 May 2023 22:29:46 -0400 Subject: readme and cleanup --- vm/memory.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'vm/memory.go') diff --git a/vm/memory.go b/vm/memory.go index 0a9dd2c..a0c610a 100644 --- a/vm/memory.go +++ b/vm/memory.go @@ -26,14 +26,18 @@ func (m *Memory) sb(ost uint64, val byte) { (*m)[ost] = val } -// loads 256b word fron offset in memory -func (m *Memory) ld(ost uint64) []byte { - if ost + 32 > uint64(len(*m)) { +func (m *Memory) ld(ost uint64, n uint64) []byte { + if ost + n > uint64(len(*m)) { log.Fatal("trying to load out of memory") } - r := make([]byte, 32) - copy(r, (*m)[ost:ost+32]) + r := make([]byte, n) + copy(r, (*m)[ost:ost+n]) + return r +} + +func (m *Memory) lw(ost uint64) []byte { + r := m.ld(ost, 32) return r } -- cgit v1.2.3