PropBASIC (Preliminary Examples)
Bean
Posts: 8,129
Okay, so I finally made a decision on my Propeller BASIC compiler.
I've decided to translate BASIC into Propeller Assembly....Just native assembly for the moment, but when the IDE support LMM, I will update it to that.
The main reason for this is that I can reuse a bunch of the code from the SX/B compiler. And users need help learning Propeller assembly as well as spin.
I have really just gotten started and here is some BASIC code and what gets generated:
The BASIC code should look very familiar to SX/B users.
You can see how any constants > 511 are defined with a underscore prefix.
The final CON line in the propeller code is for any constants that are defined that are less than 512 (there aren't any in this program).
Any comments are welcomed.
Bean.
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Does that byte of memory hold "A", 65, $41 or %01000001 ?
Yes it does...
Post Edited (Bean (Hitt Consulting)) : 10/15/2009 2:00:21 AM GMT
I've decided to translate BASIC into Propeller Assembly....Just native assembly for the moment, but when the IDE support LMM, I will update it to that.
The main reason for this is that I can reuse a bunch of the code from the SX/B compiler. And users need help learning Propeller assembly as well as spin.
I have really just gotten started and here is some BASIC code and what gets generated:
DEVICE P8X32A, XTAL1, PLL16X FREQ 80_000_000 Mask CON %0000_0000_0000_0000_1000_0000_0000_0000 temp1 VAR LONG PROGRAM Start Start: DIRA = Mask Again: OUTA = Mask PAUSE 10 OUTA = 0 PAUSE 10 GOTO Again END
'' *** COMPILED WITH PropBasic VERSION 0.00.01 08/27/2009 *** CON 'DEVICE P8X32A, XTAL1, PLL16X _ClkMode = XTAL1 + PLL16X _XInFreq = 5000000 'FREQ 80_000_000 ' Mask CON %0000_0000_0000_0000_1000_0000_0000_0000 'Mask CON %0000_0000_0000_0000_1000_0000_0000_0000 ' temp1 VAR LONG 'temp1 VAR LONG PUB Main 'PROGRAM Start CogNew(@__PROGSTART, 0) DAT __PROGSTART JMP #Start Start 'Start: MOV DIRA,Mask ' DIRA = Mask Again 'Again: MOV OUTA,Mask ' OUTA = Mask MOV __PARAM1,CNT ' PAUSE 10 ADD __PARAM1,_80000 MOV __PARAM2,#10 L0001 WAITCNT __PARAM1,_80000 DJNZ __PARAM2,#L0001 MOV OUTA,#0 ' OUTA = 0 MOV __PARAM1,CNT ' PAUSE 10 ADD __PARAM1,_80000 MOV __PARAM2,#10 L0002 WAITCNT __PARAM1,_80000 DJNZ __PARAM2,#L0002 JMP #Again ' GOTO Again JMP #$ 'END '********************************************************************** _32768 Mask LONG 32768 _80000 LONG 80000 __PARAM1 RES 1 __PARAM2 RES 1 __PARAM3 RES 1 __PARAM4 RES 1 __PARAMCNT RES 1 temp1 RES 1 CON
The BASIC code should look very familiar to SX/B users.
You can see how any constants > 511 are defined with a underscore prefix.
The final CON line in the propeller code is for any constants that are defined that are less than 512 (there aren't any in this program).
Any comments are welcomed.
Bean.
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Does that byte of memory hold "A", 65, $41 or %01000001 ?
Yes it does...
Post Edited (Bean (Hitt Consulting)) : 10/15/2009 2:00:21 AM GMT
Comments
Deep in the files of my computer are some code examples of a Basic compiler showing how it converts each instruction to Z80 assembly. None of it looked hugely complicated. Just a bit tedious coding each instruction.
Some things should end up only a few asm instructions. While/Wend, For/Next and Do/Loop, If/Endif I've got all the string functions in Z80 assembly if this might be helpful, though they are not that hard to code. Left(), Mid(), Right(), Instr(), Hex(), Asc(), Chr() are core examples.
Integer math should be fairly easy. Floating point math is harder but I have seen that done.
Some structures need a little more thinking about, eg 'if a=5 then' vs 'a=5'. No == there to make it easier on the compiler. But it isn't hard to search for the 'if' and/or 'then' somewhere in the line.
And there are a few instructions one misses in Basic (well at least some forms of basic) that should be one-liners to convert to assembly. Eg binary logic
a=a and 01000111
a=a nand 0111111
a=a or 0111111
a=a not 01010101
a=a xor 11110000
I could write pages. But I'd like to contribute something too in a more tangible way. This is so exciting!
It should be blazingly fast, and the code size limit may not matter for a lot of the small examples.
One suggestion: write a PAUSE subroutine, then you can just go:
mov _pausems,#10
call #pause
If it is used more than once in the program you win BIG on memory space.
Personally, I think this will be an invaluable tool to teach guys who use PBASIC how to write PASM code - just like SX/B was a great way to learn SX programming.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Please use mikronauts _at_ gmail _dot_ com to contact me off-forum, my PM is almost totally full
Morpheus & Mem+dual Prop SBC w/ 512KB kit $119.95, 2MB memory IO board kit $89.95, both kits $189.95
www.mikronauts.com - my site 6.250MHz custom Crystals for running Propellers at 100MHz
Las - Large model assembler for the Propeller Largos - a feature full nano operating system for the Propeller
How will it differ from FemtoBASIC? (in a nutshell)
Do you have a tiny beta PropBasic pre-release version
that I can try out on the demo board?
humanoido
· femtoBasic is written in spin, so it pretty slow. But still a cool program considering it runs totally on the Propeller.
· PropBASIC is a PC program that converts (translates) BASIC code into PASM (Propeller Assembly).
· What I have shown is all that it does at the moment.
· Give me a couple weeks and I should have something a little more useful.
· After I get far enough, I'll ask Ken if we can make a private PropBASIC forum with a couple Alpha testers to really get it going.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Does that byte of memory hold "A", 65, $41 or %01000001 ?
Yes it does...
·
Aaaaa!· Goto!
Looks interesting...· Would there be Spin compatibility for including Exchange objects for example?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I don't see how I would be able to interface to the spin objects, but I'll have to think about it. Or maybe someone else has an idea of how to do it.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Does that byte of memory hold "A", 65, $41 or %01000001 ?
Yes it does...
·
Great start.
If I may make a suggestion:
Could you use
Mask· DAT %0000_0000_0000_0000_1000_0000_0000_0000
temp1· DAT LONG
as these use program storage (initialized and not initialized) in DAT area
and reserve CON for constant values that are not stored,
like the constant 10 in
· MOV __PARAM2,#10·············
edit:
or use COG since these variables are in cogmemory
Mask· COG %0000_0000_0000_0000_1000_0000_0000_0000temp1· COG LONG
regards peter
Post Edited (Peter Verkaik) : 8/28/2009 1:36:24 PM GMT
This is fantastic! I am ready to buy a Propeller system! I already know SX/B and it should be easy to get into it. Can you mix Assembler or SPIN in with the Propeller BASIC? What about doing video, PS2 keyboard, mouse, etc.
This opens up some doors and I will not abandon the SX chip.··If I want video, PS2 capabilities and speed, then go with the more expensive Propeller but if not needed, then go with the less expensive SX28 or SX48.
We will need some translation help from SPIN to Propeller BASIC most likely also.
I will definately follow this post!
The basic to z80 assembler I mentioned earlier is from oshonsoft. It has some great examples of how things get translated. Very little in the way of strings, but it does have floating point. I can post the instruction set and heater is our resident expert on both Z80 opcodes and pasm.
For example, this is what it does with
to
One thing that is nice about that is the comments it adds automatically and also the line numbers so you can see what each line of basic has been converted to. The principles would be the same for pasm. By breaking it down into manageable pieces the whole project is not so daunting. The instruction set is small and I'd want some more than this, but it is a start and every one of those instructions translates 1:1 to some assembly so examples of each ought to be useful. Translating z80 to pasm is something I might have to look at (or ask heater!). But I think it ends up with not many assembly instructions to learn. cc below from the beginning of the instruction manual. Some of these are going to be easy, but the floating point I think could be very useful.
The list of all Basic compiler keywords:
DIM, AS, BOOLEAN, SHORT, INTEGER, LONG, SINGLE, TRUE, FALSE, CONST, MOD, NOT, AND, OR, XOR, NAND, NOR, NXOR, SQR, SIN, COS, TAN, EXP, LN, LOG, GOTO, FOR, TO, STEP, NEXT, WHILE, WEND, IF, THEN, ELSE, ENDIF, POKE, PEEK, SETBIT, RESETBIT, TESTBIT, MAKEBIT, GET, PUT, PRINT, LF, CRLF, END, GOSUB, RETURN
Default extension for basic source files is BAS. The compiler output is assembler source file (with ASM extension) that can be translated to binary code using integrated assembler. Smart editor marks all reserved keywords in different color, that simplifies debugging process.
Five data types are supported:
- Boolean (1-byte, True or False)
- Short (1-byte integers in the range -128 to 127)
- Integer (2-byte integers in the range -32,768 to 32,767)
- Long (4-byte integers in the range -2,147,483,648 to 2,147,483,647)
- Single (4-byte floating point, 7 digits precision, IEEE 754)
Post Edited (Dr_Acula) : 8/28/2009 2:06:11 PM GMT
you be implementing cognew/coginit? Will you be using the same 'Task' command in PropBASIC?
Ray
DO-LOOP, FOR-NEXT, IF-THEN-ELSE etc.
plus integermath on variables. Since there is only 1·variable type in COGs
(long) that should be doable. Further the elementary keywords
INPUT, OUTPUT, LOW, HIGH to manipulate pins, using predefined
pinnames PIN0 to PIN31 (so DIRA,·INA·and OUTA need not be used
at the propbasic level).
Regarding subroutines and functions, the simple GOSUB would suffice,
given the·very limited cog address space.
Edit:
And the ability to use long arrays
eg.
tempArray COG LONG(7) 'create uninitialized long array
tempArray(1) = 1234 + tempArray(3)
regards peter
Post Edited (Peter Verkaik) : 8/28/2009 3:05:23 PM GMT
oshonsoft, I know who this guy is
He is a scientist (Physicist) in Serbia.
It would be great if we could get him to write a basic for the prop!
His stuff has the best little IDEs you ever saw.
I have never really used basic, but this seems like a super project!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Some mornings I wake up cranky.....but usually I just let him sleep in -
Could you elaborate on your ideas?
I can see something like this:
compiles into a spin file
that we can import into a spin application file.
regards peter
Perhaps you could at least look at Holly's suggestion. Holly, I would like to contact this person.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
JMH
I think PASM can not address VAR and DAT variables, only via the PAR parameter.
So you could have something like this
that compiles into
Notice I changed PROGRAM to MODULE. Since your working from inside out (only native PASM now)
the term PROGRAM would be used for when it is possible to write an entire program in basic.
regards peter
Rick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NYC Area Prop Club
Prop Forum Search (Via Google)
·
www.oshonsoft.com/contact.php
www.oshonsoft.com/author.html
He lives very close to Mikroelektronika, they make
the best dev boards I ever saw! I wish they had some
for the propeller.
www.mikroe.com/en/tools/easyarm/
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Some mornings I wake up cranky.....but usually I just let him sleep in -
very commendable to go with your SX/B - style translator... I've mentioned many times before that SX/B helps me learn SASM.
(But please, don't call it " Prop/B " or the propeller will start sounding like a California political animal. [noparse]:)[/noparse])
thanks for your work!
cheers
- Howard
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Ken
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
There are 10 types of people in the world, those who understand binary and those who don't.·· -a poster I saw
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
There are 10 types of people in the world, those who understand binary and those who don't.·· -a poster I saw
I think one of the worst logic jokes, for a strap line, was "2b or not 2b = ff"
Edit
I took out binary and put in logic, before purists pointed out it's Hex.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Style and grace : Nil point
Post Edited (Toby Seckshund) : 8/29/2009 7:05:47 PM GMT
LOL - nothing like killing a good joke, eh? [noparse]:)[/noparse])
@technoweasel - I'd not stop working on it because you will learn a lot by doing so. Consider also that there are several versions of compliers and debuggers being worked on at the same time. And what's great about here: these folks help each other, not competing.
And you might come up with something no one else has thought of!
cheers
- Howard
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Does that byte of memory hold "A", 65, $41 or %01000001 ?
Yes it does...
·
Forum Moderator
I would "Kill" to have a Propeller/Basic complier. Just the thought of having the power of the Propeller and me being able to
write to it easily is to good. (This is why I like the $BasicStamps)
I have all the Prop stuff, Prop.Pro.Dev.Board, Prop.Proto Board, Hydra Board, Expan.cards, Key board, mouse,
Prop Clip, Prop Plug, Prop this and Prop that.
My only problem with all of this is with Prop/ASM.
It just takes way to much code for me to write/use.
I quickly loose interest and return to my little favorites the BS2s
I really like a registerd domain name "Prop/Basic".· oh-ya!
I really hope Parallax rolls with this, Especially after the end of the SX-chips!!!!!!!
___________$WMc%____
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Truth is out there············································ BoogerWoods, FL. USA
Post Edited ($WMc%) : 8/30/2009 3:00:02 AM GMT
- Steve