Part 16 - Hacking double

Let's review 0x06_double_MOD.c as follows.

#include <stdio.h>
#include "pico/stdlib.h"

int main() 
{
  stdio_init_all();

  while(1) 
  {
    double x = 40.55555555555555555555;

    printf("%.16f\n", x) 

    sleep_ms(1000);
  }

  return 0;
}

Let's fire up in our debugger.

radare2 -w arm -b 16 0x06_double.elf

Let's auto analyze.

aaaa

Let's seek to main.

s main

Let's go into visual mode by typing V and then p twice to get to a good debugger view.

Our microcontroller is a little endian architecture as we have discussed before therefore if we are going to change our 40.5555555560000000 to 1.0 we need to put that value in reverse byte order therefore...

0x3ff00000

Needs to be...

0x0000f03f

Therefore we need to change the value at the following.

wx 0x0000f03f @ 0x00000344

All we have to do now is exit and convert our .elf to .uf2!

./elf2uf2/elf2uf2 0x06_double.elf 0x06_double.uf2

Plug in the Pico and make sure you hold down BOOTSEL or use the setup I provided in the part 2.

cp 0x06_double.uf2 /Volumes/RPI-RP2

Let's screen it!

screen /dev/tty.usbmodem0000000000001

AHH yea!

1.0000002380000000
1.0000002380000000
1.0000002380000000
1.0000002380000000
1.0000002380000000
1.0000002380000000
1.0000002380000000
1.0000002380000000
1.0000002380000000
1.0000002380000000
1.0000002380000000
1.0000002380000000
1.0000002380000000
1.0000002380000000
1.0000002380000000

Now we should have a good understanding of the data types within C to look at some slightly larger concepts.

In our next lesson we will begin to discuss input.

results matching ""

    No results matching ""