From 62f33d50540fab9a42adbe8f53c0441b125e1068 Mon Sep 17 00:00:00 2001 From: Atreya Bain Date: Tue, 5 Mar 2024 20:11:17 +0530 Subject: [PATCH] [cpu] Bugfixes Add to register should be a wrapped add BCD should be hundreds first --- src/device/device.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/device/device.rs b/src/device/device.rs index f7eee84..3707207 100644 --- a/src/device/device.rs +++ b/src/device/device.rs @@ -99,7 +99,7 @@ impl Device { self.registers.v[reg_location] = value; } Instruction::AddValueToRegister(reg_location, value) => { - self.registers.v[reg_location] += value; + self.registers.v[reg_location] = self.registers.v[reg_location].wrapping_add( value); } Instruction::SetIndex(value) => { self.registers.i = value; @@ -252,7 +252,7 @@ impl Device { binary_value_to_decode_temp /= 10; // If this fails, something has gone truly wrong assert_eq!(0, binary_value_to_decode_temp); - let val = [unit_digit, tens_digit, hundreds_digit]; + let val = [hundreds_digit, tens_digit, unit_digit]; let index = self.registers.i as usize; self.memory[index..(index + 3)].copy_from_slice(&val); }