Download presentation
Presentation is loading. Please wait.
Published byMelvyn Owen Modified over 9 years ago
1
Speed Not affected by compiler optimization
2
r0 r18-r25 r25-r27 (X) r30-r31 (Z) r1 (must be cleared before returning)
3
Arguments allocated left to right (r25 to r18) Even register aligned
4
ArgumentRegisters 8-bitr24 16-bitr25:r24 32-bitr25:r24:r23:r22 64-bitr25:r24:r23:r22:r21:r20:r19:r18
5
Data lengthregisters 8-bitr24 16-bitr25:r24 32-bitr25:r24:r23:r22 64-bitr25-r18 Return sizeRegisters 8-bitr24 16-bitr25:r24 32-bitr25:r24:r23:r22 64-bitr25:r24:r23:r22:r21:r20:r19:r18
6
#include.text.global subit subit: sub r22, r20 ; subtract b (r20) from ul (r25-r22) sbc r23, r1 ;.. NOTE: gcc makes sure r1 is always 0 sbc r24, r1 ;.. sbc r25, r1 ;.. ret.end uint32_t subit(uint32_t ul, uint8_t b) { return(ul-b); }
7
#include ; defines the # of cpu cycles of overhead ; (includes the ldi r16,byte0; ldi r17,byte1; ldi r18, byte2, ; ldi r19, byte3, and the call _delay_cycles) OVERHEAD = 24 ; some register aliases cycles0 = 22 cycles1 = 23 cycles2 = 24 cycles3 = 25 temp = 19.text.global delay_cycles delay_cycles: ; ; subtract the overhead subi cycles0,OVERHEAD ; subtract the overhead sbc cycles1,r1 ;.. sbc cycles2,r1 ;.. sbc cycles3,r1 ;.. brcs dcx ; return if req’d delay too short ; ; delay the lsb mov r30,cycles0 ; Z = jtable offset to delay 0-7 cycles com r30 ;.. andi r30,7 ;.. clr r31 ;.. subi r30,lo8 (-(gs(jtable))) ; add the table offset sbci r31,hi8 (-(gs(jtable))) ;.. ijmp ; vector into table for partial delay jtable: nop nop nop nop nop nop nop ; ; delay the remaining delay loop: subi cycles0,8 ; decrement the count (8 cycles per loop) sbc cycles1,r1 ;.. sbc cycles2,r1 ;.. sbc cycles3,r1 ;.. brcs dcx ; exit if done nop ;.. add delay to make 8 cycles per loop rjmp loop ;.. dcx: ret.end void delay_cycles(uint32_t cpucycles);
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.