0

Question: 3. Write an assembly code to light up alternate LEDs continuously starting with LED1. Use the given Delay routine.

LED1  LED2  LED3
ON     OFF   OFF
Delay
OFF     ON    OFF
Delay
OFF    OFF   ON
Delay
ON     OFF   OFF

…

My Assembly Code:

Main:
    LDI R16,0x80;
    OUT DDRD,R16;
    LDI R16,0x28;
    OUT DDRB,R16;

Start:
  
SBI PORTD,7;
CBI PORTB,3;
CBI PORTB,5;
CALL Delay
CBI PORTD,7;
SBI PORTB,3;
CBI PORTB,5;
CALL Delay
CBI PORTD,7;
CBI PORTB,3;
SBI PORTB,5;
CALL Delay
RJMP Start
Delay:
LDI R19,0;
LDI R20,0xFF;
Loop:
LDI R21,0xFF;
Loop1;
DEC R21;
CPSE R21,R19;
RJMP Loop1;
DEC R20;
CPSE R20,R19;
RJMP Loop
RET;
3
  • 3
    I’m voting to close this question because We are not doing homework here Oct 12 at 10:03
  • then what are you doing?
    – Maya
    Oct 12 at 10:35
  • @Maya Hello, for homework questions it is important that you show what you have tried so far and where you are getting stuck. However, the homework question does not say anything about translating this assembly to C, right? Please also note that in cases where assembly is written by hand rather than having been translated from C source, translating the assembly directly to semantically-equivalent C code may be quite difficult or in some cases infeasible.
    – julian
    Oct 12 at 23:57