Skip to content
Snippets Groups Projects
Commit 4bf86dcd authored by Hammarkvast's avatar Hammarkvast
Browse files

bare0 almost done

parent eaf154ae
Branches
No related tags found
No related merge requests found
......@@ -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)
//
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment