void setup() {
// put your setup code here, to run once:
volatile byte a,b,c;
Serial.begin(9600);
Serial.println("Enviar dato serial para variable local b:");
while(Serial.available()==0){}
delay(50);
//pasar los bytes recibidos a un entero
b=Serial.parseInt(SKIP_NONE,'\n');
Serial.println("Enviar dato serial para variable local c:");
while(Serial.available()==0){}
delay(50);
//pasar los bytes recibidos a un entero
c=Serial.parseInt(SKIP_NONE,'\n');
//a en Y+3, b en Y+2, c en Y+1
//-------------pasar a assembly-----------
//fooA(a,b,c);
//c=c+a;
asm(
"ldd r22,Y+2 \n"
"ldd r23,Y+1 \n"
"movw r24,r28 \n"
"adiw r24,3 \n"
"call fooA \n" //llamado funcion
"ldd r24, Y+1 \n" //r24 <-- c
"ldd r25, Y+3 \n" //r25 <-- a
"add r24, r25 \n" //r24 <-- c + a
"std Y+1, r24 \n" //c <-- c + a
);
//-----------------------------------------
Serial.print("a = ");
Serial.println(a);
Serial.print("b = ");
Serial.println(b);
Serial.print("c = ");
Serial.println(c);
}
void loop() {
// put your main code here, to run repeatedly:
}
//-------------pasar a assembly----------------------
//byte fooA(volatile byte &q,volatile byte s, volatile byte t)
//{
//if(s<=t)
//{
//t=s+t;
//}
//else
//{
//t=s-t;
//}
//q=t;
//}
//----------------------------------------------------
asm("fooA: ");
asm(
"push r28 \n" //salvar Y del caller
"push r29 \n" //..................
"push r0 \n" //....................
"push r0 \n" //...................
"push r0 \n" //.................
"push r0 \n" //.................
"in r28, 0x3d \n" // Y <-- SP
"in r29, 0x3e \n" //.................
"std Y+4, r23 \n" //t <-- c
"std Y+3, r22 \n" //s <-- b
"std Y+1, r24 \n" //Y+1
"std Y+2, r25 \n" //Y+2
"ldd r22, Y+3 \n" //r22 <-- s
"ldd r23, Y+4 \n" //r23 <-- t
"cp r23, r22 \n" //s - t
"brlo Q10 \n" //brlo a Q10(else) si s >t
"ldd r22, Y+3 \n" //r22 <-- s
"ldd r23, Y+4 \n" //r23 <-- t
"add r23 , r22 \n" //r23 <-- s + t
"std Y+4, r23 \n" //t <-- s + t
"rjmp Q20 \n" //saltar el else
"Q10: \n"
"ldd r22, Y+3 \n" //r22 <-- s
"ldd r23, Y+4 \n" //r23 <-- t
"sub r22, r23 \n" //r22 <-- s -t
"std Y+4, r22 \n" //t <-- s - t
"Q20: \n"
"ldd r24,Y+1 \n" //r24 <-- low byte a
"ldd r25,Y+2 \n" //r25 <-- high byte a
"movw r30,r24 \n" //Z <-- a
"ldd r18, Y+4 \n" //r18 <-- t
"st Z, r18 \n" //a <-- t
"pop r0 \n" //se sacan los bytes de a
"pop r0 \n" //.......................
"pop r0 \n" //se saca s
"pop r0 \n" //se saca t
"pop r29 \n" //restauramos Y del caller
"pop r28 \n" //......................
"ret \n" //PC <-- direccion de retorno al caller
);
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5