DataMuseum.dk

Presents historical artifacts from the history of:

RegneCentralen RC759 "Piccoline"

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about RegneCentralen RC759 "Piccoline"

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download

⟦7fb34b2db⟧ TextFile

    Length: 24275 (0x5ed3)
    Types: TextFile
    Names: »SIDSAMPL.DOC«

Derivation

└─⟦f18477172⟧ Bits:30003931/GEM_Develop_disk_1_CDOS.imd Disketter indleveret af Steffen Jensen (Piccolo/Piccoline)
    └─⟦this⟧ »DOCU\SIDSAMPL.DOC« 

TextFile




                         SID-86 Sample Session

In the following sample session,  the user interactively debugs a simple 
program.  Remarks in brackets explain the steps involved.


ÆType source file of program to test.Å

C>type sample.a86
;
;  This program reads an ASCII file, breaking it up into "tokens",
;  which are displayed on the console.
;
fcb		equ	5ch
cr		equ	0dh
lf		equ	0ah
tab		equ	09h
end_file	equ	1ah

init:
	mov	dx,fcb
	mov	ah,15
	int	21h
	or	al,al
	jnz	err
main_loop:
	call	collect_token
	cmp	token,end_file
	jz	done
	call	print_token
	jmps	main_loop
done:
	retf

err:	mov	dx,offset nofile
	call	printm
	jmp	done

collect_token:
	call	get_char
	call	check_delim
	jz	col1
	mov	bx,token_len
	mov	tokenÆbxÅ,al
	inc	token_len
	jmps	collect_token
col1:	ret

check_delim:
	cmp	al,cr
	jz	cret
	cmp	al,lf
	jz	cret
	cmp	al,tab
	jz	cret
	cmp	al,' '
cret:	ret

get_char:
	cmp	buffptr, buffsize
	jc	get1
	mov	dx,offset buff
	call	setdta
	mov	dx,fcb
	call	readsec
	mov	buffptr,0
get1:
	mov	bx,buffptr
	mov	al,buffÆbxÅ
	inc	buffptr
	ret

print_token:
	mov	cx,token_len
	jcxz	pr2
	sub	bx,bx
pr1:	mov	dl,tokenÆbxÅ
	push	cx
	push	bx
	call	conout
	pop	bx
	pop	cx
	inc	bx
	dec	cx
	loop	pr1
	mov	dl,cr
	call	conout
	mov	dl,lf
	call	conout
pr2:
	ret

conout:	mov	ah,2
	int	21h
	ret

printm:	mov	ah,9
	int	21h
	ret

readsec:
	mov	ah,20
	int	21h
	ret

setdta:	mov	ah,26
	int	21h
	ret

	dseg

nofile		db	'NO FILE$'

buffsize	equ	128
buffptr		dw	0
buff		rb	buffsize

max_token	equ	40
token_len	rw	1
token		rb	max_token

	end

ÆAssemble the file using the $LO option, which puts local symbols into 
the object file.Å
 
C>rasm86 sample $lo
--------------------------------------------------
RASM-86 Relocating Assembler           Version 1.0
Serial No. PPPP-OOOO-SSSSSS    All Rights Reserved
Copyright (C) 1982,1983     Digital Research, Inc.
--------------------------------------------------

END OF PASS 1
END OF PASS 2

SEGMENTS
--------

00B4 DATA
00A7 CODE

END OF ASSEMBLY.  NUMBER OF ERRORS:   0.  USE FACTOR:  1%

ÆLink the object file to produce an executable (EXE) file and a symbol
table (SYM) file.Å

C>link86 sample
--------------------------------------------------
LINK-86 Linkage Editor                 Version 1.0
Serial No. PPPP-OOOO-SSSSSS    All Rights Reserved
Copyright (C) 1982,1983     Digital Research, Inc.
--------------------------------------------------

CODE    000AC
DATA    001B4

USE FACTOR:  00%

ÆTEST.TEX has test data for SAMPLE.Å

C>type test.tex

Now is the time for all good men to come to the aid of their country.
 
ÆTry running SAMPLE on TEST.TEX.Å

C>sample test.tex

