mirror of
https://github.com/byteworksinc/Linker.git
synced 2024-11-27 23:49:16 +00:00
1 line
27 KiB
NASM
1 line
27 KiB
NASM
|
keep obj/exp
mcopy exp.mac
****************************************************************
*
* Expression evaluation
*
* This module handles evaluation of expressions during pass
* 2.
*
****************************************************************
copy directPage
****************************************************************
*
* ExpCommon - global data for the expression module
*
****************************************************************
*
;
; Constants
;
maxTerm gequ 16 max # of STACKED terms in an expression
maxDepth gequ 8 max # of NESTED unresolved labels
ExpCommon data
;
; External value returned by CopyExpression
;
copiedExpression ds 2 was the expression resolved to a constant?
shiftCount ds 4 shift count (# bits to shift)
shiftFlag ds 2 is the expression shifted?
shiftValue ds 4 expression value before shift
symbolCount ds 2 count attribute
symbolLength ds 2 length attribute
symbolRelocatable ds 2 symbol relocatable flag
symbolType ds 2 type attribute
symbolValue ds 4 symbol value
symbolData ds 2 symbol data area number
symbolFlag ds 2 symbol flags
symbolFile ds 2 symbol file
expSegment ds 2 segment number for the expression
;
; Current expression information
;
expValue ds 4 expression value
expLength ds 2 expression length
end
****************************************************************
*
* CopyExpression - resolve or copy an expression
*
* Inputs:
* ep - pointer to the first opcode in the expression
*
* Outputs:
* X-A constant value or ptr to a safe copy of the expression
* copiedExpression -
* 1 -> the value returned is a copy of the expression
* 0 -> the value returned is a constant
*
****************************************************************
*
CopyExpression start
using ExpCommon
val equ 1 value of the expression
oep equ 5 original copy of ep
length equ 9 length of the expression, in bytes
done equ 13 done processing flag
sp equ 15 expression stack pointer
stack equ 17 expression stack
sub (4:ep),16+maxTerm*4
stz copiedExpression assume we can resolve to a constant
move4 ep,oep save a copy of the start of the expression
stz done not done, yet
stz sp nothing on the operand stack
lb1 lda [ep] loop over the expression, processing it
and #$00FF
asl A
tax
jsr (addr,X)
lda done
beq lb1
lda #9 if sp <> 4 then
ldx sp
cpx #4
jne TermError flag an expression syntax error
move4 stack,val set the value
lda copiedExpression if the expression is not constant then
beq lb4
sub2 ep,oep,length get some memory from the symbol table
ph2 length
jsr GetSymbolMemory
sta val
stx val+2
sta ep
stx ep+2
lda length X = # of words to copy
lsr A
tax
bcc lb2 if there are an odd # of bytes then
short M
lda [oep]
sta [ep]
long M
inc4 oep
inc4 ep
tax
beq lb4
lb2 ldy #0
lb3 lda [oep],Y
sta [ep],Y
iny
iny
dex
bne lb3
lb4 ret 4:val return the expression value
;
; Add:
;
Add anop
inc4 ep update ep
jsr Check2 make sure there are at least 2 operands
clc do the operation
lda stack-4,X
adc stack,X
sta stack-4,X
lda stack-2,X
adc stack+2,X
sta stack-2,X
rts
;
; And:
;
And anop
inc4 ep update ep
jsr Check2 make sure there are at least 2 operands
lda stack-4,X do the operation
ora stack-2,X
beq and1
lda stack,X
ora stack+2,X
beq and1
lda #1 result is true
bra and2
and1 lda #0 result is false
and2 sta stack-4,X
lda #0
sta stack-2,X
rts
;
; BAnd:
;
BAnd anop
inc4 ep update ep
jsr Check2 make sure there are at least 2 operands
lda stack-4,X do the operation
and stack,X
sta stack-4,X
lda stack-2,X
and stack+2,X
sta stack-2,X
rts
;
; BEor:
;
BEor anop
inc4 ep update ep
jsr Check2 make sure there are at least 2 operands
lda stack-4,X do the operation
eor stack,X
sta stack-4,X
lda stack-2,X
eor stack+2,X
sta stack-2,X
rts
;
; BNot:
;
BNot anop
inc4 ep update ep
jsr Check1 make sure there is at least 1 operand
lda stack-4,X do the operation
eor #$FFFF
sta stack-4,X
lda stack-2,X
eor #$FFFF
sta stack-2,X
rts
;
; BOr:
;
BOr anop
inc4 ep update ep
jsr Check2 make sure there are at least 2 operands
ld
|