Asm help needed

For some college work we have to use a BL2000 wildcat board with a Rabbit2000 microprocessor to turn on LED DS6 for 5 seconds then off for 5 seconds then repeat. I have managed to get it to turn on and off when debugging but the delay loop isn't repeating. Any help would be most greatful

It sounds like your problem is mainly in the flow control logic, which means people could help you even if they aren't very familiar with that assembly language. However, for those people to help you, they would need some indication of what the code actually means (comments, for example). I'm just saying this because there probably aren't a whole lot of people here who know that language, but there are potentially many people who could help you if your bug is indeed in the flow control.

First off, you are using a fixed delay loop to time the LED toggling. Now, I usually would recommend against busy-waiting, as fixed timing loops can be rather brittle. However, since this is embedded code, it is not so problematic. What is problematic is way the loop index is updated; if you look carefully at the code in this section, you should find the bug you are looking for.

As a side point, you use two separate, identical code sections to handle the two sets of timeouts, which, aside from taking up extra space on a rather memory-constrainted system, is simply bad design; this is particularly important in this case since it seems likely that the timing loops are the source of the problem you are having. I'm guessing that you professor hasn't covered subroutine calls yet, but fortunately, they are fairly easy to do on this processor using the CALL and RET instructions.

I also noticed that the code for setting and testing the LED status was also duplicated, and could easily be broken out into a subroutine as well; doing this not only saves memory, but makes debugging easier, since it isolates the different parts of the program and allows you to study them independently. Indeed, I probably would not have noticed the loop index problem mentioned above if I hadn't tried re-writing the code this way (see below). [EDIT: I was going to answer the problem outright, but I figured it would be better to give a hint and let you figure it out. The changes I've made to the code below should make it clearwhere the problem lies; fortunately, you only need to make two trivial changes to fix it.]

In fact, you probably should remove the assembly code from the main() function and put it in it's own function outright. Finally, you should be able to replace the JP (jump absolute) instructions with JR (jump relative) without any trouble, though it's not a big deal either way; similarly, the 'decrement word register and jump if not zero' can be done as a single DWJNZ instruction, though you may need to adjust the timing of the loop to account for the difference in clock cycles it uses.

Below is a modified version of your code following this recommendation (I've also changed the labels to improve readability, and added some debugging printouts):

Since I don't have access to the compiler and SBC in question, I have no way of knowing if this code is correct, but it should give you a starting point. I would recommend checking out the BIOS to see if there's a better alternative to the timing loop (you might want to look at the periodic interrupt and the timer in particular).