diff --git a/examples/bare0.rs b/examples/bare0.rs index e2ea814165f34054a66890d896780d7d695a0a5d..dae25b59ab14769f44097786759aa6320356614c 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) //