I'm working with arduino board. I'm coding in C but I want to use inline assembly.i have this code:
volatile int input1[20]={1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,4};
volatile int input2[20]={1,2,8,9,6,2,0,3,4,5,6,7,0,0,0,2,2,3,3,0};
volatile int temp[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
volatile int output[40]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
// // put your main code here, to run repeatedly:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
asm(
"statrt:;"
"ldi YL, low(input1[0]) ; " //load address of Data
"ldi YH, high(input1[0]) ; "
"ldi ZL, low(input2[0]) ; " //load address of Data
"ldi ZH, high(input2[0]) ;"
"CompareLoop:;"
"lpm r0 , Z+;"
"lpm r1 , Y+;"
"cp r1,r0;"
"brlt Change;"
"cpi Z,20;"
"breq SubLoop;"
"brne CompareLoop;"
"Change:"
"lds XL, low(temp[0]) ;" //load address of Data
"lds XH, high(temp[0]) ;"
"MoveToTempLoop:"
"lpm r3,Z+;"
"st temp+,r3;"
"cpi Z,20;"
"brne MoveToTempLoop;"
"MoveToInput1Loop:"
"lpm r3,Y+;"
"st Z+,r3;"
"cpi Z,20;"
"brne MoveToInput1Loop;"
"MoveToInput2Loop:"
"lpm r3,temp+;"
"st Y+,r3;"
"cpi Y,20;"
"brne MoveToInput2Loop;"
"statrt:;"
"add r3,r3;"
"lds XL, low(output[39]) ;" //load address of Data
"lds XH, high(output[39]) ;"
"lds YL, low(input1[19]) ;" //load address of Data
"lds YH, high(input1[19]) ;"
"lds ZL, low(input2[19]) ;" //load address of Data
"lds ZH, high(input2[19]) ;"
"SubLoop:"
"clr r2;"
"lpm r0 , Z-;"
"lpm r1 , Y-;"
"cp r1,r0;" //check kon moghe r1-r0 r1 koochiktar nabashe
"brge Label;"
"lpm r2,Z;"
"subi r2,1;"
"add r1,10;"
"st Z,r2;"
"Label:"
"sub r1,r0;"
"st X-,r1;"
"cpi ZL, -1 ;" //if i >-1 then
"brne SubLoop ;" // do it again
);
int i=0;
for ( i=0; i<40;i++){
Serial.println(output[i]);
}
}
actually I have 2 big number that have 20 digits and I want to have input1-input2. but the answer is 0 always :( it seams that it never executes the asm part ...
lds
loads from the former,lpm
from the latter. – Jester