NowqPF1RwqBÆ
æ   QR@ÅBUlF91Rwq   C
æ#"F1RwqB	Q0RH"ÅBUlG"!LH9"wN6"F"sdÅCUl
^7Qcv	Hw&t#"R	"!t9wa#
"!"@;:%v
!:%+"@wa#
"!"#Iüu!V#66
"8(Phå!"#V66
"8(PhüÅBUl0vhÅBUl0vv-
^7Q7vhüü
^7QcÅBUv8k6jht""
"7
lP^C

ÆThis does not look quite right.  Load the EXE and SYM files under SID-
86 (the appropriate file types are assumed).Å

C>sid86 sample sample
--------------------------------------------------
SID-86 Symbolic Debugger               Version 1.0
Serial No. PPPP-OOOO-SSSSSS    All Rights Reserved
Copyright (C) 1983          Digital Research, Inc.
--------------------------------------------------

  START      END
0B5F:0000 0B5F:09FF
SYMBOLS

ÆList the symbols that SID-86 reads from SAMPLE.SYM.Å

#h

0009 TAB
001A END_FILE
000D CR
000A LF
005C FCB
0028 MAX_TOKEN
0000 NUMBERS
0010 MAIN_LOOP
00A2 READSEC
0005 INIT
004E CRET
0076 PRINT_TOKEN
0020 ERR
0040 CHECK_DELIM
001F DONE
0029 COLLECT_TOKEN
004F GET_CHAR
009D PRINTM
0098 CONOUT
0097 PR2
007E PR1
0069 GET1
003F COL1
00A7 SETDTA
0000 LABELS
018A TOKEN_LEN
0100 NOFILE
010A BUFF
0108 BUFFPTR
018C TOKEN
0000 VARIABLES
0000 SAMPLE

ÆDisassemble the beginning of the program.Å

#l

SAMPLE:
  0B9F:0000 NOP    
  0B9F:0001 NOP    
  0B9F:0002 NOP    
  0B9F:0003 NOP    
  0B9F:0004 NOP    
INIT:
  0B9F:0005 MOV    DX,005C .FCB
  0B9F:0008 MOV    AH,0F
  0B9F:000A INT    21
  0B9F:000C OR     AL,AL
  0B9F:000E JNZ    0020 .ERR
MAIN_LOOP:
  0B9F:0010 CALL   0029 .COLLECT_TOKEN
  0B9F:0013 CMP    BYTE Æ018CÅ,1A .TOKEN

ÆStart the program with a breakpoint at MAIN_LOOP.Å

#g,10
NO FILE
PROGRAM TERMINATED NORMALLY
#^C

ÆOops!  Forgot to tell SAMPLE the name of the file to process.  Reload 
the program.Å

C>sid86 sample sample
--------------------------------------------------
SID-86 Symbolic Debugger               Version 1.0
Serial No. PPPP-OOOO-SSSSSS    All Rights Reserved
Copyright (C) 1983          Digital Research, Inc.
--------------------------------------------------

  START      END
0B5F:0000 0B5F:09FF
SYMBOLS

ÆSet up the file name for SAMPLE to use.Å

#
itest.tex

ÆGo with breakpoint at 10H (MAIN_LOOP).Å

#g,10

*0B9F:0010 .MAIN_LOOP

ÆGot there this time!  List next instructions.Å

#l

MAIN_LOOP:
  0B9F:0010 CALL   0029 .COLLECT_TOKEN
  0B9F:0013 CMP    BYTE Æ018CÅ,1A .TOKEN
  0B9F:0018 JZ     001F .DONE
  0B9F:001A CALL   0076 .PRINT_TOKEN
  0B9F:001D JMPS   0010 .MAIN_LOOP
DONE:
  0B9F:001F RETF   
ERR:
  0B9F:0020 MOV    DX,0100 .NOFILE
  0B9F:0023 CALL   009D .PRINTM
  0B9F:0026 JMP    001F .DONE
COLLECT_TOKEN:
  0B9F:0029 CALL   004F .GET_CHAR
  0B9F:002C CALL   0040 .CHECK_DELIM
  0B9F:002F JZ     003F .COL1

ÆTrace without call to see the results of COLLECT_TOKEN without worrying 
about what happens at lower levels.Å

#tw3

           AX   BX   CX   DX   SP   BP   SI   DI   IP
--I--Z-P- 0F00 0BAA 0000 005C 037B 0000 0100 0100 0010
 CALL   0029 .COLLECT_TOKEN
--I--Z-P- 1420 0003 0000 005C 037B 0000 0100 0100 0013
 CMP    BYTE Æ018CÅ,1A .TOKEN =00
