ESE101: Assembly Language Playground Followup

Last time I ended with a small challenge:

Figure out how to put a loop around the instructions you added so that the light keeps blinking on and off instead of ending up in the __TI_ISR_TRAP code.

The solution is adding two lines to the code, shown in bold:

; Set GPIO P1.0 to be an output

MainLoop: ; *ADDED THIS LINE*, it must start in the first column,
 ; at the far left side of the window.

; Set output on GPIO P1.0 to high voltage

; Set output on GPIO P1.0 to low voltage

; And repeat.


The first new line, “MainLoop:”, is called a label. A label is a symbol that marks a spot in a program, like a bookmark. Code Composer Studio requires that labels start in the first column.

I can't figure out how to get the "MainLoop:" line to be indented less than the other lines in Squarespace (the platform this blog runs on), so be sure your "MainLoop:" line starts at the far left.

The second new line, “JMP MainLoop,” is a JMP instruction which always jumps to the label MainLoop. (We talked about this earlier, remember?)

This is a classic infinite loop. The code between the MainLoop label and the JMP MainLoop instruction run forever, infinitely. The code turns the LED on and off until you turn the power off. Because there is no delay between the LED on and off instructions the LED will toggle on and off faster than you can see.

There are many ways to add a delay, ranging from simple (having the processor count up to a large number to waste time) to more complex (having the processor go to sleep and wake up from a timer interrupt). Can you figure out a way to implement the simple delay? If you need ideas, go back and look at the blinky code.

I’ll explain a simple way to add a delay next week.