Shop OBEX P1 Docs P2 Docs Learn Events
spin to assembly — Parallax Forums

spin to assembly

DFDF Posts: 10
edited 2010-07-28 21:12 in Propeller 1
I have created a program in spin and it works exactly how I want it to. Now I need to convert it to assembly to utilize the faster speed. Programming in spin seemed a lot easier, I am completely lost trying to convert it. Any help would be welcomed with open arms. Below is the spin code I have to convert:

OBJ
· PC:"SerialMirror"

VAR
· long PCin
· byte num, track, val, count, c
· byte char[noparse][[/noparse]10]

CON
· _clkmode= xtal1 + pll16x
· _xinfreq= 5_000_000
· BaudRate= 38400········ 'Baud·····························
· RxPin= 31··········· 'For RS232························
· TxPin= 30··········· 'For RS232
· 'TxPin= 23············ 'sending to the motor controller
· CommsMode= %0000········ 'See SerialMirror.spin for meaning
PUB Main······
PC.start(RxPin, TxPin, CommsMode, BaudRate)
val:=0
count:=0
track:=0
repeat
·· PCin:=PC.rxcheck
· if PCin |= -1
···· PCin := PC.rx
···· c:=PCin
···· if (c => "0") and (c =< "9")·······························
······ val := (val * 10) + (c - "0")
······ count:=++count
······ PC.tx(45)
······ PC.tx(c)
······ PC.tx(44)
······ PC.dec(val)
······ PC.tx(59)
······ if count==3
······· PC.tx(13)
······· num:=val
······· repeat
·········· Char[noparse][[/noparse]track]:=num
··········· if track<(10)··························
············ num:= ++num
·············PC.tx(60)
············ PC.dec(Char[noparse][[/noparse]track])
············ PC.tx(44)
············ PC.tx (Char[noparse][[/noparse]track])·································
············ PC.tx (62)
············ PC.tx(13)
············ track:=++track
············ if track==10
············· track:=0
············· quit
······· val:=0
······· count:=0

I wouldn't call myself a newbie, but I'm def still a rookie.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-07-28 16:59
    SerialMirror already uses assembly language to do the serial I/O. Why do you think you need to use assembly for your program? You're really limited anyway by I/O speeds set by the Baud used for the serial I/O.
  • Dave HeinDave Hein Posts: 6,347
    edited 2010-07-28 17:29
    DF,

    I looked at your code, and there's a few things that don't look quite right.· The rxcheck will return a -1 if there is no received character, or it will return the next received character if availble.· You seem to be using it as a kbhit type of routine, which would tell you whether a charater is available, but would not read the character.· Of course, I assuming rxcheck in SerialMirror works the same as FullDuplexSerial.

    I believe you have an error in the expression "if PCin |= -1".· You are or'ing a -1 with PCin, and storing it into PCin.· This will always be TRUE, so you will always execute the statements after this.· I suspect you are trying to do the equivalent of the C statement "if PCin != -1", which would translate into Spin as "if PCin <> -1".

    Since PCin |= -1 is always TRUE you will then execute PCin := PC.rx, which will wait for the next character to be received.· I think you can delete the call to rxcheck and the following "if" stament, and your code should do what you want it to do.

    The other curious thing is the statement "count := ++count".· The ++count increments count, and the := will just assign the incremented value back to count.· You do not need the "count :=" part of the statement.

    Dave

    ·
  • DFDF Posts: 10
    edited 2010-07-28 18:55
    Mike Green said...
    SerialMirror already uses assembly language to do the serial I/O. Why do you think you need to use assembly for your program? You're really limited anyway by I/O speeds set by the Baud used for the serial I/O.
    This program will evolve to collect data from an AtoD (analog to digital converter) I will need the speed to measure data points of a really really small wave form. That is why i need the speed. Using assembly will give me 20 to 40 times as many points to plot
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2010-07-28 21:12
    There is no easy conversion button. You have to go line by line and determine whats happening then convert to PASM. You will find that sometimes one line of SPIN is five or more lines in PASM. Seeing as you are calling other objects, it becomes that much more difficult, cause one call to an object's method may call dozens of lines of SPIN and PASM. You'd have to rewrite the object into your PASM as well.

    Ultimately, as others have unfired, you need to asses if it is really worth it. What will have to happen is that you learn PASM and manually convert it. It really is a great language to learn because of the speed, but it can be a big headache when you first start and it is a pain to maintain if you don't program consistently and/or don't comment your code well.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    April, 2008: when I discovered the answers to all my micro-computational-botherations!

    Some of my objects:
    MCP3X0X ADC Driver - Programmable Schmitt inputs, frequency reading, and more!
    Simple Propeller-based Database - Making life easier and more readable for all your EEPROM storage needs.
    String Manipulation Library - Don't allow strings to be the bane of the Propeller, bend them to your will!
    Fast Inter-Propeller Comm - Fast communication between two propellers (1.37MB/s @100MHz)!
Sign In or Register to comment.