spin to assembly
DF
Posts: 10
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.
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
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
·
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)!