Shop OBEX P1 Docs P2 Docs Learn Events
how about a tutorial explaining single commands, tipps and tricks how to debug — Parallax Forums

how about a tutorial explaining single commands, tipps and tricks how to debug

StefanL38StefanL38 Posts: 2,292
edited 2007-03-21 15:09 in Propeller 1
Hello,

this thread is called "Assembly Code Examples for the Beginner"

what i have read yet, in my opinion, is more like: "here are some code-snippets with some small comments"

for REAL beginners comments have to be bigger than three freak-words

what i would expect are code examples like

how can i change a single bit the shortest way?

just showing THIS WITHOUT beeing embedded in a bigger code-example like a SPI-engine.
If you now nothing at all, in an example like the SPI-engine there is much to much around irritating


how do i create a loop that will repeat "n" times?

i made some comments explaining what is happening in "medium-size" (see code example {{ AssemblyToggle.spin N-TIMES}} below)
for a tutorial these comments can still be improved a lot

with things like
- pictures showing the code and values inside the RAM, showing the destination and source-place inside the RAM and what is happening with the values at the destination-adress through that ONE command
- additional lines showing the concrete values of "variables" before and after a command
example:

command "shr" bitshift right: what does it do?

imagine the "variable" BitFilter contains the value decimal 32
in the dualsystem this looks like this:

87654321
value of "BitFilter"=00100000

87654321
before command shr value of "BitFilter"=00100000

87654321
after command shr value of "BitFilter"=00010000

the "1" has moved from bit 6 to bit 5

so THIS is an example explaining a lot of details and makes it easy to understand

additional there could be a complete code (SPIN and asm) that makes a "running light" with a row of 8 LEDs
using the commands shr shl


COMPLETE code-examples for debugging purposes like:
-copy value to main-ram that it could be accessed by a spin-code running in antother cog
showing the value in binary,hex or decimal writing (on TV, RS232 etc.)
or showing messages like "asm-code branched to subroutine "xy"



code-snippet for an repeat n-times loop

basic principle

mov LoopCntr,#8 'set counter"variable" to value how often loop should be repeated
testloop nop 'nop means "no operation" in your real code place here your first command that should be inside the loop
'commands that should be repeated
djnz LoopCntr, #testloop 'decrement counter"variable" and jump to label "testloop" if value of counter"variable" is NOT zero


so if you modify the code-example from the manual as complete code-example that (should work)

it looks like this:

{{ AssemblyToggle.spin N-TIMES}}
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000

PUB Main
{Launch cog to toggle P16 n times}
cognew(@Toggle, 0) 'Launch new cog

DAT
{Toggle P16}
ORG 0 'Begin at Cog RAM addr 0
Toggle mov dira, Pin 'Set Pin to output

mov LoopCntr,#8 'set counter"variable" to value how often loop should be repeated
'this command stores the value "8" in the cog-ram and can be accessed by its label "LoopCntr"

mov Time, cnt 'Calculate delay time
add Time, #9 'Set minimum delay here
:loop waitcnt Time, Delay 'Wait
xor outa, Pin 'the xor-command inverts the value of the bit "PIN". The value of this bit inside the register outa changes from "0" to "1" to "0" so the IO-PIN Toggles from low to high to low...
djnz :loop ''decrement counter"variable" and jump to label "testloop" as long value of counter"variable" is NOT zero

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


tricks for easy testing:
connect a LED in serial with a fitting current-limiting resistor to one IO-PIN

take this n-time loop at the beginning of your assemblercode

place your new code after that n-time loop

place another endless loop AFTER your new code to test with another delay time 3x faster

then you have a feedback by the flashing of the LED
starting your code makes the LED flash n-time
then your new code is running down

after finishing your new code the LED starts flashing faster endlessly telling you that your new code was executed completly

so what are your tricks for debugging asm-code?


I'm developing software now for 20 years (most in Pascal and Delphi) only a VERY little bit in assembler

But even for me with this great experience of programming in high-languages a tutorial like described above
would speed up learning propeller-assembler 3 to 5 times.

So i hope to see a lot of postings with easy to understand comments.

lot's of greatings

Stefan Ludwig


wise word an old programmer: a software is NEVER finished. It's just eventual running 99% bugfree - still missing the following features wished by the users.....

Comments

  • StefanL38StefanL38 Posts: 2,292
    edited 2007-03-20 20:17
    hm - the formatting looks awful

    almost no formatting left after posting

    how can I post it a way that keeps the fomatting like tabulators?

    Stefan Ludwig
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-03-20 20:25
    If you use the full post form and use the code button (# in IE, [noparse][[/noparse]code] in other browsers) you can keep formating
    Formatted text
       at different indentations
           for easier reading of structure
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • KaioKaio Posts: 253
    edited 2007-03-21 15:09
    Hi Stefan,

    you can now debug your assembly programs easily using POD.

    If you need assistance using POD I can help you.
Sign In or Register to comment.