From e85ca7d8602b5c26fa3302e9fe6dc0165d6db976 Mon Sep 17 00:00:00 2001
From: Hammarkvast <tomham-3@student.ltu.se>
Date: Thu, 20 Feb 2020 14:00:56 +0100
Subject: [PATCH] bare0_5

---
 examples/bare0.rs | 38 ++++++++++++++++++++++++++++++++------
 1 file changed, 32 insertions(+), 6 deletions(-)

diff --git a/examples/bare0.rs b/examples/bare0.rs
index e2ea814..dae25b5 100644
--- a/examples/bare0.rs
+++ b/examples/bare0.rs
@@ -33,17 +33,43 @@ const X_INIT: u32 = core::u32::MAX;
 static mut X: u32 = X_INIT;
 static mut Y: u32 = 0;
 
+fn read_X() -> u32{
+    unsafe{
+        return X;
+    }
+}
+
+
+fn read_Y() -> u32 {
+    unsafe{
+        return Y;
+    }
+}
+
+
+fn write_X() -> () {
+    unsafe{
+        X = X.wrapping_add(1);
+    }
+}
+
+fn write_Y() -> () {
+    unsafe{
+        Y = X;
+    }
+}
+
+
 #[entry]
 fn main() -> ! {
     // local mutable variable (changed in safe code)
-    let mut x = unsafe { X };
+    let mut x = read_X();
 
     loop {
        x = x.wrapping_add(1); // <- place breakpoint here (3)
-        unsafe {
-           X = X.wrapping_add(1);
-           Y = X;
-        }
+       write_X();
+       write_Y();
+        
     }
 }
 
@@ -89,7 +115,7 @@ fn main() -> ! {
 //    The program does not panic this time, and instead x wraps to 0, as it should.
 //
 //    Now continue execution, what happens
-//    The program goes to the breakpoint every time we press continue, and 1 is added to x, every time.
+//    The program goes to the breakpoint every time we press continue, and 1 is added to x, every iteration.
 //
 //    Commit your answers (bare0_3)
 //
-- 
GitLab