#pragma GCC optimize ("Og")
#include "ArduinoTrace.h"
//volatile int8_t a=9,b=8,c; //prueba 1 c=3
//volatile int8_t a=10,b=9,c; //prueba 2 c=5
volatile int8_t a=7,b=8,c; //prueba 3 c=7
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("INICIO");
//------------- Proceso en alto nivel -------------------
// IF SIMPLE
// if(x==3) { goto then1; }
// else {goto else1; }
// then1: ... ; goto endif;
// else1: ...
// endif: {}
// Warnings*
// x <= y -> y >= x brge
// x > y -> y < x brlt
// IF COMPUESTO
// (AND) -> if (a>=2 && b>5)
// cond1:
// if(a >= 2) { goto cond2; }
// else {goto else1; }
// cond2:
// if(b>5) { goto then1; }
// else {goto else1; }
// ...
// (OR) -> if (a>=2 || b>5)
// cond1:
// if(a >= 2) { goto then1; }
// else {goto cond2; }
// ...
// WHILE
// if(n>0){ goto body1; }
// else { goto endw1; }
// body1:
// ...; n--;
// DO WHILE
// body1:
// ...; n--
// if(n>0){ goto body1; }
// else{ goto endw1; }
// FOR ( n -> cte )
// if(i<=n) { goto body1; }
// else { goto endfor1; }
// body1:
// ...; i++;
// * Usar DEC (--) e INC (++)
// IF ANIDADOS
// if (a>b){
// if(b<=8){c=3;}
// else{c=5;} }
// else{c=7;} (ORIGINAL)
// ---------------------------
/*
cond1:
if(a>b){ goto then1; }
else{ goto else1; }
then1:
if(b <= 8){ goto then2; }
else{ goto else2; }
then2:
c = 3; goto endif;
else2:
c = 5; goto endif;
else1: c = 7;
endif: (GOTO)
*/
// EJEMPLO ASM (IF Anidado)
cond1:
// if(a>b){ goto then1; }
// else{ goto else1; }
asm goto(
"lds r16,a \n"
"lds r17,b \n"
"cp r17,r16 \n"
"brlt %l[then1] \n"
"jmp %l[else1] \n"
:::: then1, else1
);
then1:
// if(b <= 8){ goto then2; }
// else{ goto else2; }
asm goto(
"lds r16,b \n"
"cpi r16,9 \n"
"brlt %l[then2] \n"
"jmp %l[else2] \n"
:::: then2, else2
);
then2:
//c = 3;
asm goto(
"ldi r16,3 \n"
"sts c,r16 \n"
"jmp %l[endif] \n"
:::: endif
);
else2:
//c = 5;
asm goto(
"ldi r16,5 \n"
"sts c,r16 \n"
"jmp %l[endif] \n"
:::: endif
);
else1:
asm volatile(
"ldi r16,7 \n"
"sts c,r16 \n"
);
endif:
//--------------------------------------------------------
DUMP(c);
}
void loop() {
}