bal_gennady

blinking_for_asm.s

Oct 2nd, 2025
1,168
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;---------------
  2. ; Assembly Code
  3. ;---------------
  4. #define __SFR_OFFSET 0x00
  5. #include "avr/io.h"
  6. ;------------------------
  7. .global start
  8. .global led
  9. ;------------------------
  10. start:
  11.     SBI   DDRB, 4             ;set PB4 (D12) as o/p
  12.     RET                       ;return to setup() function
  13. ;---------------------------------------------------------------------------
  14. led:
  15.     CPI   R24, 0x00           ;value in R24 passed by caller compared with 0
  16.     BREQ  ledOFF              ;jump (branch) if equal to subroutine ledOFF
  17.     SBI   PORTB, 4            ;set D12 to high
  18.     RCALL myDelay
  19.     RET                       ;return to loop() function
  20. ;---------------------------------------------------------------------------
  21. ledOFF:
  22.     CBI   PORTB, 4            ;set D12 to low
  23.     RCALL myDelay
  24.     RET                       ;return to loop() function
  25. ;---------------------------------------------------------------------------
  26. .equ  delayVal, 10000         ;initial count value for inner loop
  27. ;---------------------------------------------------------------------------
  28. myDelay:
  29.     LDI   R20, 100            ;initial count value for outer loop
  30. outerLoop:
  31.     LDI   R30, lo8(delayVal)  ;low byte of delayVal in R30
  32.     LDI   R31, hi8(delayVal)  ;high byte of delayVal in R31
  33. innerLoop:
  34.     SBIW  R30, 1              ;subtract 1 from 16-bit value in R31, R30
  35.     BRNE  innerLoop           ;jump if countVal not equal to 0
  36.     ;--------------
  37.     SUBI  R20, 1              ;subtract 1 from R20
  38.     BRNE  outerLoop           ;jump if R20 not equal to 0
  39.     RET
  40. ;---------------------------------------------------------------------------
Tags: Arduino asm
Advertisement
Comments
Add Comment
Please, Sign In to add comment