--I-S-A-C 1420 0003 0000 005C 037B 0000 0100 0100 0018
 JZ     001F .DONE
*0B9F:001A

ÆDisplay the contents of the TOKEN array.Å

#d.token,+f

0BAA:018C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
................

ÆThe TOKEN array is empty!  No wonder it does not work.  Reload the 
program.Å

#esample sample

  START      END
0B5F:0000 0B5F:09FF
SYMBOLS
#itest.tex

ÆGo up to MAIN_LOOP.Å

#g,10

*0B9F:0010 .MAIN_LOOP
#l,+9

MAIN_LOOP:
  0B9F:0010 CALL   0029 .COLLECT_TOKEN
  0B9F:0013 CMP    BYTE Æ018CÅ,1A .TOKEN
  0B9F:0018 JZ     001F .DONE

ÆThis time trace through COLLECT_TOKEN routine.Å

#t

           AX   BX   CX   DX   SP   BP   SI   DI   IP
--I--Z-P- 0F00 0BAA 0000 005C 037B 0000 0100 0100 0010
 CALL   0029 .COLLECT_TOKEN
*0B9F:0029 .COLLECT_TOKEN
#l

COLLECT_TOKEN:
  0B9F:0029 CALL   004F .GET_CHAR
  0B9F:002C CALL   0040 .CHECK_DELIM
  0B9F:002F JZ     003F .COL1
  0B9F:0031 MOV    BX,Æ018AÅ .TOKEN_LEN
  0B9F:0035 MOV    018CÆBXÅ,AL .TOKEN
  0B9F:0039 INC    WORD Æ018AÅ .TOKEN_LEN
  0B9F:003D JMPS   0029 .COLLECT_TOKEN
COL1:
  0B9F:003F RET    
CHECK_DELIM:
  0B9F:0040 CMP    AL,0D .CR
  0B9F:0042 JZ     004E .CRET
  0B9F:0044 CMP    AL,0A .LF
  0B9F:0046 JZ     004E .CRET

ÆTrace through GET_CHAR routine.Å

#t

           AX   BX   CX   DX   SP   BP   SI   DI   IP
--I--Z-P- 0F00 0BAA 0000 005C 0379 0000 0100 0100 0029
 CALL   004F .GET_CHAR
*0B9F:004F .GET_CHAR
#l
GET_CHAR:
  0B9F:004F CMP    WORD Æ0108Å,0080 .BUFFPTR
  0B9F:0055 JB     0069 .GET1
  0B9F:0057 MOV    DX,010A .BUFF
  0B9F:005A CALL   00A7 .SETDTA
  0B9F:005D MOV    DX,005C .FCB
  0B9F:0060 CALL   00A2 .READSEC
  0B9F:0063 MOV    WORD Æ0108Å,0000 .BUFFPTR
GET1:
  0B9F:0069 MOV    BX,Æ0108Å .BUFFPTR
  0B9F:006D MOV    AL,010AÆBXÅ .BUFF
  0B9F:0071 INC    WORD Æ0108Å .BUFFPTR
  0B9F:0075 RET    
PRINT_TOKEN:
  0B9F:0076 MOV    CX,Æ018AÅ .TOKEN_LEN
#t2

           AX   BX   CX   DX   SP   BP   SI   DI   IP
--I--Z-P- 0F00 0BAA 0000 005C 0377 0000 0100 0100 004F
 CMP    WORD Æ0108Å,0080 .BUFFPTR =0000
--I-S---C 0F00 0BAA 0000 005C 0377 0000 0100 0100 0055
 JB     0069 .GET1
*0B9F:0069 .GET1
#l

GET1:
  0B9F:0069 MOV    BX,Æ0108Å .BUFFPTR
  0B9F:006D MOV    AL,010AÆBXÅ .BUFF
  0B9F:0071 INC    WORD Æ0108Å .BUFFPTR
  0B9F:0075 RET    
PRINT_TOKEN:
  0B9F:0076 MOV    CX,Æ018AÅ .TOKEN_LEN
  0B9F:007A JCXZ   0097 .PR2
  0B9F:007C SUB    BX,BX
PR1:
  0B9F:007E MOV    DL,018CÆBXÅ .TOKEN
  0B9F:0082 PUSH   CX
  0B9F:0083 PUSH   BX
  0B9F:0084 CALL   0098 .CONOUT
  0B9F:0087 POP    BX

