Jump to content

Assembly $ symbol

- - - - -

  • Please log in to reply
1 reply to this topic

#1
darknoobie

darknoobie

    Newbie

  • Members
  • PipPip
  • 19 posts
Hello forum,

Ive been looking into getting back into the pic micro scene and have been a while since i have programmed some. I pulled up an old delay routine i used before. The $ symbol means the current address right? So if I have :

goto $+1
goto $+1
goto $+1

Since goto requires to cycles.. goto current address 1 time then .... continues for the next 2?
Total cycles used = 6


decfsz timer1, 1 ;Loaded with 0xff
goto $+2

Total number cycles = ?

kinda stuck on last one
If there are no stupid questions, then what kind of questions do stupid people ask? Do they get smart just in time to ask questions?
—Scott Adams

#2
dbug

dbug

    Programmer

  • Members
  • PipPipPipPip
  • 155 posts
As you say $ symbol represents the current address of the instruction containing it, but $+1 has nothing to do with cycles or time. It's simply a way to simplify assembly writing, avoiding having to define too many labels for trivial jumps.

In this case, goto $+1 means: jump to the instruction located at the current address + 1 (only simple arithmetic with addresses). This is the next instruction.

The code you posted is equivalent to this one:

Delay8:   goto Delay6

Delay6:   goto Delay4

Delay4:   goto Delay2

Delay2:
As you can see, unless you need to make calls to these addressess from other locations, it's simpler to write your code.

The total number of cycles needed to execute the 3 jumps are: 2 cycles per jump instruction * 3 jumps = 6 cycles.

I think the last fragment of code you postes is not correct. As it is, without anything else after it, it makes no sense. I think the correct code (for a delay loop) should be:

        decfsz timer1, 1  ; 1 cycle if timer1-1 != 0, 2 cycles if timer-1 == 0

        goto   $-1        ; 2 cycles
This way the loop repeats as many times as timer1 is initialized with. If we start with timer1 = 1, then the first execution takes 2 cycles (because timer1-1 is 0), and the next instruction is not executed (decfsz skips the next instruction if timer1-1 is 0). So it takes 2 cycles when timer1 = 1. If timer1 is greater than 1, then for each value > 1, it will take 1 cycle for decfsz, and 2 cycles for goto. This means 3 cycles * (timer1 - 1).

So the total number of cycles is: 3 * (timer1 - 1) + 2 = 3 * timer1 - 1




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users