home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_2.iso
/
files
/
768b.lha
/
Brainfuck
/
bfc.asm
< prev
next >
Wrap
Assembly Source File
|
1993-05-27
|
2KB
|
168 lines
EXEOBJ
OUTPUT "bfc"
read EQU -$2a
write EQU -$30
input EQU -$36
output EQU -$3c
openlib EQU -$198
closlib EQU -$19e
LEN EQU 4096
; a2 = origstack
; a3 = entry
; a4 = codeptr
; a5 = codebuf
; a6 = doslib
; d3 = 1
;========= opendos ==========
bra.w startup
;============data============
dc.b 0
ecode: dc.b 0 ; left
subq.l #4,a4
dc.b '<'
dc.b 0 ; right
addq.l #4,a4
dc.b '>'
dc.b 0 ; inc
addq.l #1,(a4)
dc.b '+'
dc.b 0 ; dec
subq.l #1,(a4)
dc.b '-'
dc.b 1 ; loop
dc.w $6000,$0000
dc.b '['
dc.b 1 ; endloop
tst.l (a4)
dc.w $6600
dc.b ']'
dc.b 4 ; in
move.l a4,d2
addq.l #3,d2
move.l d4,d1
jsr read(a6)
dc.b ','
dc.b 6 ; out
save jsr output(a6)
move.l d0,d1
move.l a4,d2
addq.l #3,d2
jsr write(a6)
move.l (a7),(a7)
;========== exit ============
exit move.l a2,a7
move.l a6,a1
move.l (4).w,a6
jsr closlib(a6)
moveq #0,d0
rts
a3pos
;=========== emit ===========
eloop move.w (a0)+,(a1)+
dbra d0,eloop
cmp.b (a0)+,d6
bne.s eentry
move.l a1,a4
eentry: move.l a4,a1
move.b (a0)+,d0
ext.w d0
bge.s eloop
move.l a0,a3
sub.b #91,d6
bne.s nodo
;============ [ =============
move.l a4,-(sp)
;============================
nodo: subq.b #2,d6
bne.s loop
;============ ] =============
move.l (sp),d6 ; fix up the backward beq
sub.l a4,d6
move.w d6,(a4)+
move.l (sp)+,a0 ; fix up the forward bra
neg.w d6
subq.w #2,d6
move.w d6,-(a0)
;======== mainloop ==========
loop move.l a4,d2
move.l d4,d1
jsr read(a6)
lea ecode(pc),a0
move.b (a4),d6
tst.l d0
bgt.s eentry
;========== finish =========
finish move.l (a3)+,(a4)+
move.l (a3)+,(a4)+
move.l (a3)+,(a4)+
move.l (a3)+,(a4)+
move.l #$3f2,LEN-36+startup-a3pos(a3)
;========== save ===========
lea odata-3(pc),a4
move.w #LEN,d3
bra.s save
odata: dc.l $3f3
dc.l 0
dc.l 1
dc.l 0
dc.l 0
hlen: dc.l (LEN-36)/4
dc.l $3e9
clen: dc.l (LEN-36)/4
;========== doslib ==========
startup lea dosn(pc),a1
move.l (4).w,a6
jsr openlib(a6) ; opendoslib
move.l d0,a6 ; a6=dosbase
bra.s clrstk
dosn: dc.b "dos.library",0
;========= clrstack =========
clrstk move.l a7,a2
moveq #100,d0
1$ clr.l -(a7)
dbra d0,1$
move.l a7,a4
;=========== getio ==========
jsr input(a6)
move.l d0,d4
moveq #1,d3
;========= writebuf ========
start: lea start(pc),a5 ; store beg for len calc
move.l a5,a4
bra.w loop
dx.b LEN
END