From: Jan Panteltje on
Released under GPL2: An 8051-8052 2 pass assembler for the Linux OS.
http://panteltje.com/panteltje/newsflex/a52-2.0.tgz

This is a very simple assembler, and has less features then all the big macro ones.
But it has one feature all other ones do not have as far as I know:
It can generate binary output in MCS-52 BASIC data statements.
this makes writing inline asm easy in MCS-BASIC.
For example the code in q2.asm:
org $6000
lcall mysub
ret
mysub:
mov $20.0,c
ret
when assembled like this:
a52 q2.asm -l -b1000

generates these BASIC lines:
1000 rem code from q2
1002 data 18,96,4
1004 data 34
1006 data 146,0
1008 data 34
1010 org=24576
1012 for i=0 to 6
1014 read a:xby(org+i)=a:next
1016 return

You can then and do a
gosub 1000
in MCS-BASIC to call the asm.

Have fun.
From: Tim Williams on
Heh, when writing assembly in BASIC (QB specifically), I often assign
everything to an array then execute it. e.g.,

DIM Code(10) 'AS INTEGER implied by DEFINT A-Z
Code(0) = &H1234
....
Code(10) = &HF00F

DEF SEG = VARSEG(Code(0))
CALL ABSOLUTE(VARPTR(Code(0)), stuff)
DEF SEG

That looks ugly after more than a few lines, so most of the time I read from
a file as a first-run initialization. Also lots easier to maintain. Fine
for simple routines that don't need to change.

I don't really like DATA, it's the idea of having something and no way to
access it. I suppose assigning entries of an array is the closest thing to
predefined data (as in C or ASM), but I'm willing to bet it still executes
an awful lot of lines to do it. Stupid QB...

Tim

--
Deep Friar: a very philosophical monk.
Website: http://webpages.charter.net/dawill/tmoranwms

"Jan Panteltje" <pNaonStpealmtje(a)yahoo.com> wrote in message
news:hidq2n$v40$1(a)news.albasani.net...
> Released under GPL2: An 8051-8052 2 pass assembler for the Linux OS.
> http://panteltje.com/panteltje/newsflex/a52-2.0.tgz
>
> This is a very simple assembler, and has less features then all the big
> macro ones.
> But it has one feature all other ones do not have as far as I know:
> It can generate binary output in MCS-52 BASIC data statements.
> this makes writing inline asm easy in MCS-BASIC.
> For example the code in q2.asm:
> org $6000
> lcall mysub
> ret
> mysub:
> mov $20.0,c
> ret
> when assembled like this:
> a52 q2.asm -l -b1000
>
> generates these BASIC lines:
> 1000 rem code from q2
> 1002 data 18,96,4
> 1004 data 34
> 1006 data 146,0
> 1008 data 34
> 1010 org=24576
> 1012 for i=0 to 6
> 1014 read a:xby(org+i)=a:next
> 1016 return
>
> You can then and do a
> gosub 1000
> in MCS-BASIC to call the asm.
>
> Have fun.


From: John Larkin on
On Sun, 10 Jan 2010 19:16:49 -0600, "Tim Williams"
<tmoranwms(a)charter.net> wrote:

>Heh, when writing assembly in BASIC (QB specifically), I often assign
>everything to an array then execute it. e.g.,
>
>DIM Code(10) 'AS INTEGER implied by DEFINT A-Z
>Code(0) = &H1234
>...
>Code(10) = &HF00F
>
>DEF SEG = VARSEG(Code(0))
>CALL ABSOLUTE(VARPTR(Code(0)), stuff)
>DEF SEG
>
>That looks ugly after more than a few lines, so most of the time I read from
>a file as a first-run initialization. Also lots easier to maintain. Fine
>for simple routines that don't need to change.
>
>I don't really like DATA, it's the idea of having something and no way to
>access it. I suppose assigning entries of an array is the closest thing to
>predefined data (as in C or ASM), but I'm willing to bet it still executes
>an awful lot of lines to do it. Stupid QB...
>
>Tim

PowerBasic (the DOS and Console Compiler versions) have inline
assembly, and it's easy to make links between the BASIC and assembly.
For exaample, you can name or dim a variable in Basic and just refer
to it in assembly.

John

