Shop OBEX P1 Docs P2 Docs Learn Events
basic question — Parallax Forums

basic question

BebopALotBebopALot Posts: 79
edited 2006-02-03 15:09 in General Discussion
Hey folks, I have some code generated for a delay. I am new to assembly - what is the JMP$+2 command doing? I assume this is some type of nested loop arrangement...Hex 93 = 147 (decimal) and 0b = 11 (decimal). How does this loop waste 18940 cycles? The product of the 2 is only 1617. Does it serve a multiplier function?

; Delay = 0.0037 seconds
; Clock frequency = 5.12 MHz

; Actual delay = 0.0037 seconds = 18944 cycles
; Error = 1.92038577232e-014 %


;18940 cycles
mov w, #$93
mov Long_Delay1, w
mov w, #$0B
mov Long_Delay2, w
Delay_A:
decsz Long_Delay1
jmp $+2
decsz Long_Delay2
jmp Delay_A

;4 cycles
jmp $+1
nop

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-02-03 13:59
    In SX assembly $ is an alias for the Program Counter, so JMP $+2 is "jump to current Program Counter + 2", since decsz is single instruction, and the PC is pointing to the jmp $+2 instruction, it jumps to jmp Delay_A. The product of the two counts are 1617, but you need to add the amount of time each inner and outerloop take to execute, if each inner loop takes Ti cycles and each outer loop takes To cycles, then the delay is (Ti*Long_Delay1+To)*Long_Delay2+Te cycles, Te are the cycles at the end (4 in this case). The actual count will be likely a little off, because of differences in branch execution entering and leaving a loop as opposed to taking the loop (ie decsz takes 1 clock cycle when skip isnt taken as opposed to 2 clock cycles when skip is taken).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • BebopALotBebopALot Posts: 79
    edited 2006-02-03 15:09
    Oh I see...the first loop will count down all the way but the second loop decrements only by one and returns back to the first loop, unless it is zero, then it terminates. I get it, thanks Paul. I guess your formula there is used in some form in the "Delay Code Generator" site I have used.

    -BBAL
Sign In or Register to comment.