Hey all I am fairly new with the MSP430 and I have begun using it to do very simple projects and I am trying to keep track of how many cycles I use within my program, and I have a two simple questions that I cannot find the answer for.

How many cycles does it take to run the 'ret' or 'reti' from my program? How many cycles does it take to assign a variable in MSP430 or to call the variable as seen in my "mov.w #COUNT,r13" as seen below? Here is the part of the code that I am using:

COUNT       .equ    <number>                ; <-- Does this take any cycles?    

callLoop:   call    #myDelay                ; 2 cycles
            sub.w   #1,r12                  ; 1 cycles
              jne   callLoop                ; 2 cycles
            jmp     RESET                   ; 2 cycles

myDelay:    mov.w   #COUNT,r13              ; 1  <-- Is it only one cycle to run the mov.w?

delayloop:  sub.w   #1,r13                  ; 1 cycles
              jne   delayloop               ; 2 cycles
            ret                             ; ???  No idea what this would be.

r12 has already been assigned a value earlier. Let me know if you need anything else from me.

  • \$\begingroup\$ Hrm. I was thinking about looking into MSP430, but after a few minutes of researching the answer for this question, I think I'll hold off. \$\endgroup\$ – Ignacio Vazquez-Abrams Oct 8 '13 at 4:20
  • \$\begingroup\$ lol, I feel like there's nowhere for me to find the basic information that I need. Anything that exists usually assumes that I already know what I'm doing, a pretty hefty assumption. \$\endgroup\$ – Mitch Oct 8 '13 at 4:26
  • \$\begingroup\$ Isn't Return simply a jump? But to a memory address held on the stack? \$\endgroup\$ – Passerby Oct 8 '13 at 4:34
  • \$\begingroup\$ The answer is actually somewhat convoluted. ret is actually mov.w @sp+,pc under the hood. \$\endgroup\$ – Ignacio Vazquez-Abrams Oct 8 '13 at 4:36
  • \$\begingroup\$ So if its mov.w @sp+,pc then that means it is going to be 3 cycles because it is indexed and auto-increment from what I understand. Excellent, where did you find that answer Ignacio? \$\endgroup\$ – Mitch Oct 8 '13 at 4:43

According to this article, ret is actually mov.w @sp+,pc, so it only takes the cycles required for indirection, post-increment and assignment to the program counter.

.equ is an assembler directive similar to #define in C and generates no instructions; the mov.w #,r uses a constant substituted by the assembler and therefore incurs no additional cycles.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.