Shop OBEX P1 Docs P2 Docs Learn Events
Blinded by ASM — Parallax Forums

Blinded by ASM

Jay KickliterJay Kickliter Posts: 446
edited 2009-01-28 21:55 in Propeller 1
This is perplexing me. I'm modifying the MCP3208 object to do a few extra things. Being very new to assembly, I've run into a lot of problems, but this one I just cant seem to figure out.

The top spin object is calling these methods from my assembly/spin sub object:
PUB sendReportPacket
    uarts.dec(DEBUG_PORT, imu.in(0))
    uarts.tx(DEBUG_PORT, ",")
    uarts.dec(DEBUG_PORT, imu.in(1))
    uarts.tx(DEBUG_PORT, ",")
    uarts.dec(DEBUG_PORT, imu.in(2))
    uarts.tx(DEBUG_PORT, ",")
    uarts.dec(DEBUG_PORT, imu.in(3))
    uarts.tx(DEBUG_PORT, ",")
    uarts.dec(DEBUG_PORT, imu.in(4))
    uarts.tx(DEBUG_PORT, ",")
    uarts.dec(DEBUG_PORT, imu.in(5))
    uarts.tx(DEBUG_PORT, ",")
    uarts.dec(DEBUG_PORT, imu.in(6))
    uarts.tx(DEBUG_PORT, ",")
    uarts.dec(DEBUG_PORT, imu.in(7))
    uarts.tx(DEBUG_PORT, "|")
    uarts.str(DEBUG_PORT, floatString.floatToString(imu.in(8)))
    uarts.tx(DEBUG_PORT, CR) 




This is the most pertinent code in the sub-object:
_imu_update             mov    kt1,par
                        add    kt1,#28
                        mov    kt2,#channel_0
                        mov    kt3,#8
                        mov    kt4,#offset_0
:aloop                  movs   :sub_offset,kt4
:sub_offset             subs   kt2,0
                        movd   :read_from,kt2
:read_from              wrlong 0,kt1
                        add    kt2,#1
                        add    kt1,#4
                        add    kt4,#1
                        djnz   kt3,#:aloop

                        mov    fnumA,channel_0
                        call   #_ffloat
                        wrlong fnumA,kt1
_imu_update_ret         ret

offset_0                 long    0
offset_1                 long    0
offset_2                 long    0
offset_3                 long    0
offset_4                 long    0
offset_5                 long    0
offset_6                 long    0
offset_7                 long    0 

channel_0               res     1
channel_1               res     1
channel_2               res     1
channel_3               res     1
channel_4               res     1
channel_5               res     1
channel_6               res     1
channel_7               res     1




And the spin code from the modified MCP3208 object:

VAR
  long  cog
  long  ins          '7 contiguous longs (8 words + 1 long + 2 longs)
  long  count
  long  dacx, dacy
  long  imuData[noparse][[/noparse]16] 

PUB in(channel) : sample

'' Read the current sample from an ADC channel (0..7)
  return imuData.long[noparse][[/noparse]channel] 




Finally, here's the output to the serial term:
2025,1878,1516,2054,2012,1635,4095,13|1877




The floating point value after the '|' should be 2025, since it was converted to FP from the integer in channel_0, but instead it looks as if it is it is being converted from the integer channel_1. Since I'm advancing the pointer after the loop, shouldn't both the first long written to HUB memory and the floating point value (which is directly reverenced to channel_0), be the same?

Comments

  • Mark SwannMark Swann Posts: 124
    edited 2009-01-28 21:36
    You need to place a NOP between two of your instructions, like this.

                            movd   :read_from,kt2
                            nop ' <<- add this line
    :read_from              wrlong 0,kt1
    
    

    Post Edited (Mark Swann) : 1/28/2009 9:42:30 PM GMT
  • Jay KickliterJay Kickliter Posts: 446
    edited 2009-01-28 21:46
    Thanks, I it worked when only when I put NOP after the movs, and the movd instruction. But then it blew up when I tried to put anything other than 0 in the offset table.

    I can't find anything in the documentation suggesting the extra NOP. Is it a bug?
  • Paul RowntreePaul Rowntree Posts: 49
    edited 2009-01-28 21:54
    Jay, the NOP takes care of instructions that are in the execution pipeline. In effect, it makes sure that the modified instruction gets out to memory before it is read back in for execution. It is the price to pay for optimized execution, so I would not call it a bug. I think it is described in deSilva's PASM tutorials.

    Cheers!
  • Mark SwannMark Swann Posts: 124
    edited 2009-01-28 21:55
    Jay Kickliter said...
    Thanks, I it worked when only when I put NOP after the movs, and the movd instruction. But then it blew up when I tried to put anything other than 0 in the offset table.

    I can't find anything in the documentation suggesting the extra NOP. Is it a bug?
    It is a well known issue, but it is not a bug. It is a side-effect of the instruction pipe-line.

    Paul is right. Go look in deSilva's PASM tutorials.

    http://forums.parallax.com/showthread.php?p=668559

    Mark

    Post Edited (Mark Swann) : 1/28/2009 10:03:58 PM GMT
Sign In or Register to comment.