Shop OBEX P1 Docs P2 Docs Learn Events
Basic <-> Asm help required — Parallax Forums

Basic <-> Asm help required

magnetmagnet Posts: 13
edited 2008-01-03 15:41 in Propeller 1
Hi from a total newbie.

I took the plunge and bought a DIP chip education pack to play around with. After draining several 9v batteries I found a regulated 7.5v 0.86VA mains adaptor in my "bits box" to use and am assuming this will be suitable to power my projects without damage for the future?

The first program I wrote, a port of a C program I have running on my main computer, failed despite "looking fine" to me... Lesson #1 learnt! Forget old habits.

Now to my request:
As there is no screen output from the chip circuit, I am using known data input values and results that trigger a row of LEDs to signal the code has performed correctly and has found the correct solution. However, as with all interpreted languages, speed is slower than this chip can deliver if coded using assembler, so to get me started can someone tell me if the following 2 bits of code do exactly the same thing please so I can start to get a grip on the syntax...

{{spin code}}
r001 += f101
carry := 0
if r001 > 999
  carry := 0
  r001 -= 1000




{{assembler ??}}
DAT
                org             0
add_f       adds           r101,f101
                movs          carry,#0
                cmps          r101,#v999      wc
if_a          movs          carry,#0
                subs            r101,#v1000


r101        long            1234
f101        long            5678
carry       long            0
v999        long            999
v1000      long            1000




Some pointers to working assembler code would be appreciated.

Happy New Year
magnet

Comments

  • AleAle Posts: 2,363
    edited 2008-01-01 19:58
    Magnet:

    The labels referenced in assembler do not need the # (excet when they are destination of jm or call).
    # is only used when the value you want is going to be used as literal.

    Example:

    add v1,v2


    v1 long 3
    v2 long 4

    is the right form to add the contents of memory position v2 to v1

    add v1,#123

    is the right to add the constant 123 (decimal) to the contents of memory position v1.

    This is extensively explained both in the propeller manual and in deSilva's assembler tutorial.

    There is a wiki at propeller.wikispaces.com with loads of examples and useful information.
    The sticky propeller programming tutorials is very well recommended too.

    Rewrite your code removing the #s from where they are not needed and try again.

    you can test assembler code with my propeller simulator at sourceforge.net/projects/pPropellerSim

    Post Edited (Ale) : 1/1/2008 8:08:59 PM GMT
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-01 21:26
    magnet,

    there is much more to say...
    Don't use the opcodes with "S" until you understand what they do. In nearly all cases in your example it has to be
    MOV
    ADD
    SUB
    CMPS is o.k. however smile.gif

    But the last SUBS must be guarded by IF_A as well!
    Your SPIN code is also unclear: Why do you set flag to zero twice? r001 could be set to zero, rather...

    I should also recommend to read through my tutorial.... of course smile.gif

    ---
    Edit:
    Wait, there is more:
    (a) Of course you can operate your TV monitor using three resistors
    (b) or you use one of the serial PC objects (Recommendation: PropTerm) to communicate with PC screen, keyboard and mouse
    (c) or you use Ariba's PASD for debugging and steping through your machine code

    Post Edited (deSilva) : 1/1/2008 9:43:38 PM GMT
  • magnetmagnet Posts: 13
    edited 2008-01-01 22:25
    {{spin code}}
    r001 += f101
    carry := 0             <----- this is a carry clear
    if r001 > 999
      carry := 1           <----- typo in original code. should be a carry set.
      r001 -= 1000
    
    



    I always assumed you have to use the S when signed variable values are important, especially as some of my values can go negative, but I see your point with just clearing the carry variable, it could just be a MOV used in that case.

    Will read through the tutorial as any literature is most welcome. I have managed to get a small snippet of asm code to compile so this is a good step in the right direction.

    Many thanks
    magnet
  • bambinobambino Posts: 789
    edited 2008-01-02 03:53
    Magnet, S can stand for signed, but the dangerous S I think desilva was pointing out is movs, where the s stands for source operand.
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-02 05:06
    Also: There is no difference in the "main working" of SUB/SUBS and ADD/ADDS, however the flags will be set differently. As this has turned out to be difficult to explain, I strongly recommend to not use ADDS/SUBS below guru level. smile.gif
  • magnetmagnet Posts: 13
    edited 2008-01-02 09:09
    bambino: Yes, I see what you mean now. Another dangerous assumption made by me. Thanks.
    deSilva: I have checked my input data over a wide range and can find no instant where adding any 2 numbers together will result in a value exceeding the 32bit max.value so in that case a simple MOV will be sufficient.
    Thanks
  • magnetmagnet Posts: 13
    edited 2008-01-03 15:04
    Coding going well but stumbled again. Trying to get an led to flash on, then off every loop of my code to let me see the cog is active.

    Tried this code and it turns on the led fine but does not switch if off again after my delay. What have I done wrong this time please?

    led_pulse   mov   t1,#1   wz
                      shl   t1,pin15
                      muxnz outa,t1
                      muxnz dira,t1
                      waitcnt cnt,delay
                      muxnz outa,t1
                      muxnz dira,t1
    
    
    t1             long  0
    pin15       long  15
    delay       long  100000
    
    



    Many thanks
    magnet.
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-03 15:41
    Magnet,
    (1) There is no loop, the activity after the last mux is undefined; in best case the COG will stop (but why?) and all I/O will idle as well.
    (2) Why do you touch DIRA so often? Once per COG should be enough.
    (3) There is rarely a need to use MUX, especially not as a beginner. It will not make you happy...
    (4) But after the wait it will not change anything.. Do you wanted to use MUXZ ?
    (5) The WAITCNT will stop any activity for 50 seconds, as it will wait for a tick just over. Read the description of WAITCNT please. What you want to do is:
    MOV deadline, theDelay
    ADD deadline, CNT
    WAITCNT deadline, #0
    



    There is a more advanced technique that uses also the src parameter of WAITCNT..

    Post Edited (deSilva) : 1/3/2008 3:46:28 PM GMT
Sign In or Register to comment.