ASM questsion.

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have this

sbic	PINx,PIN5;( skip if 0 ) 1 or 2 
rjmp	nextBit; 2
rjmp	nextBit; 2

nextBit:
sbic	PINx,PIN4
sec
st		X+,r18
clr		r18
rol		r18

This gives me 4 or 5 clocks before the bit is read.

I want to do the same thing but yield 3 or 4 based on the pin. I dont see a way to do it, any thoughts? No way to skip one line instruction without a compare, that I know of..

In this particulate case the timing is actually this critical. I do realize I could change the crystal speed, but thus far have no intentions of doing that.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wouldn't you just replace the RJMPs with NOPs?

EDIT: sorry, scratch that - same cycles (3) in either case I guess

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yeah I keep thinking there is some simple answer laying right in front of me but I dont see it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I probably did not get it. Would it be ok
to replace the second rjmp by a nop ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Surely you have tried the 3/4 cycle version below

       IN   r0,PINx   ; 1
       andi r0,(1<<5) ; 1
       brne next      ; 1/2
next:

This is 2/3 cycles

       sbic PINx,5    ; 1/2
       rjmp next      ; 2
next:

Or you can use the T bit if you like.

Untested, but you can try in the simulator.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

well you had 3 or 4 to the next sbic.

    sbic   PINx,PIN5 ;( skip if 0 ) 1 or 2
    rjmp   nextBit   ; 2
nextBit:
    sbic   PINx,PIN4
    sec
    st     X+,r18
    clr    r18
    rol    r18 

will give you your 2 or 3 cycles. Add a nop before 'nextBit' for a constant 4 cycles. If the logic/timing is reverse of what you want, use sbis instead.

Note that this code will not work correctly, unless you have something that clears the carry bit.

I can't help but think you're barking up the wrong tree here, perhaps a full description of what you're trying to accomplish would let us help you more. I can't think of any reason why you would want to change the sampling of a I/O pin by only a single CPU cycle.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
sbic   PINx,PIN5 ;( skip if 0 ) 1 or 2
rjmp   nextBit   ; 2 

Ok I need it reversed. this is 3 or 4, I'm looking for 4 or 3.
The 0 case needs to be 4 and the true case 3.
Sorry I said that backwards above.

Thinking I can do this with Daves andi suggestion

like..

       IN   r0,PINx   ; 1
       andi r0,(1<<5) ; 1
       breq next      ; 1/2
next: 

but getting

Error: register number above 15 required

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Right, andi needs r16-r31.

RES

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

RES wrote:
Right, andi needs r16-r31.

Ahh ok.

I got it using this

       IN   r25,PINx   ; 1
       andi r25,0x20 ; 1
       breq skipped   ; 1/2 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can invert it by exchange of sbis with sbic.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ossi wrote:
You can invert it by exchange of sbis with sbic.
- Ahh, thx. totally forgot about that.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

S_K_U_N_X wrote:
ossi wrote:
You can invert it by exchange of sbis with sbic.
- Ahh, thx. totally forgot about that.

evidentially you didn't read my post

Writing code is like having sex.... make one little mistake, and you're supporting it for life.