Shop OBEX P1 Docs P2 Docs Learn Events
Having some trouble with Assembly code — Parallax Forums

Having some trouble with Assembly code

dayoadedayoade Posts: 13
edited 2017-07-05 11:55 in Propeller 1
Hello everyone,

I am sorry for the long post but I have been rattling my head around this problem for quite some time. If anyone could provide assistance to one of my problems I would greatly appreciate it.

1. Every time I load the ASM code onto the debugger i get an error message that says "no data- assembly code with Debug kernel loaded in Propeller Chip?", what does this mean and how do i fix it?

2. I have no problem running the Pasm_AsmDebug_Demo ASM code on the debugger. However, whenever I run the Toggle program (assembly code from the propeller education kit, i see pins that are not supposed to be on turn on and pins that are supposed to be on are off in various different ways. When I run it step by step in the debuggger and then proceed to run the program in its entirety, it executes the way it supposed to. Essentially, it doesn't execute properly until I run it step by step and then run the program in its entirety, how do i fix this?
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
PUB Main
{Launch cog to toggle P16 endlessly}

dbg.start(31,30,@entry) 
cognew(@Toggle, 0) 'Launch new cog
OBJ

dbg :  "PASDebug"

DAT
{Toggle P17}
                       org        0                           'Begin at Cog RAM addr 0

               entry

      '  --------- Debugger Kernel add this at Entry (Addr 0) ---------
   long $34FC1202,$6CE81201,$83C120B,$8BC0E0A,$E87C0E03,$8BC0E0A
   long $EC7C0E05,$A0BC1207,$5C7C0003,$5C7C0003,$7FFC,$7FF8
'  -------------------------------------------------------------- 
    
                                                          
Toggle                 mov        dira, Pin                             'Set Pin to output
                       mov        Time, cnt                             'Calculate delay time
                       add        Time, #9                              'Set minimum delay here
:loop                  waitcnt    Time, Delay                           'Wait
                       xor        outa, Pin                             'Toggle Pin
                       jmp        #:loop                                'Loop endlessly

Pin          long |< 17                                                 'Pin number
Delay        long 6_000_000                                             'Clock cycles to delay
Time         res 1                                                      'System Counter Workspace


3. This sets up the main reason why I am posting; the assembly code that I have is not executing at all. I don't know it is an interference with the pins that are operating in Spin or another issue.

CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000

VAR
byte datin[3], dp
byte light1status, light2status, light3status, light4status
word dtemp1, dout1, dtemp2, dout2, dtemp3, dout3, dtemp4, dout4

long Command
long pulsecount

OBJ

dbg :  "PASDebug"

PUB LightControl_main


  dbg.start(31,30,@entry)

 'Assembly code for 4 light pulsing
  Command:=0
  cognew(@Asm, @Command) ' set up another processor

  ' UM245R communication Lines
  dira[7..0] := %00000000   ' input byte form UM245R
  dira[8] := 0               'input, RXF
  dira[9] := 1                 ' output, RD#
  dira[10] := 0              'input, TXE
  dira[11] := 1              ' output, WR#

  'Digital output communication lines, SN74HC595

  dira[12] := 1               ' output, clock
  dira[13] := 1               ' output, data line 1
  dira[14] := 1                ' output, latch 1
  dira[15] := 1                 ' output, data line 2
  dira[16] := 1                ' output, latch 2
  dira[17] := 1                'output, data line 3
  dira[18] := 1                'output, latch 3
  dira[19] := 1                 ' output, data line 4
  dira[20] := 1                 ' output, latch 4

  dira[21] := 1                    ' output, analog MUX 1
  dira[22] := 1                    ' output, analog MUX 2
  dira[23] := 1                    ' output, analog MUX 3
  dira[24] := 1                    ' output, analog MUX 4

  dira[25] := 0                    ' input, camera frame exposure signal

  


  outa[9] := 1
  outa[11] := 0
  outa[12] := 0
  outa[13] := 0
  outa[14] := 0
  outa[15] := 0
  outa[16] := 0
  outa[17] := 0
  outa[18] := 0
  outa[19] := 0
  outa[20] := 0
  outa[21] := 0
  outa[22] := 0
  outa[23] := 0
  outa[24] := 0

  
  light1status := 0
  light2status := 0
  light3status := 0
  light4status := 0

   ' set 4 LED drive voltage outputs to 0

  repeat 16
    outa[12] := 1           ' clock it in
    outa[12] := 0
  outa[14] := 1              ' latch it in
  outa[14] := 0
  outa[16] := 1              ' latch it in
  outa[16] := 0
  outa[18] := 1               ' latch it in
  outa[18] := 0
  outa[20] := 1                ' latch it in
  outa[20] := 0

repeat

  repeat dp from 0 to 2
    repeat until ina[8]==0
    outa[9] := 0
    datin[dp] := ina[7..0]
    outa[9] := 1

    'change lightlevel1
  if datin[0]==2
    dout1 := datin[1] + datin[2]*256
    dtemp1 := dout1
    repeat 12
      if (dtemp1 & %0000100000000000)==%0000100000000000
        outa[13] := 1
      else
        outa[13] := 0
      outa[12] := 1   ' clock it in
      outa[12] := 0
      dtemp1 <<= 1    ' shift left 1
    outa[14]:=1      'latch it in
    outa[14]:=0

    ' turn on light1
  elseif datin[0]==3
    if light1status==0
      outa[21] := 1
      light1status := 1
    elseif light1status==1
      outa[21] := 0
      light1status := 0

      'change lightlevel2
  elseif datin[0]==4
    dout2 := datin[1] + datin[2]*256
    dtemp2 := dout2
    repeat 12
      if (dtemp2 & %0000100000000000)==%0000100000000000
        outa[15] := 1
      else
        outa[15] := 0
      outa[12] := 1   ' clock it in
      outa[12] := 0
      dtemp2 <<= 1    ' shift left 1
    outa[16]:=1     ' latch it in
    outa[16]:=0

    ' turn on light2
  elseif datin[0]==5
    if light2status==0
      outa[22] := 1
      light2status := 1
    elseif light2status==1
      outa[22] := 0
      light2status := 0

     ' change lightlevel3
  elseif datin[0]==6
    dout3 := datin[1] + datin[2]*256
    dtemp3 := dout3
    repeat 12
      if (dtemp3 & %0000100000000000)==%0000100000000000
        outa[17] := 1
      else
        outa[17] := 0
      outa[12] := 1         ' clock it in
      outa[12] := 0
      dtemp3 <<= 1          ' shift left 1  
    outa[18]:=1              ' latch it in
    outa[18]:=0

    ' turn on light3
  elseif datin[0]==7
    if light3status==0
      outa[23] := 1
      light3status := 1
    elseif light3status==1
      outa[23] := 0
      light3status := 0

      ' change lightlevel4
  elseif datin[0]==8
    dout4 := datin[1] + datin[2]*256
    dtemp4 := dout4
    repeat 12
      if (dtemp4 & %0000100000000000)==%0000100000000000
        outa[19] := 1
      else
        outa[19] := 0
      outa[12] := 1   ' clock it in
      outa[12] := 0
      dtemp4 <<= 1  ' shift left 1
    outa[20]:=1   ' latch it in
    outa[20]:=0

    ' turn on light4
  elseif datin[0]==9
    if light4status==0
      outa[24] := 1
      light4status := 1
    elseif light4status==1
      outa[24] := 0
      light4status := 0

      ' Run Light Pulsing (Round-Robbin) with Processor 2
  elseif datin[0]==10
    pulsecount := datin[1] + datin[2]*256
    Command:=1
    repeat until Command==0

  elseif datin[0]==255
    reboot


DAT

' Processor 2 code: Simple Round-Robbin Sequence

                       org      0

      entry

      '  --------- Debugger Kernel add this at Entry (Addr 0) ---------
   long $34FC1202,$6CE81201,$83C120B,$8BC0E0A,$E87C0E03,$8BC0E0A
   long $EC7C0E05,$A0BC1207,$5C7C0003,$5C7C0003,$7FFC,$7FF8
'  -------------------------------------------------------------- 


                       
Asm                    mov      CmdAddr, par
                       mov      VarAddr, par
                       add      VarAddr, #4
                       mov      dira, Pin

WaitForCmd             rdlong   Temp, CmdAddr
                       tjz      Temp, #WaitForCmd

                       rdlong   Count, VarAddr

Loop1                  mov      Temp, ina
                       and      Temp, Exposurein wz
               if_z    jmp      #Loop1
                       or       outa, Plight1or          '  turn on light 1
Lp1                    mov      Temp, ina
                       and      Temp, Exposurein wz
              if_nz    jmp      #Lp1
                       and      outa, Plight1and        ' turn off light 1
Loop2                  mov      Temp, ina
                       and      Temp, Exposurein wz
              if_z     jmp      #Loop2
                       or       outa, Plight2or   ' turn on light2
Lp2                    mov      Temp, ina
                       and      Temp, Exposurein wz
              if_nz    jmp      #Lp2
                       and      outa, Plight2and   ' turn off light2
Loop3                  mov      Temp, ina
                       and      Temp, Exposurein wz
              if_z     jmp      #Loop3
                       or       outa, Plight3or      ' turn on light3
Lp3                    mov      Temp, ina
                       and      Temp, Exposurein wz
              if_nz    jmp      #Lp3
                       and      outa, Plight3and         ' turn off light 3
Loop4                  mov      Temp, ina
                       and      Temp, Exposurein wz
              if_z     jmp      #Loop4
                       or       outa, Plight4or        'turn on light4
Lp4                    mov      Temp, ina
                       and      Temp, Exposurein wz
              if_nz    jmp      #Lp4
                       and      outa, Plight4and        ' turn off light4
                       djnz     Count, #Loop1
                       wrlong   Zero, CmdAddr
                       jmp      #WaitForCmd
                       
              

CmdAddr   long   0
VarAddr   long   0
Temp      long   0
Zero      long   0
Count     long   0
Pin        long   %00000001_11111111_11111010_00000000
Plight1or  long   %00000000_00100000_00000000_00000000  ' Pin 21
Plight1and long   %11111111_11011111_11111111_11111111  ' Pin 21
Plight2or  long   %00000000_01000000_00000000_00000000  ' Pin 22
Plight2and long   %11111111_10111111_11111111_11111111  ' Pin 22
Plight3or  long   %00000000_10000000_00000000_00000000  ' Pin 23
Plight3and long   %11111111_01111111_11111111_11111111  ' Pin 23
Plight4or  long   %00000001_00000000_00000000_00000000  ' Pin 24
Plight4and long   %11111110_11111111_11111111_11111111  ' Pin 24
Exposurein long   %00000010_00000000_00000000_00000000         




Comments

  • AribaAriba Posts: 2,690
    edited 2017-07-06 05:09
    Hello dayoade

    You need to start the cog you want to debug at @entry and not at the Label after the Debug Kernel. With that your two codes load correct and show the code with addresses in PASD.
    The cog always starts into a breakpoint, that is the only way the PASDebug object can communicate with the debugged cog. Then you can press F5 to start the cog (maybe set breakpoints before that).

    Some tipps:
    You don't need an OR and an AND mask for pins. There is the ANDN instruction that inverts the bits before ANDing with the destination.
    You can define a mask with
    Plight1or long 1<<21 ' Pin 21
    If you want to set a pin according a flag then use te MUX?? instructions.
    Instead of: mov temp,INA - and temp,Exposurein wz
    you can also do it with one instruction: test Exposurein,INA wz

    Andy

Sign In or Register to comment.