diff --git a/examples/rtic_bare1.rs b/examples/rtic_bare1.rs index a173320ce2d47a965abd25e78a546cf12fadc0dd..6a48f5d5844635726dd653207d809b24a03a2401 100644 --- a/examples/rtic_bare1.rs +++ b/examples/rtic_bare1.rs @@ -20,9 +20,9 @@ const APP: () = { fn init(_cx: init::Context) { let mut x = core::u32::MAX - 1; loop { - // cortex_m::asm::bkpt(); - x += 1; - // cortex_m::asm::bkpt(); + cortex_m::asm::bkpt(); + x = x.wrapping_add(1); + cortex_m::asm::bkpt(); // prevent optimization by read-volatile (unsafe) unsafe { @@ -138,13 +138,13 @@ const APP: () = { // // Explain in your own words what this assembly line does. // -// ** your answer here ** +// load the value of the address sp + offset 0 to register address r0 // // In Cortex Registers (left) you can see the content of `r0` // // What value do you observe? // -// ** your answer here ** +// -2 (MAX-2) // // You can also get the register info from GDB directly. // @@ -162,7 +162,7 @@ const APP: () = { // // Explain in your own words what is happening here. // -// ** your answer here ** +// add to the register r0 the immidiate constant 1 // // We move to the next assembly instruction: // @@ -171,7 +171,7 @@ const APP: () = { // // What is the reported value for `r0` // -// ** your answer here ** +// -1 (MAX) (0xffffffff) // // So far so good. // @@ -202,7 +202,7 @@ const APP: () = { // // What does BCS do? // -// ** your answer here ** +// BCS.n branches if there was a carry bit from the last addition. (.n makes the instruction to be 16 bits) // // Now let's see what happens. // @@ -216,7 +216,7 @@ const APP: () = { // // Explain in your own words where we are heading. // -// ** your answer here ** +// We are heading toward a branch to the panic "function" // // To validate that your answer, let's let the program continue // @@ -232,7 +232,7 @@ const APP: () = { // Hint 3, the code is generated by the Rust compiler to produce the error message. // there is no "magic" here, just a compiler generating code... // -// ** your answer here ** +// it is to generate the error message. // // Commit your answer (bare1_4) // @@ -285,7 +285,7 @@ const APP: () = { // // Do you see any way this code may end up in a panic? // -// ** your answer here ** +// No since there is no branching when there is a carry. // // So clearly, the "semantics" (meaning) of the program has changed. // This is on purpose, Rust adopts "unchecked" (wrapping) additions (and subtractions) @@ -300,16 +300,32 @@ const APP: () = { // // Paste the generated assembly: // -// ** your answer here ** +// 0x08000e84 <+0>: push {r4, r6, r7, lr} +// 0x08000e86 <+2>: add r7, sp, #8 +// 0x08000e88 <+4>: sub sp, #16 +// 0x08000e8a <+6>: movw r0, #5808 ; 0x16b0 +// 0x08000e8e <+10>: mov r4, sp +// 0x08000e90 <+12>: movt r0, #2048 ; 0x800 +// 0x08000e94 <+16>: ldr r0, [r0, #0] +// 0x08000e96 <+18>: str r0, [sp, #0] +// 0x08000e98 <+20>: bl 0x8000fa6 <lib::__bkpt> +// => 0x08000e9c <+24>: ldr r0, [sp, #0] +// 0x08000e9e <+26>: adds r0, #1 +// 0x08000ea0 <+28>: str r0, [sp, #0] +// 0x08000ea2 <+30>: bl 0x8000fa6 <lib::__bkpt> +// 0x08000ea6 <+34>: mov r0, r4 +// 0x08000ea8 <+36>: bl 0x8000f46 <_ZN4core3ptr13read_volatile17hb977623ea709e27cE> +// 0x08000eac <+40>: b.n 0x8000e98 <rtic_bare1::init+20> // // Can this code generate a panic? // -// ** your answer here ** +// No, no branch to a panic "function" // // Is there now any reference to the panic handler? // If not, why is that the case? // -// ** your answer here ** +// There is no reference since there is no need for it as we have stated that +// wrapping is the intended outcome // // commit your answers (bare1_5) //