ÆTrace through RET instruction to see what value is returned.Å

#t4

           AX   BX   CX   DX   SP   BP   SI   DI   IP
--I-S---C 0F00 0BAA 0000 005C 0377 0000 0100 0100 0069
 MOV    BX,Æ0108Å .BUFFPTR =0000
--I-S---C 0F00 0000 0000 005C 0377 0000 0100 0100 006D
 MOV    AL,010AÆBXÅ .BUFF =00
--I-S---C 0F00 0000 0000 005C 0377 0000 0100 0100 0071
 INC    WORD Æ0108Å .BUFFPTR =0000
--I-----C 0F00 0000 0000 005C 0377 0000 0100 0100 0075
 RET    
*0B9F:002C

ÆA zero is returned in AL.  This is no surprise because the code to read 
from the disk file was not executed.  BUFFPTR should be initialized to 
the size of the buffer, rather than 0.  Use the editor to change the 
source file.Å

#^C

C>edlin sample.a86

End of input file
*sbuffptr               dw
   106: buffptr         dw      0
*106
   106:*buffptr         dw      0
   106:*buffptr         dw      0 buffsize
*e

ÆReassemble and relink.Å

C>rasm86 sample $lo
--------------------------------------------------
RASM-86 Relocating Assembler           Version 1.0
Serial No. PPPP-OOOO-SSSSSS    All Rights Reserved
Copyright (C) 1982,1983     Digital Research, Inc.
--------------------------------------------------

END OF PASS 1
END OF PASS 2

SEGMENTS
--------

00B4 DATA
00A7 CODE

END OF ASSEMBLY.  NUMBER OF ERRORS:   0.  USE FACTOR:  1%

C>link86 sample
--------------------------------------------------
LINK-86 Linkage Editor                 Version 1.0
Serial No. PPPP-OOOO-SSSSSS    All Rights Reserved
Copyright (C) 1982,1983     Digital Research, Inc.
--------------------------------------------------
CODE    000AC
DATA    001B4

USE FACTOR:  00%

ÆTry it again.Å

C>sample test.tex

NowqPF1RwqBÆ
æ   QR@ÅBUlF91Rwq   C
æ#"F1RwqB       Q0RH"ÅBUlG"!LH9"wN6"F"sdÅCUl
^7Qcv^C

ÆStill not quite perfect.  These "simple" programs are never as easy as 
they look!  Invoke SID-86 again.Å

C>sid86 sample sample
--------------------------------------------------
SID-86 Symbolic Debugger               Version 1.0
Serial No. PPPP-OOOO-SSSSSS    All Rights Reserved
Copyright (C) 1983          Digital Research, Inc.
--------------------------------------------------

  START      END
0B5F:0000 0B5F:09FF
SYMBOLS
#itest.tex

#g,10

*0B9F:0010 .MAIN_LOOP

ÆExecute COLLECT_TOKEN to see what happens.Å

#tw3

           AX   BX   CX   DX   SP   BP   SI   DI   IP
--I--Z-P- 0F00 0BAA 0000 005C 037B 0000 0100 0100 0010
 CALL   0029 .COLLECT_TOKEN
--I--Z-P- 1420 0003 0000 005C 037B 0000 0100 0100 0013
 CMP    BYTE Æ018CÅ,1A .TOKEN =4E
--I------ 1420 0003 0000 005C 037B 0000 0100 0100 0018
 JZ     001F .DONE
*0B9F:001A

ÆSee what is in TOKEN.Å

#d.token,+f

0BAA:018C 4E 6F 77 00 00 00 00 00 00 00 00 00 00 00 00 00 Now..........

ÆLooks good this time.  Execute the PRINT_TOKEN routine.Å

#tw2

           AX   BX   CX   DX   SP   BP   SI   DI   IP
--I------ 1420 0003 0000 005C 037B 0000 0100 0100 001A
 CALL   0076 .PRINT_TOKENNow^C
æ   QR@ÅBUlF91Rwq   C
æ#"F1RwqB       Q0RH"ÅBUlG"!LH9"wN6"F"sdÅCUl
^7Qcv^C

ÆPRINT_TOKEN is not working correctly.  Reload the file.Å


#esample sample

  START      END
0B5F:0000 0B5F:09FF
SYMBOLS
#itest.tex

ÆRun program with breakpoint at PRINT_TOKEN.Å

#g,.print_token

*0B9F:0076 .PRINT_TOKEN
#l

PRINT_TOKEN:
  0B9F:0076 MOV    CX,Æ018AÅ .TOKEN_LEN
  0B9F:007A JCXZ   0097 .PR2
  0B9F:007C SUB    BX,BX
PR1:
  0B9F:007E MOV    DL,018CÆBXÅ .TOKEN
  0B9F:0082 PUSH   CX
  0B9F:0083 PUSH   BX
  0B9F:0084 CALL   0098 .CONOUT
  0B9F:0087 POP    BX
  0B9F:0088 POP    CX
  0B9F:0089 INC    BX
  0B9F:008A DEC    CX
  0B9F:008B LOOP   007E .PR1
#t2

           AX   BX   CX   DX   SP   BP   SI   DI   IP
--I------ 1420 0003 0000 005C 0379 0000 0100 0100 0076
 MOV    CX,Æ018AÅ .TOKEN_LEN =0003
--I------ 1420 0003 0003 005C 0379 0000 0100 0100 007A
 JCXZ   0097 .PR2
*0B9F:007C

ÆTOKEN length of 3 looks good.  Trace through end of loop.Å

#tw#10

           AX   BX   CX   DX   SP   BP   SI   DI   IP
--I------ 1420 0003 0003 005C 0379 0000 0100 0100 007C
 SUB    BX,BX
PR1:
--I--Z-P- 1420 0000 0003 005C 0379 0000 0100 0100 007E
 MOV    DL,018CÆBXÅ .TOKEN =4E
--I--Z-P- 1420 0000 0003 004E 0379 0000 0100 0100 0082
 PUSH   CX
--I--Z-P- 1420 0000 0003 004E 0377 0000 0100 0100 0083
 PUSH   BX
--I--Z-P- 1420 0000 0003 004E 0375 0000 0100 0100 0084
 CALL   0098 .CONOUTN
--I--Z-P- 024E 0000 0003 004E 0375 0000 0100 0100 0087
 POP    BX
--I--Z-P- 024E 0000 0003 004E 0377 0000 0100 0100 0088
 POP    CX
--I--Z-P- 024E 0000 0003 004E 0379 0000 0100 0100 0089
 INC    BX
--I------ 024E 0001 0003 004E 0379 0000 0100 0100 008A
 DEC    CX
--I------ 024E 0001 0002 004E 0379 0000 0100 0100 008B
 LOOP   007E .PR1
*0B9F:007E .PR1

ÆThe first character was printed (on the line after ".CONOUT").  Go 
through the loop again.Å

#tw9

           AX   BX   CX   DX   SP   BP   SI   DI   IP
--I------ 024E 0001 0001 004E 0379 0000 0100 0100 007E
 MOV    DL,018CÆBXÅ .TOKEN =6F
--I------ 024E 0001 0001 006F 0379 0000 0100 0100 0082
 PUSH   CX
--I------ 024E 0001 0001 006F 0377 0000 0100 0100 0083
 PUSH   BX
--I------ 024E 0001 0001 006F 0375 0000 0100 0100 0084
 CALL   0098 .CONOUTo
--I------ 026F 0001 0001 006F 0375 0000 0100 0100 0087
 POP    BX
--I------ 026F 0001 0001 006F 0377 0000 0100 0100 0088
 POP    CX
--I------ 026F 0001 0001 006F 0379 0000 0100 0100 0089
 INC    BX
--I------ 026F 0002 0001 006F 0379 0000 0100 0100 008A
 DEC    CX
--I--Z-P- 026F 0002 0000 006F 0379 0000 0100 0100 008B
 LOOP   007E .PR1
*0B9F:007E .PR1

ÆThe "o" was printed.  Do the loop once more.Å

#tw9

           AX   BX   CX   DX   SP   BP   SI   DI   IP
--I--Z-P- 026F 0002 FFFF 006F 0379 0000 0100 0100 007E
 MOV    DL,018CÆBXÅ .TOKEN =77
--I--Z-P- 026F 0002 FFFF 0077 0379 0000 0100 0100 0082
 PUSH   CX
--I--Z-P- 026F 0002 FFFF 0077 0377 0000 0100 0100 0083
 PUSH   BX
--I--Z-P- 026F 0002 FFFF 0077 0375 0000 0100 0100 0084
 CALL   0098 .CONOUTw
--I--Z-P- 0277 0002 FFFF 0077 0375 0000 0100 0100 0087
 POP    BX
--I--Z-P- 0277 0002 FFFF 0077 0377 0000 0100 0100 0088
 POP    CX
--I--Z-P- 0277 0002 FFFF 0077 0379 0000 0100 0100 0089
 INC    BX
--I----P- 0277 0003 FFFF 0077 0379 0000 0100 0100 008A
 DEC    CX
--I-S---- 0277 0003 FFFE 0077 0379 0000 0100 0100 008B
 LOOP   007E  .PR1
*0B9F:007E .PR1

ÆThe "w" was printed, but now the count in CX should be 0, and it is 
FFFE. That is going to loop for a long time.  If you look at the code, 
CX seems to be decremented by 2 each time through the loop.  That "DEC 
CX" does not belong there because the LOOP instruction automatically 
decremented CX. Reload the program.Å

#esample sample

  START      END
0B5F:0000 0B5F:09FF
SYMBOLS

ÆList the area containing the extra instruction.Å

#18a,+9

0B9F:008A DEC    CX
0B9F:008B LOOP   007E .PR1
0B9F:008D MOV    DL,OD .CR
0B9F:008F CALL   0098 .CONOUT
0B9F:0092 MOV    DL,0A .LF

ÆUse the Assemble command to overwrite the instruction with a NOP.Å

#a8a

0B9F:008A nop

0B9F:008BØ .

#itest.tex

ÆRun it again.Å

#g

Now
Nowis
Nowisthe
Nowisthetime
Nowisthetimefor
Nowisthetimeforall
Nowisthetimeforallgood
Nowisthetimeforallgoodmen
Nowisthetimeforallgoodmento
Nowisthetimeforallgoodmentocome
Nowisthetimeforallgoodmentocometo
Nowisthetimeforallgoodmentocometothe
Nowisthetimeforallgoodmentocometotheaid
Nowisthetimeforallgoodmentocometotheaidof^C

ÆLooking better, but still not right!Å

C>sid86
--------------------------------------------------
SID-86 Symbolic Debugger               Version 1.0
Serial No. PPPP-OOOO-SSSSSS    All Rights Reserved
Copyright (C) 1983          Digital Research, Inc.
--------------------------------------------------

ÆThis time patch the program to avoid the edit, assemble, and link loop.  
Use the Read command to bring in the file with its header.Å

#rsample.exe

  START      END
OB4F:0000 0B4F:09FF

ÆList the area to patch (add 60H paragraphs to where the file was loaded 
to get past the header).Å

#lb4f+60:8a

   0BAF:008A DEC    CX
   0BAF:008B LOOP   007E
   0BAF:008D MOV    DL,0D
   0BAF:008F CALL   0098
   0BAF:0092 MOV    DL,0A
   0BAF:0094 CALL   0098    
   0BAF:0097 RET     
   0BAF:0098 MOV    AH,02 
   0BAF:009A INT    21
   0BAF:009C RET 
   0BAF:009D MOV    AH,09 
   0BAF:009F INT    21

ÆAssemble the NOP instruction.Å

#a8a

0BAF:008A nop

0BAF:008BØ .

ÆWrite the file back to disk (no start and end addresses are needed 
since the length of the file did not change).Å

#wsample.exe

ÆReload the patched file and the symbols.Å




#esample sample

  START     END
0B5F:0000 0B5F:09FF
SYMBOLS
#itest.tex

ÆSet a pass point of MAIN_LOOP with a count of 2 because the first token 
came out correct.Å

#p.main_loop,2

ÆStart program.  Execution stops when pass count reaches 1.Å

#g

0002 PASS 0B9F:0010 .MAIN_LOOP
--I--Z-P- 0F00 0BAA 0000 005C 037B 0000 0100 0100 0010
 CALL     0029 .COLLECT_TOKENNow

0001 PASS 0B9F:0010 .MAIN_LOOP
--I----P- 020A 0003 0000 000A 037B 0000 0100 0100 0010
 CALL     0029 .COLLECT_TOKEN
*0B9F:0029 .COLLECT_TOKEN
#1

COLLECT_TOKEN:
  0B9F:0029 CALL   004F .GET_CHAR  
  0B9F:002C CALL   0040 .CHECK_DELIM
  0B9F:002F JZ     0031 .COLI
  0B9F:0031 MOV    BX,Æ018AÅ .TOKEN_LEN
  0B9F:0035 MOV    018CÆBXÅ,AL .TOKEN
  0B9F:0039 INC    WORD Æ018AÅ .TOKEN_LEN
  0B9F:003D JMPS   0029 .COLLECT_TOKEN
COL1:
  0B9F:003F RET
CHECK_DELIM:
  0B9F:0040 CMP    AL,0D .CR
  0B9F:0042 JZ     004E .CRET
  0B9F:0044 CMP    AL,0A .LF
  0B9F:0046 JZ     004E .CRET

ÆTrace without call to see what GET_CHAR and CHECK_DELIM return.Å

#tw3

           AX   BX   CX   DX   SP   BP   SI   DI   IP
--I----P- 020A 0003 0000 000A 0379 0000 0100 0100 0029
 CALL   004F .GET_CHAR
--I----PC 0269 0004 0000 000A 0379 0000 0100 0100 002C
 CALL   0040 .CHECK_DELIM
--I------ 0269 0004 0000 000A 0379 0000 0100 0100 002F
 JZ     003F .COL1
*0B9F:0031

ÆGET_CHAR returns a 69H.  To translate to ASCII, use the M command.Å

#h69

0069 #105 'i' .GET1

ÆThat looks good.  See what happens next.Å

#1

  0B9F:0031 MOV    BX,Æ018AÅ .TOKEN_LEN
  0B9F:0035 MOV    018CÆBXÅ,AL .TOKEN
  0B9F:0039 INC    WORD Æ018AÅ .TOKEN_LEN
  0B9F:003D JMPS   0029 .COLLECT_TOKEN
COL1:
  0B9F:003F RET
CHECK_DELIM:
  0B9F:0040 CMP    AL,OD .CR              
  0B9F:0042 JZ     004E .CRET
  0B9F:0044 CMP    AL,OA .LF
  0B9F:0046 JZ     004E .CRET
  0B9F:0048 CMP    AL,09 .TAB
  0B9F:004A JZ     004E .CRET
  0B9F:004C CMP    AL,20 .ERR

ÆTrace the code that puts the character into the TOKEN buffer.Å

#tw4

           AX   BX   CX   DX   SP   BP   SI   DI   IP
--I------ 0269 0004 0000 000A 0379 0000 0100 0100 0031
 MOV    BX,Æ018AÅ .TOKEN_LEN =0003
--I------ 0269 0003 0000 000A 0379 0000 0100 0100 0035
 MOV    018CÆBXÅ,AL .TOKEN =00
--I------ 0269 0003 0000 000A 0379 0000 0100 0100 0039
 INC    WORD Æ018AÅ .TOKEN_LEN =0003
--I------ 0269 0003 0000 000A 0379 0000 0100 0100 003D
 JMPS   0029 .COLLECT_TOKEN
*0B9F:0029 .COLLECT_TOKEN

ÆAha!  TOKEN_LEN is 3, instead of 0.  It seems that TOKEN_LEN is not 
getting reset for each new token.  Try changing TOKEN_LEN on the fly to 
see if our theory is correct.Å

  START      END
0B5F:0000 0B5F:09FF        
SYMBOLS
#itest.tex

#p.main_loop,2

#g



0002 PASS 0B9F:0010 .MAIN_LOOP
--I--Z-P- 0F00 0BAA 0000 005C 037B 0000 0100 0100 0010
 CALL    0029 .COLLECT_TOKENow

0001 PASS 0B9F:0010 .MAIN_LOOP
--I----P- 020A 0003 0000 000A 037B 0000 0100 0100 0010
 CALL    0029 .COLLECT_TOKEN

ÆChange the value of TOKEN_LEN to 0.Å

#sw.token_len

0BAA:018A 0003 0

0BAA:018C 6F4EØ .

ÆPress next token (pass point still set at MAIN_LOOP).Å

#g
is

0001 PASS 0B9F:0010 .MAIN_LOOP
--I------ 020A 0002 0000 000A 037B 0000 0100 0010
 CALL    0029 .COLLECT_TOKEN
*0B9F:0029 .COLLECT_TOKEN

ÆIt printed "is" correctly.  That must be the problem.  Put in both 
changes at the source level, reassemble, and relink.Å

#^C

C>edlin sample.a86

End of input file
*sdec     cx
    75:         dec     cx
*75d
*1,20sloop:
    17: main_loop:
*18i
    18:*        mov      token_len,0
    19:*^Z
*e

C>rasm86 sample $1o
--------------------------------------------------
RASM-86 Relocating Assembler           Version 1.0
Serial No. PPPP-OOOO-SSSSSS    All Rights reserved
Copyright (C) 1982,1983     Digital Research, Inc.
--------------------------------------------------

END OF PASS 1
END OF PASS 2


SEGMENTS
________

00B4 DATA
00AC CODE

END OF ASSEMBLY.  NUMBER OF ERRORS:    0.   USE FACTOR:  1%

C>link86 sample
--------------------------------------------------
LINK-86 Linkage Editor                 Version 1.0
Serial No. PPPP-OOOO-SSSSSS    All Rights Reserved
Copyright (C) 1982,1983     Digital Research, Inc.
--------------------------------------------------
CODE    000B1
DATA    001B4

USE FACTOR:  00%

ÆOne last try!Å

C>sample test.tex

Now
is
the
time
for
all
good
men
to 
come
to 
the
aid 
of 
their
country.

ÆFinally!  Just out of curiosity, use the pass point feature to count 
the number of tokens in the file.Å

C>sid86 sample sample
--------------------------------------------------
SID-86 Symbolic Debugger               Version 1.0
Serial No. PPPP-OOOO-SSSSSS    All Rights Reserved
Copyright (C) 1983          Digital Research, Inc.
--------------------------------------------------

  START      END
0B5F:0000 0B5F:09FF
SYMBOLS
#itest.tex

ÆSet pass count of FFFF, so SID-86 counts each time MAIN_LOOP is 
executed.Å

#p.main_loop,ffff

ÆExecute program, suppressing pass point display.Å

#-g

Now
is
the
time
for
all
good
men
to
come
to
the
aid
of
their
country.

PROGRAM TERMINATED NORMALLY

ÆDisplay the pass point and its current pass count.Å

#p

FFED 0B9F:0010 .MAIN_LOOP

ÆSubtract from FFFF to calculate number of times MAIN_LOOP was 
executed.Å

#hffff-ffed

0012 #18

ÆThere are 18 tokens in the file.Å

#^C

ÆList the final version of the program.Å

C>type sample.a86

;
;  This program reads an ASCII file, breaking it up into "tokens",
;  which are displayed on the console.
;
fcb             equ     5ch
cr              equ     0dh
lf              equ     0ah
tab             equ     09h
end_file        equ     1ah

init:
        mov     dx,fcb
	mov	ah,15
	int	21h
	or	al,al
	jnz	err
main_loop:
	mov	token_len,0
	call	collect_token
	cmp	token,end_file
	jz	done
	call	print_token
	jmps	main_loop
done:
	retf

err:	mov	dx,offset nofile
	call 	printm
	jmp	done

collect_token:
	call	get_char
	call	check_delim
	jz	coli
	mov	bx,token_len
	mov	tokenÆbxÅ,al
	inc	token_len
	jmps	collect_token
coli:	ret

check_delim:
	cmp	al,cr
	jz	cret
	cmp	al,lf
	jz	creet
	cmp	al,tab
	jz	cret
	cmp	al,' '
cret:	ret

get_char:
	cmp	buffptr, buffsize
	jc	get1
	mov	dx,offset buff
	call	setdta
	mov	dx,fcb
	call	readsec
	mov	buffptr,0
get1:
	mov	bx,buffptr
	mov	al,buffÆbxÅ
	inc	buffptr
	ret

print_token:
	mov	cx,token_len
        jcxz	pr2
	sub	bx,bx
pr1:	mov	dl,tokenÆbxÅ
	push	cx
	push	bx
	call	conout
	pop	bx
	pop	cx
	inc	bx
	loop	pr1
	mov	dl,cr
	call	conout
	mov	dl,lf
	call	conout
pr2:
	ret

conout:	mov	ah,2
	int	21h
	ret

printm:	mov	ah,9
	int	21h
	ret

readsec:
	mov	ah,20
	int	21h
	ret

setdta:	mov	ah,26
	int	21h
	ret
	dseg

nofile		db	'NO FILE$'

buffsize	equ	128
buffptr		dw	buffsize
buff		rb	buffsize

max_token	equ	40
token_len	rw	1
token		rb	max_token

	end

«eof»