AMAC Info (original) (raw)

+, -, /, * ; add, subtract, divide, multiply
NOT - bit by bit complement
AND - logical and
& - same as AND
OR - logical OR
XOR - logical exclusive OR
= logical equal, also EQ
<> not equal, also NE
< less than, also LT
> greater than, also GT
<= less than or equal, also LE
>= greater or equal, also GE
SHR right shift n bits
SHL left shift n bits

***Brackets [] (not parenthesis) set precedence levels.***

As you'd expect, there are IF and ENDIF statements to use the logical tests and conditionally skip sections of code.

There's a PROC ... EPROC feature to allow defining procedures, which just means local symbol ranges. Local labels must start with a colon. I use it because on big files it gets hard to think of unique labels for jump targets, etc, after you've used a zillion of them. Within a PROC you can assign local labels accessible only within the PROC and reusuable elsewhere. Like this:

; Copy the character set down to
; $4000:

PROC
LDA #$40
STA :MVCH+5; Init self altering
LDA #0; code.
STA :MVCH+4
STA :MVCH+1
LDA #$E0
STA :MVCH+2
:LOOP LDY #0
:MVCH LDA $E000,Y; Get char from ROM
STA $4000,Y; put it into RAM
INY
BNE :MVCH; Done with a page?
INC :MVCH+2; Increment pages, ROM
INC :MVCH+5; and RAM
LDA :MVCH+2; Done all 4 pages?
CMP #$E4
BNE :MVCH; If not, loop...
LDA #$40; Point CHBAS to new base:
STA $2F4
STA $D409; Hardware CHBASE

; Now make return and carat print
; as spaces:

LDY #7
:LP2 LDA #0
STA 41F0,Y;41F0,Y; 41F0,Y;41F0 starts ^
LDA #$FF; Return prints inverse
STA 42D8,Y;42D8,Y; 42D8,Y;42D8 starts ret.
DEY
BPL :LP2
EPROC

The ORG statement is used to tell the assembler where in memory to put the code it generates. Therefore, there's got to be an ORG statement in the program before any code or data statements. You can also put in additional ORGs if you need to make the code discontinuous.

Also, the star * is the current value of the location counter: it's the value of the next memory address the assembler is going to use. See the ORG in the program starting below:

; KEYER
; An electronic keyer program by
; Nick Kennedy. Begun: 5/17/87.
; r1.1: I moved the ORG up to $8000 to
; get out of the EMDE expansion window
; because MYVBI and the new DLIST have
; NMI's which may occur during RAMDISK
; I/O, causing lockup. Could just get
; the VBI AND DLIST out if space were
; a problem.

; POKEY TIMER AND AUDIO USAGE:
; TV sidetone source: Channel 3
; Sidetone via console spkr: Ch. 4

; Code element timer (16 bit res.):
; Channel 1 into Channel 2, IRQ from
; Channel 2. Note: Hi byte to 2; Low
; to 1.
VTIMR4 EQU $214
VTIMR2 EQU $212
FPREG EQU $CB; Point to speed/ratio
KBAT EQU $4D; OS sets to 0 when key
; pressed.
ATRCT EQU $4F; My attract flag. Go
; to attract mode when b7 is set.
; BMESS is the start of the message
; storage area. Note there is a $1000
; byte limit (4K) due to ANTIC scroll
; counter limit.
BMESS EQU $3000
; TBUF is the 256 byte transmit buffer
; for the keyboard sender...
ORG $8000
TBUF EQU *-$100

; INITIALIZE:

INIT: JSR POKINI

You can see above, I ORG'd the program to 8000,thenusedtheprogramcountertocomputeanaddress8000, then used the program counter to compute an address 8000,thenusedtheprogramcountertocomputeanaddress100 bytes lower to use for a buffer. The program will start at $8000 which is the value of label INIT and contains the code, JSR POKINI.

Oh yeah, you can have INCLUDE files. This means you can break your source code down into multiple files and a statement within one file will cause the assembler to open another and resume assembly there:

INCLUDE D2:FILE2.SOR

for example. At one time, I had a shell type executive source file which just had and ORG and a few equates, then half dozen INCLUDE statements to bring in other files, then an END statement. Now I use emulators and PC editors which aren't daunted by big files, so I don't split `em up anymore. There can be other reasons to split files up, though.

Getting back to pseudo-ops that declare memory space or data storage...

DB is flexible in storing single or multiple bytes or
character strings.
DB 100 ; store single byte 100
DB 1, 7, $25 ; store three bytes (separate in the DB
statement by commas)
DB `Howdy', $9B ; store a string, followed by a byte
MWEN DW BMESS + 320; End of M-window

; Above stores a word with calculated value of BMESS +
320 and assignes the label MWEN to it.

Note that labels don't have to end in colons, although
they can if you are used to that style.

DB HIGH MWEN ; store high byte of word MWEN

Note again that EQU and = don't actually cause
anything to be stored in memory, but DB and DW do.

Numbers of different bases:

Use % for binary, as in %11001010
Use $ for hex, as in $01FF
Use plain for decimal, as 300
Use @ for octal as in @212 (why use octal? don't know)

Symbols (labels) must be unique in first 6 chars (others are ignored). Must start with a letter or number, or colon for local. Can start with ? and be excluded from reference map.