Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Assembly Code Problem?

Status
Not open for further replies.

PhillDubya

New Member
Hey guys,

New here, and a total newb at assembly code. I am a university elec. engineering student, and mostly have experience with C++.

However, I am trying to do a simple "loop and end" code with an MSP430 uC, using assembly.

Code:
 #include  "msp430x20x3.h"
;-------------------------------------------------------------------------------
            ORG     0F800h                  ; Program Reset
;-------------------------------------------------------------------------------
RESET       mov.w   #0280h,SP               ; Initialize stackpointer
StopWDT     mov.w   #WDTPW+WDTHOLD,&WDTCTL  ; Stop WDT
SetupP1     bis.b   #001h,&P1DIR            ; P1.0 output
                                            ;
                                            ;
                                            ;
// Function 1 ------------------------------------------------------------------                                          
Counter     mov.w   #20, R14                ; Set counter (R14) to 10 ON counts                       
                                            ;
Mainloop    xor.b   #001h,&P1OUT            ; Toggle P1.0
Wait        mov.w   #050000,R15             ; Delay to R15
L1          dec.w   R15                     ; Decrement R15
            jnz     L1                      ; Finished Time Delay?
            dec.w   R14                     ; Finished Mainloop?
            jnz     Mainloop                ;                                
                                            ;               
                                            ;
                                            ;
;-------------------------------------------------------------------------------
;           Interrupt Vectors
;-------------------------------------------------------------------------------
            ORG     0FFFEh                  ; MSP430 RESET Vector
            DW      RESET                   ;
            END     Mainloop                ;

With this code, I should be able to blink a light, with a delay of 500000, which is both my ON, and OFF time. There should be a total of ten times on, and subsequently, 10 counts off; however, the loop never ends... Am I ending the code with the wrong statement, e.g. "END Mainloop"?

Thanks in advance for your time!

Phill
 
Last edited:
I don't know that microcontroler. However, I think I know what is happening.

Your code runs through correctly, and flashes 10 times, but then what? The program will continue onto the line that follows jnz Mainloop
That isn't defined, so the processor could do anything.

However the are two likely things that it is likely to do. It might reset, which would start the whole lot off again. Or it might just understand the blank lines as No Operations, in which case it will run through all the memory executing NOPs until it gets back to the start again.

In either of these cases the flashing will never end.

What you want is a line that jumps to itself at the end.
 
I ended up needing to design the code where it is a repetitive loop anyway, and thus not needing the instruction after-all. I simply ended the code with an END instruction, and nothing else. However, when needed I will certainly look at a statement using the logic you suggested.

Thanks Diver300 for the information.

:)
 
Status
Not open for further replies.

Latest threads

Back
Top