diff --git a/examples/bare0.rs b/examples/bare0.rs index b64f8e5a71e073ee63f2abccf8e0624376db4d6e..e2ea814165f34054a66890d896780d7d695a0a5d 100644 --- a/examples/bare0.rs +++ b/examples/bare0.rs @@ -26,8 +26,8 @@ extern crate panic_semihosting; use cortex_m_rt::entry; // a constant (cannot be changed at run-time) -const X_INIT: u32 = 10; -//const X_INIT: u32 = core::u32::MAX; +//const X_INIT: u32 = 10; +const X_INIT: u32 = core::u32::MAX; // global mutable variables (changed using unsafe code) static mut X: u32 = X_INIT; @@ -39,11 +39,10 @@ fn main() -> ! { let mut x = unsafe { X }; loop { - x += 1; // <- place breakpoint here (3) + x = x.wrapping_add(1); // <- place breakpoint here (3) unsafe { - X += 1; - Y = X; - assert!(x == X && X == Y); + X = X.wrapping_add(1); + Y = X; } } } @@ -79,7 +78,7 @@ fn main() -> ! { // What happens when `x` wraps // (Hint, look under OUTPUT/Adopter Output to see the `openocd` output.) // -// ** your answer here ** +// The programs starts to panic. // // Commit your answers (bare0_2) // @@ -87,10 +86,10 @@ fn main() -> ! { // // Change (both) += operations to use wrapping_add // load and run the program, what happens -// ** your answer here ** +// The program does not panic this time, and instead x wraps to 0, as it should. // // Now continue execution, what happens -// ** your answer here ** +// The program goes to the breakpoint every time we press continue, and 1 is added to x, every time. // // Commit your answers (bare0_3) // @@ -99,7 +98,7 @@ fn main() -> ! { // // 4. Change the assertion to `assert!(x == X && X == Y + 1)`, what happens? // -// ** place your answer here ** +// The programs starts to panic. // // Commit your answers (bare0_4) //