Go Down

Topic: Assembly Language with the Portenta (Read 64 times) previous topic - next topic

jerteach

I have been making some videos using TRACE32 the debugger that is free for the Portenta which shows the Assembly Language for each of your C/C++ commands, so I thought I should try to do some Assembly using the asm(); function. Well it took a full day of searching for Arduino assembly code that did not work.

Here is what I finally got working. It basically just does what 
myLoop++; would do.

Using TRACE32 you can watch as the registers change.
Video should be available soon here


```
  //myLoop += 1;   // was set with  int myLoop = 0;
  // Lets mess with myLoop using assembly Language

   // Note: #0x1 for HEX, #1 for numbers, #0b00000001 for bits
   
   asm("ldr r0, =(myLoop) ");       // load myLoop address into R0
   asm("ldr r1, [r0]      ");                // Load value of myLoop into r1
   asm("add r2, r1,  #0x1 ");          // Add r1 and "1" into r2,  
   asm("str r2, [r0]      ");               // Store value in r2 back to myLoop
   
   Serial.println("Loop #: "+ String(myLoop));

```

Go Up