Can someone please tell me why this code would not compile (Assembly)?

jpanhalt

Joined Jan 18, 2008
11,087
I prefer to place the colon after labels and have them on a separate line.
A habit from the PDP and 8080 days I guess.
Also the colon helps in a search to distinguish the label from the call.
Max.
I agree on the separate line for labels vs. instructions. As for the colon, I find it distracting, particularly when on the same line as an instruction. Colons and semicolons look too much alike for me to use colons intentionally. I can't count the number of times I have unintentionally entered a colon only to have the Assembler find it for me. I am also happy to see the"movfw" instruction fall into disuse. Way too easy to confuse with"movwf."
 

MaxHeadRoom

Joined Jul 18, 2013
30,688
Well I find the different in highlight colour reduces or eliminates the confusion for me as to which it is.
Just makes it easier to find a routine itself in a search when a long program calls it numerous times.
But I have yet to confuse it with a semicolon?!
Max.
 

MrAl

Joined Jun 17, 2014
13,716
Hi,

How would you do a delay that was not too long.
We know long delays should not be used but should be mixed in with the code itself in one way or another but short delays usually are not that bad. Sometimes you cant use an interrupt either. Also, sometimes you can not allow an interrupt during a delay.
So i'd like to hear about your experiences in this area.

I've done some very unusually timed ASM code but it takes care to get the times right.
I've also called short delays from other long delay routines. For example if you need 100us a lot and 500us, you can make the 100us slightly shorter and call it 5 times to get 500us.
 

joeyd999

Joined Jun 6, 2011
6,331
Hi,

How would you do a delay that was not too long.
We know long delays should not be used but should be mixed in with the code itself in one way or another but short delays usually are not that bad. Sometimes you cant use an interrupt either. Also, sometimes you can not allow an interrupt during a delay.
So i'd like to hear about your experiences in this area.

I've done some very unusually timed ASM code but it takes care to get the times right.
I've also called short delays from other long delay routines. For example if you need 100us a lot and 500us, you can make the 100us slightly shorter and call it 5 times to get 500us.
I would be happy to have this conversation. But this is the wrong thread. Start a thread and I'll participate.
 

Thread Starter

specs365

Joined Mar 14, 2019
45
Thanks a lot everyone for the replies, really appreciate it, so found out that my main problem was the end was not at the bottom of the code (Thanks Max). Also, not sure if its the most efficient way to create a delay, but i will be looping the nop statements and using the decrement if not zero command the delay longer as the above delay only like 6 instruction cycles long.

Although that delay of about half a dozen machine cycles is not going to be very long in order to flash a LED!
And with one instruction ON time!
Max.
Also, not sure if its the most efficient way to create a delay, but I will be looping the nop statements and using the decrement if not zero command to make delay longer as the above delay is only like 6 instruction cycles long
 

Thread Starter

specs365

Joined Mar 14, 2019
45
Also can someone maybe break down what the actual difference between BRA and GOTO is? It really confuses me still.
 

JohnInTX

Joined Jun 26, 2012
4,787
Also can someone maybe break down what the actual difference between BRA and GOTO is? It really confuses me still.
They both cause the program to unconditionally jump to a new location and resume processing from there.

The practical difference between the two is that BRA can't jump as far as GOTO can.
BRA can jump ahead 1023 instructions or back 1024 instructions from wherever it is in the code. That's called relative addressing i.e. the target address is not directly specified in the instruction but is calculated relative to the current address.
GOTO can jump anywhere in program memory. The target address is fully specified in the instruction (direct addressing).

The other big difference is that GOTO takes 2 words of program memory and BRA takes only one. Thus, good programming practice dictates that BRA be used when possible to save program memory. One caution, however. While it may be tempting to use BRA everywhere, its limited reach can be problematic. Using BRA to jump to a location 980 words away for example, would work fine until you add enough code between the BRA and its target to break the 1023 word limit. Then you have to reorganize your code or change to GOTOs after the fact. A rule of thumb is to use BRA within functions, loops etc. where you know the code will be shorter and GOTO for everything else.

Good luck!
 

Thread Starter

specs365

Joined Mar 14, 2019
45
They both cause the program to unconditionally jump to a new location and resume processing from there.

The practical difference between the two is that BRA can't jump as far as GOTO can.
BRA can jump ahead 1023 instructions or back 1024 instructions from wherever it is in the code. That's called relative addressing i.e. the target address is not directly specified in the instruction but is calculated relative to the current address.
GOTO can jump anywhere in program memory. The target address is fully specified in the instruction (direct addressing).

The other big difference is that GOTO takes 2 words of program memory and BRA takes only one. Thus, good programming practice dictates that BRA be used when possible to save program memory. One caution, however. While it may be tempting to use BRA everywhere, its limited reach can be problematic. Using BRA to jump to a location 980 words away for example, would work fine until you add enough code between the BRA and its target to break the 1023 word limit. Then you have to reorganize your code or change to GOTOs after the fact. A rule of thumb is to use BRA within functions, loops etc. where you know the code will be shorter and GOTO for everything else.

Good luck!

Thanks!
 
Top