PDA

View Full Version : Null statement (NOP or CONTINUE)



RussMartin
- 4th February 2009, 17:59
I have occasional need for a null statement, one which effectively does nothing. In assembly, this would be NOP; back in the good (bad?) old days of FORTRAN, it would be CONTINUE.

I've been defining a dummy byte variable (cleverly called DUMMY) and just using

DUMMY=0

Is there a better solution? What, in terms of code space and/or execution time, is best?

mister_e
- 4th February 2009, 18:40
Well, it really depend on how the above is processed by the compiler, and on which architecture as well

Usually clearing a Variable would imply a simple asm line
CLRF _DUMMY

Or
MOVLW 0
MOVWF _DUMMY

BUT this assume you're on the right BANK... if BANK sensitive at all. Even though, there's several way to switch between BANK... and this still bring the idea of how they do it in background.

To me, NOP or GOTO $+1 (or GOTO $+2 for 18) are the best way, as they use a fixed instruction cycle and BANK insensitive AND you don't need any DUMMY variable AND you don't need to know the background process. But it's me ;)

Archangel
- 4th February 2009, 19:08
To me, NOP or GOTO $+1 (or GOTO $+2 for 18) are the best way, as they use a fixed instruction cycle and BANK insensitive AND you don't need any DUMMY variable AND you don't need to know the background process. But it's me ;)
Hi Steve,
A belated Happy New Year ! I know what a nop is and does, could you explain what GOTO $+1 does ? Thank You, JS

mister_e
- 4th February 2009, 19:11
GOTO $+1 just mean, jump one instruction next to the current one, $ being the current position/instruction.

This usually eat 2 instruction cycle, while NOP eat 1 instruction cycle

For 18F, you must use GOTO $+2

Archangel
- 4th February 2009, 19:20
GOTO $+1 just mean, jump one instruction next to the current one, $ being the current position/instruction.

This usually eat 2 instruction cycle, while NOP eat 1 instruction cycle

For 18F, you must use GOTO $+2Thank You !That's interesting, It burns through 2 instructions to go where it was going anyway, so if I get this correctly . . . would it jump to any location by changing the 1 to another number, like a GOTO LABEL without the label ?

Acetronics2
- 4th February 2009, 19:21
Hi Russ and Steve

for 16F ...



While 0
Wend

next command


gives in asm




L0001 GOTO L0002
GOTO L0001
L0002 .... Next Command



Should do the trick, no ???

Alain

mister_e
- 4th February 2009, 19:30
Alain,
well yes or no, but it's just longer to type ;)

Joe
Yes, I think you got it right.

To make it easier...

GOTO $+1

is the same as
NOP
NOP

well instruction-cycle wise (can I say that :D ??? )

RussMartin
- 4th February 2009, 20:51
I should probably have explained:

I don't leave the dummy statement in a finished program. Usually, it occupies a space where another function, or a GOTO, or a GOSUB will be placed.

I really like Alain's

WHILE 0
WEND

. . . which I assume I could render on one line as WHILE 0 : WEND, and then go from there.

But the GOTO $+1 intrigues me, too. Will that work as a PBP command?

mister_e
- 4th February 2009, 21:28
yeah it will work, but you need to use the @ sign before (how it's called anyways, here we use to call it commercial A, then AT... )as it's an ASM statement ;)

@ GOTO $+1