From: Tim Williams on
"John Larkin" <jjlarkin(a)highNOTlandTHIStechnologyPART.com> wrote in message
news:633lk5p9b1ti3lt94r1o8tek00vi8qcbsu(a)4ax.com...
> PowerBasic (the DOS and Console Compiler versions) have inline
> assembly, and it's easy to make links between the BASIC and assembly.
> For exaample, you can name or dim a variable in Basic and just refer
> to it in assembly.

Yup, and (AFAIK) newer versions e.g. FreeBASIC, QB64 etc. also support
extended features including proper OOP, inline everything, proper modern
datatypes, etc. Not to mention the Windows versions supporting everything
Windows.

It's really a shame Microsoft shipped their crappiest "language" with DOS.
It was a computational abomination. But it was either QBasic or DEBUG, so I
chose QBasic. ;^)

Tim

--
Deep Friar: a very philosophical monk.
Website: http://webpages.charter.net/dawill/tmoranwms


From: Jan Panteltje on
On a sunny day (Sun, 10 Jan 2010 19:16:49 -0600) it happened "Tim Williams"
<tmoranwms(a)charter.net> wrote in <hidu66$lac$1(a)news.eternal-september.org>:

>Heh, when writing assembly in BASIC (QB specifically), I often assign
>everything to an array then execute it. e.g.,
>
>DIM Code(10) 'AS INTEGER implied by DEFINT A-Z
>Code(0) = &H1234
>...
>Code(10) = &HF00F
>
>DEF SEG = VARSEG(Code(0))
>CALL ABSOLUTE(VARPTR(Code(0)), stuff)
>DEF SEG
>
>That looks ugly after more than a few lines, so most of the time I read from
>a file as a first-run initialization. Also lots easier to maintain. Fine
>for simple routines that don't need to change.
>
>I don't really like DATA, it's the idea of having something and no way to
>access it. I suppose assigning entries of an array is the closest thing to
>predefined data (as in C or ASM), but I'm willing to bet it still executes
>an awful lot of lines to do it. Stupid QB...
>
>Tim

I am not very familiar with all those BASIC dialects, but the 8052AH has MCS-52 BASIC build in ROM.
It has some limitations on array size I think.
It also has the 'CALL" instruction, that selects the correct register bank, and then calls asm from BASIC.
The procedure is then :

10 ....init stuff ----
20 call 1000 : REM code to RAM at org 6000H
100 ... main program ...
200 ... do something ...
300 xby(7000h)=A : REM some data to RAM for the ASM
310 CALL 6000H : REM call the asm routine
320 B=xby(7000H) : REM get data from RAM from the asm
400 ... do something ...
500 end

1000 rem code from q2
1002 data 18,96,4
1004 data 34
1006 data 146,0
1008 data 34
1010 org=24576
1012 for i=0 to 6
1014 read a:xby(org+i)=a:next
1016 return


I did a I2C driver that way long time ago, lost the asm source (5/14/ inch floppies),
first wrote a program to convert data in BASIC data statements to a binary file,
then ran an open source 8051 disassembler on the binary.
That gave me back the original asm, and then changed that very unclear asm code
so it was my original code and added comments each line....
When disassembling it with
D52 8052 Disassembler V3.4.1
Copyright (C) 1995-2007 by J. L. Post
Released under the GNU General Public License Version 3
and assembling it again with my own assembler, the generated code was different. :-(

So I tried an other open source assembler, and that was even more different.
Then I looked in the manual for MSC BASIC and it was again different....
Anyways, I could no longer find the bit to register mapping for that chip to check,
until late last night (Sunday night), and of course the error was in my assembler's
handling of bits in a register, so I fixed that and made a new release.
The old release was from 1988, hardly ever used....
21 yeas for a bug to live, every code worked perfectly, just that the bits flipped
were somewhere else then where you though they were...
With so much on chip RAM (256 bytes), never noticed!
That is why disclaimers are added to the released code...

I am thinking about adding the asm instructions as REM statement after the DATA fields like this:
1000 rem code from q2 at 6000h
1002 data 18,96,4 : REM lcall mysub
1004 data 34 :REM ret
1006 data 146,0 : REM mov $20.0,c
1008 data 34 : REM ret

Makes it more clear in case I lose the asm again :-)