diff --git a/examples/bare0.rs b/examples/bare0.rs index 2f36a34e93bf72dab0ef57bb53aa3ec25563ca8d..d7f0c54ae250e8c113672bce79960560da9124f1 100644 --- a/examples/bare0.rs +++ b/examples/bare0.rs @@ -28,18 +28,37 @@ static mut Y: u32 = 0; #[entry] fn main() -> ! { // local mutabale variable (changed in safe code) - let mut x = unsafe { X }; + let mut x = read_x(); loop { - x.wrapping_add(1); // <- place breakpoint here (3) - unsafe { - X.wrapping_add(1); - Y = X; - assert!(x == X && X == Y +1 ); - } + x = x.wrapping_add(1); // <- place breakpoint here (3) + write_x(read_x().wrapping_add(1)); + write_y(read_x()); + assert!(x == read_x() && read_x() == read_y() ); } } +fn read_x() -> u32 { + return unsafe { X }; +} + +fn read_y() -> u32 { + return unsafe { Y }; +} + +fn write_x(x: u32) { + unsafe { + X = x; + } +} + +fn write_y(y: u32) { + unsafe { + Y = y + } + +} + // 0. Compile/build the example in debug (dev) mode. // // > cargo build --example bare0 @@ -75,10 +94,10 @@ fn main() -> ! { // // Change (both) += opertions to use wrapping_add // load and run the progam, what happens -// ** x value stays at u32 max 4294967295** +// ** x value wraps around u32 max 4294967295 and get value 0** // // Now continue exectution, what happens -// ** X,Y and x = 4294967295 ** +// ** X,Y and x is incremented and wraps around max ** // // Commit your answers (bare0_3) //