David,
The parser has defined the label "Var", which the assmebly is expecting to be deifned and PC realtive. The label can appear before or after it's use, but.. Since it's PC relative it must be within a 16bit range (signed) of where it's used.
Since the assembler will not store the absolute address of this variable in memory, but it's offset from where the PC is currectly executing (the LEA opcode), it creates the A0 pointer by basically going A0 = PC + offsetToVariable.
if it were an absolute LEA you could just
Lea.l MyVariable,a0
So you could (define the variables first)
=======================
Bra Start ; skip the data segment
MyVariable: Dc.l 0 ; Define space for a long
Start:
move.l #2,D0
move.l D0,-(SP)
move.l #3,D0
add (SP)+,D0
lea MyVariable(PC),A0 ; << load relative address to MyVariable into A0
move.l D0,(A0)
brk ; force an exception (halt program)
or (define it after),
==========================
move.l #2,D0
move.l D0,-(SP)
move.l #3,D0
add (SP)+,D0
lea MyVariable(PC),A0 ; << load relative address to MyVariable into A0
move.l D0,(A0)
brk ; force an exception (halt program)
MyVariable: Dc.l 0 ; Define space for a long
A better solution would be use a format as RS structures for variables.. This is most compiler like SASC on the amiga do. This means that a register is used as the base addfress of the variable stack
I.e.
Variables:
Blk.l NumberOfVariables ; Define Space for the cleared block LONGS, at the label Variable
At the start of your code, you LEA this into an address register, like A5, A6 say
Lea.l Variables,A5
Next whenever you generate variable access, rather than LEA'ing the absolute address of the variable and then doing a move (LEA's are around 6->8 clock cycles, and two register moves to memory are a bit less, probably 4 clocks.. ).. you can use a fixed 16bit offset to the A5 register.. The compiler just needs to translate that variable name, into it's index on the variable stack.
I.e.
MOve.l #10,(a5) ; move 10 into the first variabe
Move.l #20,1*4(a5( ; move th 20 into the second variable
Etc..
rather than
Lea.l MyVariable(pc),a0
move.l #10,(a0)
Lea.l MyOtherVariable(pc),a0
move.l #20,(a0)
On the 68000 and 68010 there are some opcodes that are not supported in this format, but ya get that
68020 and above support up to 32bit offsets..
LearnToCode with Kevin Picone at www.PlayBASIC.com