Matt139 / ASM68KvsAS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ASM68K and AS. What's the difference?

Directives

ASM68K AS Purpose Example
equ equ Define a value once. Forward references allowed.
label: equ 1+2+3
constant Same as equ with different syntax.
constant label,1+2+3
set or = set or = Define a reusable value. Forward references not allowed.
label: = 1+2+3
equs Define a reusable string. Forward references not allowed.
Single or double quotes work. To include quotes in the string, use '' where the quote should be.
label: equs "string"
label2: equs 'it''s a nested quote'
equr reg Define label to represent a register.
label: equr d0
reg Define label to represent a series of registers for use with movem.
label: reg d0-d7/a1-a2
rsset and rsreset Sets the value of __rs.
rsset $100
rsreset ; __rs = 0
rs Assigns the value of __rs to a label, and advances __rs by the specified amount.
rsset $100
label: rs.l $10 ; label = $100; __rs = $110
alias and disable Change the names of constants and functions, allowing them to be redefined.
sqrtnew: alias sqrt
disable sqrt
charset Redefine the value of an ASCII character. Use without parameters to reset all characters to default.
charset 'a',255 ; a = $FF
charset ; a = $61
codepage Switch between named ASCII character sets. STANDARD is default.
codepage new
charset 'a',255 ; a = $FF
codepage STANDARD ; a = $61
enum and nextenum Define a series of values which increment. Starts at 0 unless specified. nextenum continues the same series on another line.
enum x,y,z
dc.b x,y,z ; same as dc.b 0,1,2
enumconf Change the increment for enum.
enumconf 2
enum x=2,y,z
dc.b x,y,z ; same as dc.b 2,4,6
save and restore Saves current cpu, codepage and other things.

Data

ASM68K AS Purpose Example
dc.b, dc.w and dc.l dc Writes a series of bytes, words or longwords. In ASM68K, the automatic even option (ae+) ensures words and longwords are aligned to word.
dc.b 1,$20,-$30
dcb Writes a series of bytes, words or longwords of single value.
dcb.b 5,1 ; same as dc.b 1,1,1,1,1
ds ds Writes a series of bytes, words or longwords of value 0.
ds.b 5 ; same as dc.b 0,0,0,0,0
hex Writes a series of bytes.
hex 010203 ; same as dc.b 1,2,3
datasize and data Writes a series of bytes with padding. datasize can be 1 to 256.
datasize 4
data 1,2 ; same as dc.l 1,2

Program counter control

ASM68K AS Purpose Example
org org Changes program counter to start writing anywhere.
Broken in ASM68K - always goes to 0.
org $100 ; goto address $100
rorg Add value to program counter. Can be negative.
rorg $100 ; goto *+$100
even Align to word.
dc.b 1,2,3
even ; same as dc.b 1,2,3,0
padding Always align to word when turned on.
padding on
padding off
cnop x,y Align to y and append x bytes. x can be 0 but y cannot.
cnop 2,16 ; align to 16 and append 2 bytes
obj and objend phase and dephase Makes program counter believe it's at an address, without actually going there.
obj $100
dc.l * ; writes dc.l $100 to current location
objend
align Align to value.
dc.b 1,2,3
align 2 ; same as dc.b 1,2,3,0

Conditionals

ASM68K AS Purpose Example
if, elseif, else and endif/endc if, elseif, else and endif Assemble different code depending on specified conditions. endif and endc are interchangeable.
if var=0
dc.b 'var is 0'
elseif var=1
dc.b 'var is 1'
else
dc.b 'var is something else'
endc
case and endcase Alternative to if. Seems broken in ASM68K.
case var
=0
dc.b 'var is 0'
=1
dc.b 'var is 1'
=?
dc.b 'var is something else'
endcase
switch, case, elsecase and endcase Alternative to if.
switch var
case 0
dc.b 'var is 0'
case 1
dc.b 'var is 1'
elsecase
dc.b 'var is something else'
endcase
rept x and endr rept x and endm Assembles code x number of times. Useful in combination with narg in macros.
rept 3
dc.b 0 ; same as dc.b 0,0,0
endr
while and endw while and endm Assembles code repeatedly while condition is met.
equs does not work inside a while loop.
var: = 0
while var<3
dc.b var ; same as dc.b 0,1,2
var: = var+1
endw
do and until Assembles code repeatedly until condition is met.
var: = 0
do
dc.b var ; same as dc.b 0,1,2
var: = var+1
until var>2
end Stops assembly. Place at the end of the main ASM file.
ifdef x True if x is defined.
ifndef x True if x is undefined.
ifused x True if x is referenced in the code (so far).
ifnused x True if x is unreferenced in the code (so far).
ifexist x True if file x exists.
ifnexist x True if file x doesn't exist.
ifb x,..,y True if listed parameters are all blank.
ifnb x,..,y True if listed parameters aren't all blank.

Macros

