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

bare0_5

parent 4bf86dcd
No related branches found
No related tags found
No related merge requests found
...@@ -33,17 +33,43 @@ const X_INIT: u32 = core::u32::MAX; ...@@ -33,17 +33,43 @@ const X_INIT: u32 = core::u32::MAX;
static mut X: u32 = X_INIT; static mut X: u32 = X_INIT;
static mut Y: u32 = 0; 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] #[entry]
fn main() -> ! { fn main() -> ! {
// local mutable variable (changed in safe code) // local mutable variable (changed in safe code)
let mut x = unsafe { X }; let mut x = read_X();
loop { loop {
x = x.wrapping_add(1); // <- place breakpoint here (3) x = x.wrapping_add(1); // <- place breakpoint here (3)
unsafe { write_X();
X = X.wrapping_add(1); write_Y();
Y = X;
}
} }
} }
...@@ -89,7 +115,7 @@ fn main() -> ! { ...@@ -89,7 +115,7 @@ fn main() -> ! {
// The program does not panic this time, and instead x wraps to 0, as it should. // The program does not panic this time, and instead x wraps to 0, as it should.
// //
// Now continue execution, what happens // 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) // Commit your answers (bare0_3)
// //
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment