Advertisement
Guest User

Untitled

a guest
Oct 31st, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 1.42 KB | None | 0 0
  1. start:
  2. ; r24 and r25 are input
  3.     ldi r20, 16         ; Amount of times to loop
  4. loop:
  5.     sbi PORTB, 2        ; 2cc           Set bit 2 in PORTB, after this instruction we start counting
  6.     nop             ; 1cc       1   Wait a cycle
  7.     lsr r24         ; 1cc       2       r24 >> 1, puts bit 0 into carry flag
  8.     ror r25         ; 1cc       3       r25 >> 1, puts carry flag into bit 7
  9.     ldi r18, 255        ; 1cc       4   r18 is going to be data[0] << 2, alternative instruction: ser r18
  10.     rol r18         ; 1cc       5       r18 is 11111111 if bit in data set, 11111110 otherwise
  11.     rol r18         ; 1cc       5       r18 << 1 + C, r18 is 11111111 if bit in data set, 11111101 otherwise
  12.     rol r18         ; 1cc       7       r18 << 1 + C, r18 is 11111111 if bit in data set, 11111011 otherwise
  13.     in  r19, PORTB      ; 1cc       8   Read the value of PORTB to "and" with
  14.     and r18, r19        ; 1cc       9   Do the "and"
  15.     out PORTB, r18      ; 1cc       10  Write the value back to PORTB <- here we are at the 625ns
  16.     ldi r18, 2          ; 1cc       11  Use a small loop to wait a few cycles
  17. wait:
  18.     dec r18         ; 1cc       12
  19.     brne    wait            ; 2cc/1cc   16  Delay = (1 + 2) * 2 - 1 -> 11 + 5 = 16
  20.     nop             ; 1cc       17  Delay again 2 cycles
  21.     nop             ; 1cc       18
  22.     cbi PORTB, 2        ; 2cc       20  Clear the bit in PORTB again <- here we are at the 1250ns
  23.     nop             ; 1cc       21  Wait 2 cycles
  24.     nop             ; 1cc       22
  25.     dec r16         ; 1cc       23  Loop 16 times
  26.     brne    loop            ; 2cc/1cc   25/24   Jump if not zero yet (+2 cycles from the sbi PORTB, 25+2 makes 27)
  27.     nop             ; 1cc       25  Wait 3 cycles for the last one
  28.     nop             ; 1cc       26
  29.     nop             ; 1cc       27
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement