I have recently been provided this task in a module in which we are working with Arduinos. The previous tasks we had were in C however when it comes to this I have simply no idea what to do or even how to start in that case. We have also not been provided with any type of lectures or etc to cover this. Can anyone help or just get the ball rolling a little bit so I can understand it better? Thank you.
The first bit of code that I have to edit is below:
"delay_ms%=: nop ; code to replace nop \n"
"delay_100us%=: nop ; code to replace nop \n"
"delay_1us%=: nop ; code to replace nop \n"
" sbiw r30,1 ; decrement ms count (r31:r30)\n"
" brne delay_ms%= ; loop to delay_ms while > 0 \n"
" ret ; return from subroutine \n"
and then the rest of the code is this:
" blink%=: ; start of blink code \n"
//
// turn onboard LED on
//
" ldi r18,0x20 ; bit 5 (pin 13) = high \n"
" out 5,r18 ; output to port B \n"
//
// delay by value in millisecs variable
//
" lds r30,millisecs ; r30 = hi byte \n"
" lds r31,millisecs + 1 ; r31 = lo byte \n"
" call delay_ms%= ; call millisec delay sub \n"
//
// turn onboard LED off
//
" ldi r18,0x00 ; value for all LEDs off \n"
" out 5,r18 ; output to port B \n"
//
// delay by value in millisecs variable
//
" lds r30,millisecs ; r30 = hi byte \n"
" lds r31,millisecs + 1 ; r31 = lo byte \n"
" call delay_ms%= ; call millisec delay sub \n"
::: "r16", "r17", "r18", "r30", "r31"); // clobbered registers
//------------------------------------------------------------------------- -------
// calculate the execution time of the blink routine, and print details
long endtime = millis(); // make a note of the end time
float ms = endtime-starttime; // calculate the interval
float expected = 2 * millisecs; // expected delay is millisecs * 2 (2 delays in blink)
float overheads = 17; // overheads due to the timing
expected = expected + overheads;
float error_percent = 100.0*(ms-expected)/expected;
Serial.print("delay="); Serial.print(ms); Serial.print("ms ");
Serial.print("error: ");
if(error_percent>0)
Serial.print("+");
Serial.print(error_percent);Serial.println("%");
}
The instruction set is here: http://www.atmel.com/images/Atmel-0856-AVR-Instruction-Set-Manual.pdf