Created
November 22, 2011 01:16
-
-
Save RickKimball/1384579 to your computer and use it in GitHub Desktop.
MSP430 - delay_cycles() function with one cycle granularity written for msp430-as
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;-------------------------------------------------------------------------------- | |
; gcc port of this code: http://www.43oh.com/forum/viewtopic.php?p=7273#p7265 | |
;-------------------------------------------------------------------------------- | |
#include <msp430.h> | |
#define PC r0 /* gcc doesn't know about PC,SP,SR,CG1,CG2 */ | |
#define ARG1 R15 /*C function arguments are passed in R15-R12 */ | |
.file "delay.S" | |
.text | |
.global delay_cycles | |
.p2align 1,0 ; align on a word boundary | |
.type delay_cycles,@function | |
delay_cycles: | |
sub #20, ARG1 ; Adjust for loop overhead | |
L1: | |
sub #4, ARG1 ; Subtract four w/ four cycles per iteration | |
nop ; | |
jc L1 ; | |
inv ARG1 ; Negate the remainder | |
rla ARG1 ; Multiply by two | |
add ARG1, PC ; One cycle granularity computed jump | |
nop ; | |
nop ; | |
nop ; | |
ret ; Return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment