.186
CSEG segment
org 100h
Begin:
mov dx, offset Filename
mov ah,3dh ;al sollte per default 0 sein
int 21h
xchg bx,ax ;braucht nur 1 byte
;Speicher vorbereiten, jeweils 65k für BF Code und BF Array reservieren und Nullen
mov cx,cs
add cx,0ffffh/15 ;bisschen Platz für eigentlichen Com-code lassen
mov es,cx
xor cx,cx ;auf Anzahl der Bytes bringen
dec cx
;zeromemory , ax ist durch xchg bx,ax=0
rep stosb
;File lesen
xchg cx,di ;mov cx, di
; inc di ; di auf 0
mov ah,3fh
int 21h
mov si,dx ;nötig???
add dx,ax
;schließen (später löschen!)
mov ah,3eh
int 21h
mov bx,dx
;Nun SI ist der Zeiger auf Code
;DI zeiger auf Array
INTERPRET:
cld
lodsb
cmp al,'<'
jne @f
dec DI
@@:
cmp al,'>'
jne @f
inc DI
@@:
cmp al,'+'
jne @f
inc byte ptr es:[DI]
@@:
cmp al,'-'
jne @f
dec byte ptr es:[DI]
@@:
cmp al,'.'
jne @f
mov ah,02
mov dl,byte ptr es:[DI]
int 21h
@@:
cmp al,','
jne @f
mov ah,01
int 21h
mov byte ptr es:[DI],al
xchg cx,ax ;jmp ENDE CX ist i.R 0, also wird weitere ausführung nicht beeinflüsst
@@:
;[ jump forward to the command after the corresponding ] if the byte at the pointer is zero.
;] jump back to the command after the corresponding [ if the byte at the pointer is nonzero.
xor cx,cx
cmp byte ptr es:[DI],cl
jnz NEXT_BRC ;es ist nicht 0 , also interessiert [ Scan uns gar nicht, sonst:
cmp al,'[' ;ansonten ist [ und Zelle 0
je INC_
; oder nicht [ und 0, dann interessirt und auch der ] Fall nicht
jmp ENDE
NEXT_BRC:
cmp al,']';hier=>Zelle nicht 0 -> scannen nach [
jne ENDE
std
dec si
SCAN_LOOP:
lodsb
cmp al,'['
je INC_
cmp al,']'
jne SCAN_LOOP ;sonst ist es ] ->dec
dec cx
jz ENDE
jmp SCAN_LOOP
INC_: inc cx
jnz SCAN_LOOP ;wenn ungleich, kann weitergescannt werden
inc si ;korrigiere SI
inc si
ENDE:
cmp SI,bx
jbe INTERPRET
int 20h
filename db 'i',0
CSEG ends
end Begin