Skip to content

Instantly share code, notes, and snippets.

@RickKimball
Created November 22, 2011 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RickKimball/1384579 to your computer and use it in GitHub Desktop.
Save RickKimball/1384579 to your computer and use it in GitHub Desktop.
MSP430 - delay_cycles() function with one cycle granularity written for msp430-as
;--------------------------------------------------------------------------------
; 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