#pragma GCC optimize ("Og")
#include "ArduinoTrace.h"
volatile int8_t a=0,b=1,c=8; //prueba1
//volatile int8_t a=0,b=1,c=7; //prueba2
//volatile int8_t a=0,b=4,c=8; //prueba3
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
//-------------- PROCESO ------------------------------------
// do
// {
// a=a+b;
// b++;
// }
// while (c>7 && b<=3);
body1:
// {
// a=a+b;
// b++;
// }
asm volatile
(
"lds r16, a \n" //r16 <-- (a)
"lds r17, b \n" // r17 <-- (b)
"add r16, r17 \n" // r16 <-- (a)+(b)
"sts a, r16 \n" // a <-- (a)+(b)
"inc r17 \n" // r17 <-- (b)+1
"sts b, r17" // b <-- (b)+1
);
// while (c>7 && b<=3)
// {
// if (c>7 && b<=3)
// {
// goto body1;
// }
// }
cond1:
// if (c>7)
// {
// goto cond2;
// }
// else
// {
// goto end1;
// }
asm goto
(
"lds r16, c \n" // r16 <-- (c)
"cpi r16, 8 \n" // comparar (c) y 8
"brge %l[cond2] \n" // si c>=8 <--> c>7: goto cond2
"jmp %l[end1]" // sino: goto end1
::::cond2, end1
);
cond2:
// if (b<=3)
// {
// goto body1;
// }
// else
// {
// goto end1;
// }
asm goto
(
"lds r16, b \n" // r16 <-- (b)
"cpi r16, 4 \n" // comparar (c) y 4
"brlt %l[body1] \n " // si b<4 <--> b<=3: goto body1
"jmp %l[end1]" // sino: goto end1
::::body1, end1
);
end1:
//------------------------------------------------------------
DUMP(a);
}
void loop() {
// put your main code here, to run repeatedly:
}