From 35fdb1e0b0bf7107860100809c507c9fe0fb7e19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Autin?= Date: Fri, 24 Mar 2023 18:13:18 +0100 Subject: [PATCH] :memo: :recycle: Doc updates & Registers are now sized from consts --- src/simulator/register.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/simulator/register.rs b/src/simulator/register.rs index 4cbe50d..2f78d30 100644 --- a/src/simulator/register.rs +++ b/src/simulator/register.rs @@ -1,3 +1,5 @@ +use crate::simulator::machine::{NUM_FP_REGS, NUM_INT_REGS}; + use std::ops::{Add, Sub}; pub trait RegisterNum: Add + Sub + PartialEq + Copy {} @@ -20,7 +22,10 @@ impl Register { self.register[position as usize] } - /// Set value of register *position* to *value* + /// Set value of register *position* to *value* + /// + /// Checking against trying to set a new value to the 0th register + /// as its value is NOT supposed to change pub fn set_reg(&mut self, position: usize, value: U) { if position != 0 { self.register[position] = value; } } @@ -33,7 +38,7 @@ impl Register { /// i64 register constructor pub fn init() -> Register { Register { - register: [0i64; 32] + register: [0i64; NUM_INT_REGS] } } @@ -44,7 +49,7 @@ impl Register { /// f32 register constructor pub fn init() -> Register { Register { - register: [0f32; 32] + register: [0f32; NUM_FP_REGS] } }