Advertisement
Guest User

Untitled

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