ASM68K AS Purpose Example
macro and endm Defines a macro. Parameters can be named or left blank (in which case they are referenced by \1, \2 etc.
writebyte: macro num
dc.b \num
endm
writebyte 5 ; same as dc.b 5
macros Single-line macro. endm not needed.
writebyte: macros
dc.b \1
mexit exitm Exits macro prematurely.
\0 ATTRIBUTE Size parameter. Whatever is after the . when a macro is used, usually b, w or l but can be anything.
writeany: macro
dc.\0 \1
endm
writeany.l 999 ; same as dc.l 999
\@ Underscore followed by the number of times the macro has been used. Useful for creating unique labels.
setvalue: macro
value\@: equ \1
endm
setvalue 5 ; same as value_1: equ 5
\# and \$ Value of variable output as a string. \# is decimal and \$ is hex.
value: equ 5
string: equs "\#value" ; same as string: equs "5"
\_ ALLARGS All parameters, including the commas.
\* Value of label where macro was used. * must be the first parameter, and \* must be defined. Label must be on the same line.
readself: macro *
\*: equ *
self: equ \*
endm
readself ; same as self: equ *
{INTLABEL} and __LABEL__ Value of label where macro was used. {INTLABEL} must be the last parameter. Label must be on the same line.
readself: macro {INTLABEL}
self: equ __LABEL__
endm
readself ; same as self: equ *
narg ARGCOUNT Number of parameters used in a macro. AS will include all named parameters, even if they aren't used.
nargout: macro
dc.b narg
endm
nargout 1,2,3,4 ; same as dc.b 4
shift shift Deletes the first parameter and moves the rest left. Useful in combination with narg.
pushp and popp
purge Deletes a macro.
purge macroname
! AS allows redefining any instruction with macros. ! uses the original unaltered instruction.
move macro
endm
!move.b d0,d1
function Custom function. Last parameter is the expression, all parameters before that are the function's parameters.
times2: function x,x+x
dc.b times2(4) ; same as dc.b 8

Files

ASM68K AS Purpose Example
include Include an ASM file.
include "file.asm"
incbin binclude Include a binary file.
incbin "file.bin"
incbin "file.bin",$10 ; start at address $10 in file
incbin "file.bin",$10,$20 ; start at $10, include only $20 bytes

Functions

ASM68K AS Purpose Example
ref(x) Returns true if label x has been previously encountered.
if ref(label) ; false on first run, true on second
label: rts
endif
def(x) Returns true if label x has been defined.
label: equ 1
if def(label) ; true
type(x) Returns info on label x as a word bitfield.
strlen(x) strlen(x) Returns length of string x.
if strlen("text")=4 ; true
label: equs "four"
if strlen(label)=4 ; true
strcmp(x,y) Returns true if string x matches string y. Variables require quotes and backslash.
label: equs "text"
if strcmp("\label","text") ; true
instr(x,y) and instr(s,x,y) Returns position of substring y in string x (starts at 1). Returns 0 if not found. s specifies starting position.
label: equs "string"
dc.b instr("\label","r") ; 3
dc.b instr(2,"\label","r") ; 3
dc.b instr(4,"\label","r") ; 0
substr Assigns substring to variable. Actually more like a macro than a function. Its parameters are start, end (both optional) and string.
label: equs "string"
sub1: substr 2,5,"\label" ; sub1 = trin
sub2: substr 2,,"\label" ; sub2 = tring
sub3: substr ,5,"\label" ; sub3 = strin
sub4: substr ,,"\label" ; sub4 = string
bitcnt(x) Returns count of bits set in x.
firstbit(x) Returns number of the lowest bit set in x, or -1 if not found.
lastbit(x) Returns number of the highest bit set in x, or -1 if not found.
bitpos(x) Returns number of the (only) bit set in x, or fails assembly if not found.
sgn(x) Returns 0, 1 or -1 if x is 0, positive or negative respectively.
abs(x) Returns absolute value of x.
upstring(x) Returns uppercase equivalent of x. upstring("x") returns X.
lowstring(x) Returns lowercase equivalent of x.
substr(x,y,z) Returns substring of x, starting at position y and of length z.
charfromstr(x,y) Returns the character in x at position y.
strstr(x,y) Returns position of substring y in string x (starts at 0). Returns -1 if not found. Similar to ASM68K's instr().
val(x) Converts x from string to expression.
dc.b val("1+1") ; same as dc.b 2
exprtype(x) Returns type of x — 0 for integer, 1 for floating (not relevant here) and 2 for string. Similar to ASM68K's type().

Options

ASM68K AS Purpose Example
opt Sets an option. + enables and option and - disables it.
opt ae+ Enable automatic even before dc.w, dc.l and similar.
opt an+ Enable alternative numbers. i.e. those in Z80 assembly (100h, 0Ah).
opt c+ Enable case sensitivity. c- is default.
opt d+ Descope local labels? d- is default.
opt e+ Error text in command line output.
opt lx Set local label prefix to x. @ is default.
opt w+ Warning text in command line output.
opt ws+ Allow whitespace in instructions (e.g. 1 + 2). ws- is default.
opt op+ Optimise (pc) relative from long addressing if possible. op- is default.
opt os+ Optimise branches if possible. os- is default.
opt ow+ Optimise longwords to words if possible. ow- is default.
opt oz+ Optimise 0(a0) to (a0). oz- is default.
opt oaq+, osq+ and omq+ Optimise add, sub and move to addq, subq and moveq if possible. oaq-, osq- and omq- are default.
pusho and popo Save and restore options, allowing for temporary options to be used.
nolist and list Disable and enable list generation temporarily.
inform x,y,z Outputs the error message y to command line. x can be 0 (show text only), 1 (text as warning), 2 (text as error) or 3 (stops assembly). y can contain %d (decimal), %h (hex) or %s (string) which are substituted by expression z. if value>max inform 3,"Value $%h is too high.",value endc
message x and warning x Outputs the message x to command line.
error x and fatal x Outputs the message x to command line and stops assembly.
fail Stops assembly.

About