1
0
mirror of https://github.com/pfusik/xasm.git synced 2025-08-08 14:24:57 +00:00

X-Assembler 1.2.

This commit is contained in:
Piotr Fusik
1998-05-22 18:27:22 +02:00
parent a8c91ef7ef
commit a3bfc5179a

346
xasm.asm
View File

@@ -6,11 +6,30 @@
CODESEG CODESEG
ORG 100h ORG 100h
start: start:
db 3072 dup(0) ;for packing db 4096 dup(0) ;for packing
l_lab = 50000 l_icl = 1000
l_org = 1000*2 l_org = 1000*2
l_icl = 16*6 l_lab = 50000
STRUC com
nam db ?,?,?
cod db ?
vec dw ?
ENDS
STRUC icl
prev dw ?
handle dw ?
line dd ?
nam db ?
ENDS
STRUC lab
prev dw ?
val dw ?
nam db ?
ENDS
;<3B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ;<3B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
@@ -38,12 +57,10 @@ ENDIF
MACRO file _func, _errtx MACRO file _func, _errtx
mov bp, offset _errtx mov bp, offset _errtx
IFNB <_func>
IF _func and 0ff00h IF _func and 0ff00h
mov ax, _func mov ax, _func
ELSE ELSE
mov ah, _func mov ah, _func
ENDIF
ENDIF ENDIF
call xdisk call xdisk
ENDM ENDM
@@ -84,82 +101,46 @@ _tp SUBSTR <_oper>, 6
mov [fnad], di mov [fnad], di
mov al, '?' mov al, '?'
repne scasb repne scasb
jne nousg jne begin
usg: print usgtxt usg: print usgtxt
dos 4c01h dos 4c01h
nousg: mov si, di begin: mov [origin], 0
srchex: dec si call ldname
opfile: mov bx, offset (icl).nam
add bx, [iclen]
mov si, di
srex2: dec si
cmp [byte si], '\' cmp [byte si], '\'
je addext je adex2
cmp [byte si], '.' cmp [byte si], '.'
je extexs je lvex2
cmp si, 82h cmp si, bx
jnb srchex ja srex2
addext: mov si, di adex2: mov [byte di-1], '.'
mov ax, 'a.' mov ax, 'sa'
stosw stosw
mov ax, 'xs' mov ax, 'x'
stosw stosw
extexs: inc si lvex2: call fopen
mov [fnen], si
mov [di], ch ;0
begin: mov si, [fnad]
mov di, offset fname
ldname: lodsb
stosb
test al, al
jnz ldname
cmp [pass], 1
jb pass1
mov di, [fnen]
mov [dword di], 'moc'
mov dx, [fnad]
xor cx, cx
file 3ch, e_creat
mov [ohand], ax
mov ax, 0ffffh
call putwor
mov [orgvec], offset t_org
xor ax, ax
call pheadr
mov ax, [laben]
mov [p1laben], ax
mov [pslaben], offset t_lab
pass1: mov [origin], 0
opfile: mov bx, [filidx]
cmp bx, offset t_icl+l_icl-6
mov ax, offset e_icl
jnb panica
mov [dword bx+6+2], 0
add [filidx], 6
mov dx, offset fname
file 3d00h, e_open
mov bx, [filidx]
mov [bx], ax
main: test [eoflag], 0ffh main: test [eoflag], 0ffh
jnz filend jnz filend
mov bx, [filidx] mov bx, [iclen]
inc [dword bx+2] mov bx, [(icl bx).prev]
inc [(icl bx).line]
inc [lines] inc [lines]
mov di, offset line-1 mov di, offset line-1
gline1: cmp di, offset line+255 gline1: cmp di, offset line+255
jnb linlon jnb linlon
mov bx, [filidx]
mov bx, [bx]
mov cx, 1 mov cx, 1
lea dx, [di+1] lea dx, [di+1]
push dx push dx
file 3fh, e_read call fread
pop di pop di
test ax, ax
jz eof jz eof
cmp [byte di], 0ah cmp [byte di], 0ah
jne gline1 jne gline1
@@ -169,7 +150,6 @@ eof: inc [eoflag]
mov [word di], 0a0dh mov [word di], 0a0dh
syntax: mov si, offset line syntax: mov si, offset line
mov al, [si] mov al, [si]
cmp al, 0dh cmp al, 0dh
je main je main
@@ -189,7 +169,7 @@ syntax: mov si, offset line
cmp bx, [p1laben] cmp bx, [p1laben]
jnb ltwice jnb ltwice
mov [pslaben], bx mov [pslaben], bx
inc [labvec] inc [labvec] ;1
jmp s_cmd jmp s_cmd
ltwice: mov ax, offset e_twice ltwice: mov ax, offset e_twice
jmp panica jmp panica
@@ -223,25 +203,25 @@ s_cmd: lodsb
jmp uneol jmp uneol
s_cmd1: dec si s_cmd1: dec si
lodsw lodsw
and ax, 0dfdfh and ax, 0dfdfh
sta dx sta dx
lodsb lodsb
and al, 0dfh and al, 0dfh
mov di, offset comtab mov di, offset comtab
mov bx, 64*6 mov bx, 64*size com
sfcmd1: mov ah, al sfcmd1: mov ah, al
mov cx, dx mov cx, dx
sub ah, [di+bx+2] sub ah, [(com di+bx+2).nam]
sbb ch, [di+bx+1] sbb ch, [(com di+bx+1).nam]
sbb cl, [di+bx] sbb cl, [(com di+bx).nam]
jb sfcmd3 jb sfcmd3
or ah, ch or ah, ch
or ah, cl or ah, cl
jnz sfcmd2 jnz sfcmd2
mov al, [di+bx+3] mov al, [(com di+bx).cod]
mov [cod], al mov [cod], al
call [word di+4+bx] call [(com di+bx).vec]
call linend call linend
jmp main jmp main
@@ -261,17 +241,41 @@ filend: mov [eoflag], 0
cmp [pass], 1 cmp [pass], 1
jnb noforg jnb noforg
call putorg call putorg
noforg: mov bx, [filidx] noforg: call fclose
mov bx, [bx] cmp bx, offset t_icl
file 3eh, e_read ja main
sub [filidx], 6 cmp [pass], 1
cmp [filidx], offset t_icl jnb fin
jnb main
inc [pass]
cmp [pass], 2
jb begin
mov bx, [ohand] inc [pass]
call ldname
mov si, di
srex1: dec si
cmp [byte si], '\'
je adex1
cmp [byte si], '.'
je chex1
cmp si, offset (icl t_icl).nam
ja srex1
jmp adex1
chex1: mov di, si
adex1: mov [byte di-1], '.'
mov [dword di], 'moc'
mov dx, offset (icl t_icl).nam
xor cx, cx
file 3ch, e_creat
mov [ohand], ax
mov ax, 0ffffh
call putwor
mov [orgvec], offset t_org
xor ax, ax
call pheadr
mov ax, [laben]
mov [p1laben], ax
inc [pslaben] ;0
jmp begin
fin: mov bx, [ohand]
file 3eh, e_writ file 3eh, e_writ
mov eax, [lines] mov eax, [lines]
shr eax, 1 shr eax, 1
@@ -286,6 +290,7 @@ tmlab: mov ax, offset e_tlab
jmp panica jmp panica
linlon: mov ax, offset e_long linlon: mov ax, offset e_long
; Obsluga bledow
panica: mov [errad], ax panica: mov [errad], ax
panic: cmp [errad], offset lislin panic: cmp [errad], offset lislin
jb panifn jb panifn
@@ -295,27 +300,61 @@ prilin: inc si
dos 2 dos 2
cmp [byte si], 0ah cmp [byte si], 0ah
jne prilin jne prilin
panifn: mov dx, offset fname panifn: mov bx, [iclen]
mov di, dx cmp bx, offset t_icl
mov ch, -1 jna eronly
xor al, al mov di, [(icl bx).prev]
repne scasb push di
mov [byte di-1], ' ' lea dx, [(icl di).nam]
mov [word di], '$(' mov [byte bx-1], ' '
mov [word bx], '$('
print print
mov bx, [filidx] pop bx
mov eax, [bx+2] mov eax, [(icl bx).line]
call pridec call pridec
print errtxt mov dl, ')'
dos 2
eronly: print errtxt
mov dx, [errad] mov dx, [errad]
print print
dos 4c01h dos 4c01h
; I/O
xdisk: mov [errad], bp xdisk: mov [errad], bp
dos dos
jc panic jc panic
ret ret
fopen: mov ax, offset e_icl
cmp di, offset t_icl+l_icl-2
jnb panica
mov bx, [iclen]
mov [(icl bx).line], 0
lea dx, [(icl bx).nam]
mov [(icl di).prev], bx
mov [iclen], di
file 3d00h, e_open
mov bx, [iclen]
mov bx, [(icl bx).prev]
mov [(icl bx).handle], ax
ret
fread: mov ah, 3fh
freacl: mov bx, [iclen]
mov bx, [(icl bx).prev]
mov bx, [(icl bx).handle]
mov bp, offset e_read
call xdisk
test ax, ax
ret
fclose: mov ah, 3eh
call freacl
mov bx, [iclen]
mov bx, [(icl bx).prev]
mov [iclen], bx
ret
putwor: push ax putwor: push ax
call putbyt call putbyt
pop ax pop ax
@@ -337,6 +376,16 @@ savwor: inc [origin]
savbyt: inc [origin] savbyt: inc [origin]
jmp putbyt jmp putbyt
; Przepisuje nazwe z linii komend
ldname: mov si, [fnad]
mov di, offset (icl t_icl).nam
ldnam1: lodsb
stosb
cmp al, 0dh
jne ldnam1
mov [byte di-1], 0
ret
; Wyswietla dziesietnie EAX ; Wyswietla dziesietnie EAX
pridec: mov di, offset dectxt+10 pridec: mov di, offset dectxt+10
mov ebx, 10 mov ebx, 10
@@ -378,7 +427,7 @@ space1: call get
dec si dec si
rstret: ret rstret: ret
; Stwierdza blad, jesli nie spacja, tab i eol ; Stwierdza blad, jesli nie spacja, tab lub eol
linend: lodsb linend: lodsb
cmp al, 0dh cmp al, 0dh
je rstret je rstret
@@ -389,11 +438,15 @@ linend: lodsb
mov ax, offset e_xtra mov ax, offset e_xtra
jmp panica jmp panica
; Czyta nazwe pliku
rfname: call spaces
mov di, offset (icl).nam
add di, [iclen]
; Czyta lancuch i zapisuje do [di] ; Czyta lancuch i zapisuje do [di]
rstr: call get rstr: call get
cmp al, "'" cmp al, "'"
jne strer jne strer
push di mov dx, di
rstr1: call get rstr1: call get
stosb stosb
cmp al, "'" cmp al, "'"
@@ -402,11 +455,9 @@ rstr1: call get
cmp al, "'" cmp al, "'"
je rstr1 je rstr1
dec si dec si
dec di mov [byte di-1], 0
mov [byte di], 0 lea cx, [di-1]
mov cx, di sub cx, dx
pop di
sub cx, di
jnz rstret jnz rstret
strer: mov ax, offset e_str strer: mov ax, offset e_str
@@ -444,14 +495,14 @@ sflab0: mov dx, di
dec si dec si
push si push si
mov bx, [laben] mov bx, [laben]
sflab1: cmp bx, offset t_lab+4 sflab1: cmp bx, offset (lab t_lab).nam
jb sflabn jb sflabn
lea cx, [bx-4] lea cx, [bx-4]
mov bx, [bx] mov bx, [(lab bx).prev]
sub cx, bx sub cx, bx
cmp cx, dx cmp cx, dx
jne sflab1 jne sflab1
lea si, [bx+4] lea si, [(lab bx).nam]
mov di, offset tlabel mov di, offset tlabel
repe cmpsb repe cmpsb
jne sflab1 jne sflab1
@@ -516,7 +567,7 @@ vlabel: dec si
cmp [pass], 1 cmp [pass], 1
jb vlabun jb vlabun
jmp unknow jmp unknow
vlabkn: mov dx, [bx+2] vlabkn: mov dx, [(lab bx).val]
cmp bx, [pslaben] cmp bx, [pslaben]
jbe value1 jbe value1
vlabun: mov [undef], 0ffh vlabun: mov [undef], 0ffh
@@ -590,6 +641,7 @@ getadr: call spaces
xor dl, dl xor dl, dl
cmp al, '@' cmp al, '@'
je getadx je getadx
push 0ffh
inc dx inc dx
cmp al, '#' cmp al, '#'
je getad1 je getad1
@@ -603,13 +655,30 @@ getadr: call spaces
cmp al, '(' cmp al, '('
je getad1 je getad1
dec si dec si
mov dl, 2 lodsw
and al, 0dfh
xor dx, dx
cmp ax, ':Z'
je getad0
dec dx
cmp ax, ':A'
je getad0
dec si
dec si
jmp getad9
getad0: pop ax
push dx
getad9: mov dl, 2
getad1: mov [amod], dl getad1: mov [amod], dl
call value call value
mov al, [byte high val] mov al, [byte high val]
jnc getad2 jnc getad2
sbb al, al sbb al, al
getad2: mov dl, [amod] getad2: pop dx
and al, dl
or al, dh
mov dl, [amod]
cmp dl, 1 cmp dl, 1
je getart je getart
cmp dl, 10 cmp dl, 10
@@ -702,6 +771,24 @@ p_srt: call getadr
je ilamod je ilamod
jmp putcmd jmp putcmd
p_inw: call getadr
cmp al, 6
jnb ilamod
sub al, 2
jb ilamod
mov bx, offset inwtab
xlat
push ax
call putcmd
inc [val]
mov ax, 03d0h
test [amod], 1
jz p_iw1
dec ah
p_iw1: call savwor
pop ax
jmp putcmd
p_ldi: call getadr p_ldi: call getadr
cmp al, 1 cmp al, 1
jb ilamod jb ilamod
@@ -835,7 +922,7 @@ nolabl: mov ax, offset e_label
p_org: call getval p_org: call getval
jc unknow jc unknow
cmp [pass], 1 p_org1: cmp [pass], 1
jnb org1 jnb org1
call putorg call putorg
stc stc
@@ -863,6 +950,13 @@ putorg: mov bx, [orgvec]
tmorgs: mov ax, offset e_orgs tmorgs: mov ax, offset e_orgs
jmp panica jmp panica
p_rui: mov ah, 2
mov [val], ax
call p_org1
call getval
mov ax, [val]
jmp savwor
valuco: call value valuco: call value
jc unknow jc unknow
call get call get
@@ -1009,7 +1103,7 @@ dtat1: mov di, offset tlabel
dec si dec si
xor ah, ah xor ah, ah
dtat2: push si dtat2: push si
mov si, di mov si, dx
dtatm: lodsb dtatm: lodsb
xor al, ah xor al, ah
cmp [cod], 'D' cmp [cod], 'D'
@@ -1032,21 +1126,46 @@ dtanxt: lodsb
dec si dec si
ret ret
p_icl: call spaces p_icl: call rfname
mov di, offset fname
call rstr
pop ax pop ax
call linend call linend
jmp opfile jmp opfile
p_ins: call rfname
call fopen
push si
p_in1: mov cx, 256
mov dx, offset tlabel
call fread
jz p_in2
add [origin], ax
cwde
mov bx, [iclen]
mov bx, [(icl bx).prev]
add [(icl bx).line], eax
cmp [pass], 1
jb p_in1
add [bytes], eax
sta cx
mov bx, [ohand]
mov dx, offset tlabel
file 40h, e_writ
jmp p_in1
p_in2: call fclose
pop si
ret
p_end: pop ax p_end: pop ax
call linend call linend
jmp filend jmp filend
; addressing modes:
; 0-@ 1-# 2-A 3-Z 4-A,X 5-Z,X 6-A,Y 7-Z,Y 8-(Z,X) 9-(Z),Y 10-(A)
lentab db 1,2,3,2,3,2,3,2,2,2,3 lentab db 1,2,3,2,3,2,3,2,2,2,3
acctab db 0,9,0dh,5,1dh,15h,19h,19h,1,11h,0 acctab db 0,9,0dh,5,1dh,15h,19h,19h,1,11h,0
srttab db 0ah,0,0eh,6,1eh,16h srttab db 0ah,0,0eh,6,1eh,16h
lditab db 0,0,0ch,4,1ch,14h,1ch,14h lditab db 0,0,0ch,4,1ch,14h,1ch,14h
inwtab db 0eeh,0e6h,0feh,0f6h
comtab: cmd ADC60p_acc comtab: cmd ADC60p_acc
cmd ADD18p_ads cmd ADD18p_ads
@@ -1078,6 +1197,9 @@ comtab: cmd ADC60p_acc
cmd EQU00p_equ cmd EQU00p_equ
cmd ICL00p_icl cmd ICL00p_icl
cmd INCe0p_srt cmd INCe0p_srt
cmd INIe2p_rui
cmd INS00p_ins
cmd INW00p_inw
cmd INXe8p_imp cmd INXe8p_imp
cmd INYc8p_imp cmd INYc8p_imp
cmd JCCb0p_juc cmd JCCb0p_juc
@@ -1106,6 +1228,7 @@ comtab: cmd ADC60p_acc
cmd ROR60p_srt cmd ROR60p_srt
cmd RTI40p_imp cmd RTI40p_imp
cmd RTS60p_imp cmd RTS60p_imp
cmd RUNe0p_rui
cmd SBCe0p_acc cmd SBCe0p_acc
cmd SEC38p_imp cmd SEC38p_imp
cmd SEDf8p_imp cmd SEDf8p_imp
@@ -1122,13 +1245,13 @@ comtab: cmd ADC60p_acc
cmd TYA98p_imp cmd TYA98p_imp
comend: comend:
hello db 'X-Assembler 1.1 by Fox/Taquart',eot hello db 'X-Assembler 1.2 by Fox/Taquart',eot
usgtxt db 'Give a source filename. Default extension is .ASX.',eol usgtxt db 'Give a source filename. Default extension is .ASX.',eol
db 'Destination will have the same name and .COM extension.',eot db 'Destination will have the same name and .COM extension.',eot
lintxt db ' lines assembled',eot lintxt db ' lines assembled',eot
byttxt db ' bytes written',eot byttxt db ' bytes written',eot
dectxt db 10 dup(' '),'$' dectxt db 10 dup(' '),'$'
errtxt db ') ERROR: $' errtxt db ' ERROR: $'
e_open db 'Can''t open file',eot e_open db 'Can''t open file',eot
e_read db 'Disk read error',eot e_read db 'Disk read error',eot
e_creat db 'Can''t write destination',eot e_creat db 'Can''t write destination',eot
@@ -1156,7 +1279,7 @@ e_spac db 'Space expected',eot
pass dw 0 pass dw 0
lines dd 0 lines dd 0
bytes dd 0 bytes dd 0
filidx dw t_icl-6 iclen dw t_icl
laben dw t_lab laben dw t_lab
p1laben dw 0 p1laben dw 0
pslaben dw -1 pslaben dw -1
@@ -1178,7 +1301,6 @@ obyte db ?
undef db ? undef db ?
labvec dw ? labvec dw ?
fnad dw ? fnad dw ?
fnen dw ?
fname db 80 dup(?) fname db 80 dup(?)
line db 258 dup(?) line db 258 dup(?)