home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
alib
/
d5xx
/
d592
/
ezasm.lha
/
EZAsm
/
EZAsm.doc
< prev
next >
Wrap
Text File
|
1992-01-31
|
27KB
|
1,247 lines
EZAsm Version 1.6 September '91 by Joe Siebenmann
DISCLAIMER:
The following only applies to EZAsm, ez.lib, funcnm2, funcdat2,
and related .doc files. ( A68k & Blink have their own
distribution policies )
You have the right to freely use, copy and distribute this program
as long as the following conditions are met:
1. The documentation is included with the program, and neither
is modified in any way.
2. The program is not included in any package for profit
unless written consent from the author is obtained.
NOTE: The author does not accept any responsibility for any damage
that might result from the use of this program.
--- New for Version 1.6 ---
o All 2.0 functions are now supported.
o Output is now completely compatible with, and will
assemble without changes under: A68k, Manx, and Lattice.
( for Lattice, change the extension from ".asm" to ".a" )
o Bug fixes:
- Problem with conditional assembly statements, and
macros ( IFD/IFND ENDC, MACRO ENDM ) placed before "END".
- Problem with generating .asm files greater than 32,767
bytes. Thanks to Jan Geissler for reporting the bug.
- Problem calling EZAsm with no arguments.
o Mk ( Make1 ) now has support for an optional include path for
A68k, and support for a .mak file.
o Additional improvements and optimizations.
EZAsm was written to make programming in 68000 assembly
language much easier! EZAsm combines parts of "C" with
68000 assembly, giving it the "feel" of a higher level language.
The resulting code is optimized as much as possible.
A68k ( by Charlie Gibbs ) and Blink ( from The Software Distillery )
are included, and the offsets for all the 2.0 functions are
internal, so you'll have everything you need to start
producing executables ( except the include files ( if you need them )).
Here are some of its advantages:
o Your code is converted into the fastest possible
assembly statement(s), so you automatically write
"good" code.
o More structured. Compare and bit test statements can have
braces and "else" like "C". Being able to use braces lets
you use assembly in a whole new way!
o "C" like Amiga function calls! Every 2.0 function in every
library is supported.
o Your code is much more readable, and easier to debug.
You can code nearly twice as fast, with fewer syntax errors.
o No more having to constantly look up which condition code to
use for compares, bit tests, or maximum numbers for
"moveq" or "addq" etc.
o You can freely mix "EZAsm statements" and normal
assembly statements.
You need to know a little about assembly language and
"C" operators before you dive right in. If you're new to
68000 assembly language, I suggest looking at one of the
many available books on the subject. The included example
source programs can give you a good idea about:
o General statement syntax.
o Use of "l", "w", "b" size arguments.
o Using assembly statements in your code.
****************************************
Using EZAsm:
1. Create a directory, and copy these files into it:
EZAsm, A68k, Blink, Mk, ez.lib, funcnm2, funcdat2
2. CD into your new directory, and you're ready to go!
( Another good method is to create an ALIAS to load these
files into VD0: and work from there )
Mk
Mk is a "make" like program, written in EZAsm, that will
Execute() the necessary programs for you, creating an
executable file with a minimum of effort. It also
supports an optional include path for A68k, and support
for a ".mak" file. The source code is included.
With include path:
Mk -iPathToIncludes file
Without include path ( also for .mak ):
Mk file
( where "file" is your source file with path if needed
( No extension ))
Execute()'s these commands:
ezasm file.s
a68k [-iPathToIncludes] file.asm
blink FROM file.o LIBRARY ez.lib TO file
.mak
For times when you need to supply more options for A68k
or Blink, Mk now supports a .mak file. Just create a file
with the same name as your source file, but with a ".mak"
extension. The file should contain the EZAsm, A68k, and
Blink commands with any options/switches you need, as if
you were entering them from the CLI. Any comments should
begin with a non-alpha character. If Mk finds the .mak
file, it will Execute() those commands, otherwise it will
Execute() the standard commands.
************************************
* Operand Table *
************************************
Operand Type
Mode [A] [B] [C] [D] [E] [F]
Dn * * * - * -
An * - * - - -
(An) * * * * * *
(An)+ * * * * * *
-(An) * * * * * *
d(An) * * * * * *
d(An,Xn) * * * * * *
16 bit addr * * * * * *
32 bit addr * * * * * *
d(PC) * - - - * *
d(PC,Xn) * - - - * *
immediate * - - - * -
declared variables:
"foo" becomes "foo(a5)" ( d(An) )
**************************************
#<1> 1 - 8
#<2> 0 - 7
#<3> 0 - 31
#<q> -128 - 127
#<any> any byte, word, or long size number
Dn d0 - d7
An a0 - a7
{B} byte data size not allowed for An operands
********************************************
* legal * converted * legal *
* operands * to * sizes *
********************************************
Addition Subtraction
++
--
[C] <op> addq/subq L,W,{B}
+=
-=
Dn <op> [A] add/sub L,W,B
[D] <op> Dn add/sub L,W,B
An <op> [A] adda/suba L,W
[B] <op> #<any> addi/subi L,W,B
[C] <op> #<1> addq/subq L,W,{B}
Examples:
Total ++
d1 += 10
Optional Args:
l, w, b
********************************************
Multiplication Division
*=
Dn *= [E] mulu W
Dn *= ## * W
/=
Dn /= [E] divu W
Examples:
d0 *= d1
d2 /= 2
Optional Args:
w,
s ( signed divs/muls )
* This optimization results in code that's larger then "mulu"
or "muls", but will execute much faster. Not all numbers
can be optimized. If the number doesn't work, "mulu"
or "muls" will be used.
( where ## is a word or byte length number )
*********************************************
And Or Exclusive Or
&=
|=
[B] <op> #<any> andi/ori L,W,B
Dn <op> [E] and/or L,W,B
[D] <op> Dn and/or L,W,B
x=
[B] x= Dn eor L,W,B
[B] x= #<any> eori L,W,B
Examples:
Mask &= %11010000
Flags |= $f0
Optional Args:
l, w, b
*********************************************
Shift Left/Right
<<
>>
Dn <op> Dn lsl/lsr L,W,B
Dn <op> 1-31 * lsl/lsr L
Dn <op> 1-8 lsl/lsr L,W,B
[D] <op> 1 lsl/lsr W
Examples:
d2 << d0
d1 >> 4
Optional Args:
l, w, b,
a ( arithmetic shift asl/asr )
* Normally you're limited to shifting 1-8, or using a
data register to hold higher. This optimized version
is faster, and saves using a data register!
( logical shift only )
*********************************************
Assign
=
[B] = [A] move L,W,{B}
An = [A] movea L,W
Dn = #<q> moveq L
Examples:
temp = Total
(a1)+ = 0 w
Optional Args:
l, w, b
********************************************
Compare
>=
<=
!=
>
<
=
Dn <op> [A] cmp L,W,{B}
An <op> [A] cmpa L,W
[B] <op> #<any> cmpi L,W,B
(An)+ <op> (An)+ cmpm L,W,B
Syntax types:
[opr] <op> [opr] label
[opr] <op> [opr] {
.
.
}
[opr] <op> [opr] {
.
.
} else {
.
.
}
Examples:
Total >= 100 Over
Buf != 0 {
FreeMem( Buf 100 )
}
Optional Args: ( placed AFTER label or brace )
l, w, b,
s ( signed )
*********************************************
Bit test
Dn:0-31 = 0-1 btst.l L
Dn:Dn = 0-1 L
[F]:0-7 = 0-1 btst.b B
[F]:Dn = 0-1 B
Syntax types:
[opr] <op> [opr] label
[opr] <op> [opr] {
.
.
}
[opr] <op> [opr] {
.
.
} else {
.
.
}
Examples:
d1:0 = 0 EvenRtn
($bfe001):6 = 0 LMBDown
d2:d0 = 1 {
rts
}
Optional Args:
( ignored )
Rules:
o No spaces inside first operand.
o Only "=" is allowed.
o Right operand can only be 0 or 1.
*********************************************
Additional Arguments:
b forces operation to be byte
w " " " word
l " " " long
a arithmetic shift ( <<, >> )
s signed ( *=, /=, compares )
( these are RESERVED and can't be used as variables, or labels
( unless you use upper case ) )
*********************************************
Functions:
Syntax examples:
CloseWindow( Window )
Buf = AllocMem( 512 #CLEAR_PUBLIC )
Permit( )
Example:
--------------------------------
CLEAR_PUBLIC equ $10001
OLDFILE equ 1005
LONG _DosBase FHandle num Rbuf
_DosBase = OpenLibrary( "dos.library" 0 )
beq Exit
Rbuf = AllocMem( 100 #CLEAR_PUBLIC )
beq Exit
FHandle = Open( "df0:myfile" #OLDFILE )
beq Exit
d3 = 100 ; preload D3 *1
num = Read( d0 Rbuf * )
.
.
.
*1 normally you wouldn't need to do this, it's only an example..
---------------------------------
o All 2.0 functions are now supported.
Don't worry, the older 1.3 functions are still there.
Some 2.0 functions are "for internal use only",
some "OBSOLETE", some functions may have been deleted,
or added. Check "funcnm2" for supported function names.
( AllocWBObject( ), FreeWBObject( ), GetWBObject( ),
PutWBObject( ) in IconBase, are listed as "OBSOLETE"
but are still included )
o You must first do an OpenLibrary( ) to access functions in
a library. Functions in ConsoleDevice are accessed
differently, see the ConsoleDevice section in the RKM p 662.
( load the io_Device field into "_ConBase" )
Functions in ExecBase ( SysBase ) are always accessible and don't
need to be opened.
The library bases MUST be named:
_AslBase
_BattClockBase
_BattMemBase
_ConBase
_CxBase
_DiskBase
_DiskfontBase
_DosBase
_ExpansionBase
_GadToolsBase
_GfxBase
_IconBase
_IFFParseBase
_InputBase
_IntuitionBase
_KeymapBase
_LayersBase
_MathBase
_MathIeeeDoubBasBase
_MathIeeeDoubTransBase
_MathIeeeSingBasBase
_MathIeeeSingTransBase
_MathTransBase
_MiscBase
_PotgoBase
_RexxSysBase
_TimerBase
_TranslatorBase
_UtilityBase
_WorkbenchBase
o Unfortunately the leading underscores are necessary so you can
use includes without your assembler complaining. Some library
bases are already defined in some .i's resulting in
"multiply defined symbol" errors.
o You might notice that ExecBase is missing. It isn't needed.
( it's loaded with "movea.l $4,a6" )
Permit( )
OpenLibrary( "dos.library" 0 )
^ ^ ^
no space | | space | space
o The function name must be followed immediately with "("
( no spaces between ) and then followed by a space or tab.
If the function has no arguments, it still needs a space in
the middle. Arguments must be separated with a space or tab.
ReturnVar = AllocMem( FSize $10001 )
o All variables used in function calls, return variables or
function arguments, should be LONG.
a2 = ViewAddress( )
d1 = Read( "myfile" Buf BufLen )
o Address or data registers can also be used for returns
if they're more convenient.
( returns to D0 are now ignored, as it produces a useless
"move.l d0,d0" instruction )
o Several people were concerned when their OpenWindow( ) and
OpenScreen( ) calls crashed. The included example source
"scrwin.s" opens a screen and a window, and is a good
"base" for starting similar programs. Problems occur
when the NewWindow fields "IDCMPFlags" and "Flags" are
incorrectly switched, or fields arn't aligned.
( not word aligned at the start, or fields the wrong size )
( also include any filler "kludge" bytes, as they're also
important for field "alignment" )
Arguments:
o If your argument is already in a DIFFERENT data or address register,
you can pass it as an argument directly. Often a previous function
will put results in D0, so just pass d0. If the proper
register is already loaded, just pass "*".
( if you pass it the same register it uses, it'll be skipped.
func defined as: D0 = Lock( D1 D2 ) "Flock = Lock( d1 -2 )"
arg "d1" will be skipped )
o EZAsm supports argument strings surrounded by double quotes.
The following "C" character constants are supported:
\b backspace
\f form feed
\n newline
\r carriage return
\t horizontal tab
\v vertical tab
examples:
"Hello, World!\n"
"\t\tHeading\n"
( strings are automatically null terminated )
NewWin ds.w 0 ;align
dc.w 0,0,640,200
dc.b -1,-1
.
.
o To load a pointer to a NewWindow or other "structure" you've
defined use: #NewWin ( etc. ) it'll load its address into
a data or address register.
o if you need a pointer to one of your declared variables
( where the argument goes to an address register ) use:
&foo ( address of "foo" )
( output as "lea foo(a5),An" )
( "&" is ONLY recognized inside function arguments )
o Sometimes you have to "play around" with using "#", "&", variables,
constants etc. You might be giving it the contents of a variable,
when it needs its address ( etc. )
All functions within these 2.0 libraries are supported:
AslBase
BattClockBase
BattMemBase
ConBase
CxBase
DiskBase
DiskfontBase
DosBase
ExecBase ( SysBase )
ExpansionBase
GadToolsBase
GfxBase
IconBase
IFFParseBase
InputBase
IntuitionBase
KeymapBase
LayersBase
MathBase
MathIeeeDoubBasBase
MathIeeeDoubTransBase
MathIeeeSingBasBase
MathIeeeSingTransBase
MathTransBase
MiscBase
PotgoBase
RexxSysBase
TimerBase
TranslatorBase
UtilityBase
WorkbenchBase
o It keeps track of the current library base. As long as no user
labels, or close braces ("}") are hit, it will skip reloading
the base register for functions which use the same
library base.
o The file "funcnm2" contains a list of every function that is
supported.
*********************************************
Optimizations:
In addition to the many "normal" optimizations performed
on statements, the following are also performed:
STATEMENT BECOMES NOTE
An = 0 sub.l An,An
[B] = 0 clr [B] 1
( compares )
[B] < 0
[B] >= 0 5
[B] = 0
[B] != 0 tst [B]
bxx label
----------------------------------
[B] += #<q>
[B] -= #<q>
[B] &= #<q>
[B] |= #<q>
[B] x= #<q>
[B] = #<q> moveq #<q>,d7 2
[opr].l d7,[B]
( compares )
Dn <op> #<q> moveq #<q>,d7 2
cmp.l d7,dn
bxx label
An <op> #<q> moveq #<q>,d7 2
cmpa.l d7,an
bxx label
----------------------------------
An += #1 lea n(An),An
An -= #1 lea -n(An),An 3, 2
An = #<any> lea n,An 4, 2
#1 = maximum: -= 32768 += 32767
Notes:
1 For byte and word sizes the code size is smaller, for long,
its smaller and faster. ( then "move #0,[B]" )
2 Only apply to long sized operations.
3 ( 1-8 handled by "addq", "subq" )
4 ( 0 handled by "sub.l An,An" )
5 Taken as signed.
*********************************************
General Info:
o Statements can be indented as you like. Operands, operator,
and arguments must be separated by at least one space or tab.
o Braces can be nested up to 30 deep.
o Only one statement per line.
o If you declare variables or use function call's, the first statement
in your code must be an "EZAsm statement" so it knows when
to insert the XREF's and/or get stack frame for the
variables. Comments, assembly directives, or assembly statements
placed between your variables and the start of your code will be
OUT OF PLACE in the output file.
o Comments must begin with "*" or ";" and begin at column 1, or after
statements ( separated from last argument or operand ) using ";".
( both types are transferred to output file ( some may not ))
o Operands supported: @141 (octal), $61 (hex), %1100001 (binary),
'a' (ASCII), 97 (decimal). ASCII strings in operands can
contain a maximum of 4 characters.
( no quotes within quotes permitted )
o To make labels and symbols as compatible as possible, they arn't
checked for illegal characters. Typically the 1st character
must be a letter, underscore "_", or a period "." .
The rest of the characters can be any of these plus 0-9.
o Labels and symbols are limited to a length of 127.
( Check your assembler to find what length they're
significant to ( usually around 30))
o Labels that don't begin at column 1 should be followed immediately
with ":".
o Temporary labels of the form n$, where n consists of decimal
digit(s), are supported. These labels are only in effect till
the next non-temporary label is encountered. ( be careful
of "hidden" labels generated by braces )
o No need to put in the usual "moveq #0,d0", "rts" at the end of your
code, its part of the closing block of code it inserts.
o D7 is used as a scratch register for some optimizations, so be
careful if you use it.
o Labels that it generates for braces are in the range
".laaa" to ".lzzz" so try to avoid using them.
( upper case is OK )
o Constants generated from argument strings are in the range:
.c0 to .c0+n . Matching strings are not duplicated.
o "SP", "PC", "CCR", "SR" & "USP" ( upper or lower case )
are supported, but you must ensure the size is legal etc.
o For best viewing of output file set your tabs to 8 spaces.
( printing should be fine )
IMPORTANT! :
Use of register A5 is RESERVED!
( it contains the base address for variable storage )
*********************************************
Variable Declaration:
LONG foo Save[10] bar
WORD DMASave
BYTE Sw
o "xxx[n]" reserves n consecutive blocks of given size,
with "xxx" pointing to left-most byte.
( this is for advanced users who need a convenient
way to allocate SMALL chunks of memory for saving
registers etc. )
o You're limited to 14 variables per line.
o No other statement types may occur between these lines.
o Variables must be separated by at least one space, or tab.
o To keep things word aligned, if an odd number of bytes are
declared in BYTE, an extra byte will be added.
( this will offset the next "equ" by one )
o Must occur JUST BEFORE your program code.
o Must begin at 1st column, with LONG, WORD, or BYTE in upper case.
o EZAsm uses "link" to allocate space for variables on the stack.
The maximum size of this space is 32K. Since this stack space
contains "garbage", code is added to clear it out before use.
( A0 and D0 are not disturbed )
What the stack frame looks like:
LONG foo
WORD bar Total
LONG Cnt
becomes...
foo equ -4
bar equ -6
Total equ -8
Cnt equ -12
h l A5 base register
i o |
OOOO OO OO OOOOO memory bytes
(-) 1119 87 65 4321
210
( Sometimes variables are "adjusted" for proper loading, and
"-2(a5)" or other displacement may appear in the output file
instead of "foo(a5)" or other variable you might be expecting. )
*********************************************
How to get what you need, hints, etc.:
END
Data statements ( "dc.b", "ds.l" etc. ) should be
placed BELOW the "END" statement. Any string
constants which are generated will also appear
below the "END". Other "data" statements
( "equ", "xref", "xdef" etc. ) can be placed ABOVE
your variables, or BELOW "END".
( In the output .asm file "END" will be adjusted )
o Instruction size: In most cases you WON'T NEED
A SIZE ARGUMENT. It knows the size of your variables,
address and data registers, and is smart enough to know
what size to use. It determines the size of data by it's
actual value not its physical size.
( $0020 %11010000 $12 125 are all BYTE size )
If the data is smaller than the instruction size you want,
( d1 = $20 w ) or it can't know an operands size
( (a2)+ = 3(a0) l ) you'll need to give it a size argument.
Caution: Be aware that if you load small variables into
larger ones, the upper bytes arn't cleared and
may garbage your result. Always initialize your
variables or restrict the size of the operation to
"b" or "w".
o Try not to overuse the size arguments. Once you get confident
it's sizing your instructions correctly ( by checking the
.asm file ) you'll find you can eliminate their use almost
entirely! By needlessly restricting a long operation to
a word, or byte, you can miss the "quick" optimization.
o Since "(a1)" refers to the CONTENTS of the byte, word, or long
that A1 points to, "($dff180)" is used in a similar way.
"d0 = ($dff01e) w" is converted to "move.w $dff01e,d0"
( decimal addr's are also valid: "(14675968)" )
o When numbers are used as operands "$fe02" or "37", they are
converted to "#$fe02" and "#37". Operands that it
doesn't recognize ( doesn't match with any declared
LONG, WORD, BYTE, or standard "(a1)+" etc. ) get output
as is. This is very useful when you need operands
like: "#NewWin", "wd_UserPort(a1)", "$20(a1)", "DMACON(a6)"
o Most instructions set condition code flags on the result of the
operation. Often, instead of using a compare to check the
result, you can use a branch on condition instruction ( "beq",
"bne" etc. ) to jump to a location on the state of a condition
code flag. You need to check which flags are set ( if any )
for an instruction.
o If at any time you're unsure of what a statement is being
output as, or want to check something out, just look
at the output file. Well placed blank lines in your source
code can enhance its readability.
o I think it's a good idea to get away from using include files.
Most assembly source files I see do this.
It speeds up the assembler tremendously, and saves
endless wear and tear on your drives.
*********************************************
Converting C to EZAsm:
Its fairly easy to convert any C code into
EZAsm if you follow these guidelines:
Allocating structures:
Whenever you see "struct VSprite SpriteA" etc.,
you need to either allocate some memory for the
structure, or set up your own:
CLR_PUB equ $10001
LONG SpriteA
SpriteA = AllocMem( [structure size] #CLR_PUB )
beq Exit
---------- or ----------------
SpriteA ds.w 0 ;align
dc.l 0 ;NextVSprite
dc.l 0 ;PrevVSprite
.
.
( you could use "#vs_SIZEOF" etc. for [structure size]
and let the assembler get its size from the includes )
Some functions will create the structures for you
and return a pointer to it ( OpenWindow( ), OpenScreen( )
etc. ) just declare a LONG, and load the returned pointer:
LONG Window
Window = OpenWindow( #NewWindow )
beq Exit
Referencing structures:
Often you'll need to get at data inside structures.
First load the "structure pointer" into an address
register, then use the offset of the structure element.
Here's a typical example:
Move( Window->RPort, 20, 20 ); /* C */
a0 = Window
Move( wd_RPort(a0) 20 20 )
---- or ----
a0 = Window
Move( 50(a0) 20 20 )
( add an include to your source, and the assembler
will look up "wd_RPort" and substitute its offset or,
if you have access to the offsets, use "50(a0)"
instead of "wd_RPort(a0)" )
( it's Ok to use the same address register )
a0 = Window
a0 = wd_RPort(a0)
Loops:
I've often thought about trying to add at least a
while( ) like statement, but it's just as easy
to "code-your-own":
for ( foo = 0; foo < 10; foo++ ) { /* C */
}
LONG foo
foo = 0 ;initialization statements..
Again: . ;body..
.
foo < 10 { ;test, and other statements..
foo ++
jmp Again
}
Info:
If you try converting statements one-for-one
in C code that has lots of loops and complex
statements, you can end up pulling your hair out,
and end up with tons of code. In cases like
this, take a step back, and try to figure
out the "idea" of what's going on, or what
the final result will be, THEN try to think
how you'd code it using EZAsm.
*********************************************
Errors:
"Illegal argument"
The argument found was not valid for the operator. See
the list of "Optional Args" for the operator. It must
be lower case, and be separated from the operands
by at least a space or a tab.
"Illegal operand"
One, or both, of the operands are: not valid for the operator,
have an invalid number, or byte size was specified for an
"An" operand ( {B} ). In most cases it's looking for "Dn" or "An"
as one of the operands. ( look under the "legal operands"
of the operator for a valid combination )
"Illegal size"
The argument size you specified is not valid for the operator.
Check the "legal sizes" for the operator.
"Needs size argument"
It doesn't have enough size information about the operands to
calculate an instruction size.
You need to add an l, w, or b argument.
"Label not found"
No label matching your label argument was found.
"Brace mismatch"
Checks are made when a closing brace ( "}" ) is hit, and when "END"
is hit. If the brace stack is "messed up" at that time, an error
is given. If "}" is shown, look from there up. Both "}" and "END"
may appear. If just "END", look for a "{" or "} else {" without a
matching "}".
"Function not found"
No function matching your function name was found. Check case and
spelling of function name, and be sure there isn't a space before
the "(". Check the list of supported function names in the
file "funcnm2".
"Function argument count incorrect"
Check the number of arguments you used for the function. Too many
or not enough were used. With string arguments, check for
a missing '"'. Also look for a missing end ")".
( EZAsm doesn't do much checking of normal assembly statements.
A68k and Blink will catch any problems missed by EZAsm and bring
them to your attention )
*******************************************************************
*******************************************************************
Try using it, I think you'll like it! 8^)
I'm always trying to improve EZAsm, and I'd really like
to hear any ideas you have on making it better,
even your complaints. So if you've found an
"undocumented feature", or there's something you'd like
to see in a future version, I'd be happy to hear from you.
Enjoy!
You can reach me at:
Joe Siebenmann
8303 Old Tree Court
Springfield, VA 22153
( USA )
(703) 455-4982