     1                                  ; ****************************************************************************
     2                                  ; cat386.s (Retro Unix 386 v1) - /bin/cat - concatenate files
     3                                  ; ----------------------------------------------------------------------------
     4                                  ;
     5                                  ; RETRO UNIX 386 (Retro Unix == Turkish Rational Unix)
     6                                  ; Operating System Project (v0.2) by ERDOGAN TAN (Beginning: 24/12/2013)
     7                                  ;
     8                                  ; Retro UNIX 8086 v1 - '/bin/cat' file
     9                                  ;
    10                                  ; Derived from 'Retro UNIX 8086 v1' source code by Erdogan Tan
    11                                  ; (v0.1 - Beginning: 11/07/2012)
    12                                  ;
    13                                  ; [ Last Modification: 17/06/2022 ] -cat4.s-
    14                                  ;
    15                                  ; Derived from UNIX Operating System (v1.0 for PDP-11) 
    16                                  ; (Original) Source Code by Ken Thompson (Bell Laboratories, 1971-1972)
    17                                  ; ****************************************************************************
    18                                  ; ((nasm cat4.s -l cat4.txt -o cat4 -Z error.txt))
    19                                  ; cat386.s - cat4.s (17/06/2022, Retro UNIX 386 v1 & v1.1)
    20                                  ; cat386.s - cat3.s (15/06/2022, Retro UNIX 386 v1.2)
    21                                  ; cat386.s - cat2.s (14/06/2022, Retro UNIX 386 v1 & v1.1)
    22                                  ; cat386.s - cat1.s (05/03/2022, Retro UNIX 386 v1 & v1.1 & v1.2)
    23                                  ; cat386.s - cat0.s (17/10/2015 - 28/12/2015, Retro UNIX 386 v1, NASM 2.11)
    24                                  ; CAT2.ASM (02/12/2013 - 16/07/2015, Retro UNIX 8086 v1, MASM 6.11) 
    25                                  
    26                                  ; 17/10/2015
    27                                  
    28                                  ; UNIX v1 system calls
    29                                  _rele 	equ 0
    30                                  _exit 	equ 1
    31                                  _fork 	equ 2
    32                                  _read 	equ 3
    33                                  _write	equ 4
    34                                  _open	equ 5
    35                                  _close 	equ 6
    36                                  _wait 	equ 7
    37                                  _creat 	equ 8
    38                                  _link 	equ 9
    39                                  _unlink	equ 10
    40                                  _exec	equ 11
    41                                  _chdir	equ 12
    42                                  _time 	equ 13
    43                                  _mkdir 	equ 14
    44                                  _chmod	equ 15
    45                                  _chown	equ 16
    46                                  _break	equ 17
    47                                  _stat	equ 18
    48                                  _seek	equ 19
    49                                  _tell 	equ 20
    50                                  _mount	equ 21
    51                                  _umount	equ 22
    52                                  _setuid	equ 23
    53                                  _getuid	equ 24
    54                                  _stime	equ 25
    55                                  _quit	equ 26	
    56                                  _intr	equ 27
    57                                  _fstat	equ 28
    58                                  _emt 	equ 29
    59                                  _mdate 	equ 30
    60                                  _stty 	equ 31
    61                                  _gtty	equ 32
    62                                  _ilgins	equ 33
    63                                  _sleep	equ 34 ; Retro UNIX 8086 v1 feature only !
    64                                  _msg    equ 35 ; Retro UNIX 386 v1 feature only !
    65                                  _geterr	equ 36 ; Retro UNIX 386 v1 feature only !
    66                                  ; 12/01/2022 - Retro UNIX 386 v1.2
    67                                  ; Retro UNIX 386 v2 system calls
    68                                  _setgid	equ 37
    69                                  _getgid	equ 38
    70                                  _sysver	equ 39 ; (get) Retro Unix 386 version
    71                                  
    72                                  %macro sys 1-4
    73                                      ; 03/09/2015	
    74                                      ; 13/04/2015
    75                                      ; Retro UNIX 386 v1 system call.		
    76                                      %if %0 >= 2   
    77                                          mov ebx, %2
    78                                          %if %0 >= 3    
    79                                              mov ecx, %3
    80                                              %if %0 = 4
    81                                                 mov edx, %4   
    82                                              %endif
    83                                          %endif
    84                                      %endif
    85                                      mov eax, %1
    86                                      int 30h	   
    87                                  %endmacro
    88                                  
    89                                  ; 17/06/2022 - Retro UNIX 386 v1
    90                                  ;struc stat
    91                                  ;	; Retro UNIX v1 'sysstat' output !
    92                                  ;	; (34 bytes)
    93                                  ;	.inode:  resw 1	
    94                                  ;	.mode:	 resw 1
    95                                  ;	.nlinks: resb 1
    96                                  ;	.uid:	 resb 1
    97                                  ;	.size:	 resw 1
    98                                  ;	.dskptr: resw 8
    99                                  ;	.ctime:	 resd 1
   100                                  ;	.mtime:	 resd 1
   101                                  ;	.rsvd:   resw 1
   102                                  ;	.strucsize:
   103                                  ;endstruc  
   104                                  
   105                                  ; Retro UNIX 386 v1 system call format:
   106                                  ; sys systemcall (eax) <arg1 (ebx)>, <arg2 (ecx)>, <arg3 (edx)>
   107                                  
   108                                  [BITS 32] ; We need 32-bit intructions for protected mode
   109                                  
   110                                  [ORG 0] 
   111                                  
   112                                  START_CODE:
   113                                  	;; / cat -- concatenate files
   114                                  
   115                                  	sys	_write, 1, nl, 2
    73                              <1> 
    74                              <1> 
    75                              <1> 
    76                              <1>  %if %0 >= 2
    77 00000000 BB01000000          <1>  mov ebx, %2
    78                              <1>  %if %0 >= 3
    79 00000005 B9[6A010000]        <1>  mov ecx, %3
    80                              <1>  %if %0 = 4
    81 0000000A BA02000000          <1>  mov edx, %4
    82                              <1>  %endif
    83                              <1>  %endif
    84                              <1>  %endif
    85 0000000F B804000000          <1>  mov eax, %1
    86 00000014 CD30                <1>  int 30h
   116                                  
   117 00000016 5D                      	pop	ebp
   118 00000017 5A                      	pop	edx
   119                                  	; esi = 0 ; ('sysexec' sets regs to zero)
   120                                  	; 05/03/2022
   121                                  	;mov	esi, fin 
   122                                  	;mov    edi, obuf
   123                                  	;EAX = 2 (written byte count)
   124 00000018 30C0                    	xor	al, al ; 0
   125 0000001A B9[74010000]                    mov	ecx, iobuf ; 17/06/2022
   126 0000001F 4D                      	dec     ebp
   127 00000020 7454                    	jz	short cat_3	
   128                                  		;;mov	(sp)+,r5
   129                                  		;;tst	(sp)+
   130                                  		;;mov	$obuf,r2
   131                                  		;;cmp	r5,$1
   132                                  		;;beq	3f
   133                                  cat_0:	
   134 00000022 5B                      	pop	ebx
   135 00000023 803B2D                  	cmp	byte [ebx], '-'
   136 00000026 744E                    	je	short cat_3 ; 16/06/2022
   137                                  		;;dec	r5
   138                                  		;;ble	done
   139                                  		;;mov	(sp)+,r0
   140                                  		;;cmpb	(r0),$'-
   141                                  		;;bne	2f
   142                                  		;;clr	fin
   143                                  		;;br	3f
   144                                  cat_1:
   145                                  	;;2:
   146                                  	; ebx = file name offset
   147 00000028 31C9                    	xor 	ecx, ecx ; 0
   148                                  	sys 	_open
    73                              <1> 
    74                              <1> 
    75                              <1> 
    76                              <1>  %if %0 >= 2
    77                              <1>  mov ebx, %2
    78                              <1>  %if %0 >= 3
    79                              <1>  mov ecx, %3
    80                              <1>  %if %0 = 4
    81                              <1>  mov edx, %4
    82                              <1>  %endif
    83                              <1>  %endif
    84                              <1>  %endif
    85 0000002A B805000000          <1>  mov eax, %1
    86 0000002F CD30                <1>  int 30h
   149                                  	;jc	short cat_7
   150                                  	; 05/03/2022 ; (+)
   151 00000031 7305                    	jnc	short cat_2
   152 00000033 E907010000              	jmp	cat_7
   153                                  cat_2:
   154                                  	; 05/03/2022
   155 00000038 89C6                    	mov	esi, eax
   156                                  	;mov	[esi], eax ; 05/03/2022
   157                                  	;mov	[esi], ax
   158                                  		;;mov	r0,0f
   159                                  		;;sys	open; 0:..; 0
   160                                  		;;bes	loop
   161                                  		;;mov	r0,fin
   162                                  
   163                                  	; 05/03/2022 ; (+)
   164                                  	; convert user's file number to inode number
   165                                  	; (get 34 byte inode details, inode num + inode)
   166                                  	; (get 66 byte inode details for runix 386 v1.2)
   167                                  	sys	_fstat, esi, iobuf 
    73                              <1> 
    74                              <1> 
    75                              <1> 
    76                              <1>  %if %0 >= 2
    77 0000003A 89F3                <1>  mov ebx, %2
    78                              <1>  %if %0 >= 3
    79 0000003C B9[74010000]        <1>  mov ecx, %3
    80                              <1>  %if %0 = 4
    81                              <1>  mov edx, %4
    82                              <1>  %endif
    83                              <1>  %endif
    84                              <1>  %endif
    85 00000041 B81C000000          <1>  mov eax, %1
    86 00000046 CD30                <1>  int 30h
   168                                  	;jc	short cat_7
   169                                  	; 05/03/2022 ; (+)
   170 00000048 7321                    	jnc	short cat_f
   171 0000004A E9E7000000              	jmp	cat_k ; 15/06/2022
   172                                  
   173                                  rwcount:
   174                                  	; 17/06/2022 - Retro UNIX 386 v1 (& v1.1)
   175 0000004F 31D2                    	xor	edx, edx
   176 00000051 66A1[74010000]          	mov	ax, [iobuf] ; inode number
   177 00000057 6683F829                	cmp	ax, 41 ; regular file (or directory) ?
   178 0000005B 730B                    	jnb	short rwc_2 ; yes
   179                                  
   180 0000005D 3C08                    	cmp	al, 8 ; > hd3 inode number ?
   181 0000005F 7704                    	ja	short rwc_1 ; yes ; character device
   182                                  
   183 00000061 3C03                    	cmp	al, 3 ; >= fd0 inode number ?
   184 00000063 7303                    	jnb	short rwc_2 ; yes ; block device
   185                                  rwc_1:
   186                                  	; no, character device
   187                                  	; read/write count = 1
   188 00000065 FEC2                    	inc	dl
   189 00000067 C3                      	retn
   190                                  rwc_2:
   191                                  	; regular file or block device
   192                                  	; read/write count = 512
   193 00000068 B602                    	mov	dh, 2 ; edx = 512
   194 0000006A C3                      	retn
   195                                  	
   196                                  cat_f:
   197                                  	; 15/06/2022
   198 0000006B E8DFFFFFFF              	call	rwcount
   199 00000070 8915[70010000]          	mov	[filerwc], edx
   200                                  cat_3:	
   201                                  	; 05/03/2022 ; (+)
   202                                  	; get inode number of current tty (stdin)
   203                                  	; (get 34 byte inode details, inode num + inode)
   204                                  	; (get 66 byte inode details for runix 386 v1.2)
   205                                  	;sys	_fstat, 0, iobuf 
   206                                  	;;jc	short cat_n
   207                                  	;mov	ecx, iobuf	
   208                                  	sys	_fstat, 0  ; get stdin file inode details
    73                              <1> 
    74                              <1> 
    75                              <1> 
    76                              <1>  %if %0 >= 2
    77 00000076 BB00000000          <1>  mov ebx, %2
    78                              <1>  %if %0 >= 3
    79                              <1>  mov ecx, %3
    80                              <1>  %if %0 = 4
    81                              <1>  mov edx, %4
    82                              <1>  %endif
    83                              <1>  %endif
    84                              <1>  %endif
    85 0000007B B81C000000          <1>  mov eax, %1
    86 00000080 CD30                <1>  int 30h
   209                                  
   210                                  	; 15/06/2022
   211 00000082 E8C8FFFFFF              	call	rwcount
   212 00000087 8915[6C010000]          	mov	[stdinrw], edx
   213                                  
   214                                  cat_n:	;;3:
   215                                  	; get keyboard status of console tty
   216 0000008D 31DB                    	xor	ebx, ebx  ; 0
   217 0000008F 31C9                    	xor	ecx, ecx ; 0
   218                                  	sys	_gtty
    73                              <1> 
    74                              <1> 
    75                              <1> 
    76                              <1>  %if %0 >= 2
    77                              <1>  mov ebx, %2
    78                              <1>  %if %0 >= 3
    79                              <1>  mov ecx, %3
    80                              <1>  %if %0 = 4
    81                              <1>  mov edx, %4
    82                              <1>  %endif
    83                              <1>  %endif
    84                              <1>  %endif
    85 00000091 B820000000          <1>  mov eax, %1
    86 00000096 CD30                <1>  int 30h
   219                                  	; 15/06/2022
   220 00000098 21DB                    	and	ebx, ebx ; is there a waiting char ?
   221 0000009A 753F                    	jnz	short cat_x ; yes
   222                                  
   223 0000009C 08F6                    	or	dh, dh  ; is stdin a character device (tty) ?
   224 0000009E 7540                    	jnz	short cat_p
   225                                  			; no, stdin is a file or block device
   226                                  
   227                                  	; is there a file to read ?
   228 000000A0 09F6                    	or	esi, esi ; 05/03/2022
   229 000000A2 755F                    	jnz	short cat_r ; yes
   230                                  
   231                                  	; edx = [stdinrw]
   232                                  	sys	_read, 0, iobuf
    73                              <1> 
    74                              <1> 
    75                              <1> 
    76                              <1>  %if %0 >= 2
    77 000000A4 BB00000000          <1>  mov ebx, %2
    78                              <1>  %if %0 >= 3
    79 000000A9 B9[74010000]        <1>  mov ecx, %3
    80                              <1>  %if %0 = 4
    81                              <1>  mov edx, %4
    82                              <1>  %endif
    83                              <1>  %endif
    84                              <1>  %endif
    85 000000AE B803000000          <1>  mov eax, %1
    86 000000B3 CD30                <1>  int 30h
   233                                  		; read one char into [iobuf]
   234 000000B5 727B                    	jc	short cat_6 ; (ebx = 0)
   235                                  
   236 000000B7 803D[74010000]1B        	cmp	byte [iobuf], 1Bh ; 27 ; ESCape key ?
   237 000000BE 7505                    	jne	short cat_c 
   238                                  
   239 000000C0 E982000000              	jmp	cat_exit ; yes, exit
   240                                  
   241                                  cat_c:
   242                                  	; is there a file to read ?
   243                                  	;or	esi, esi ; 05/03/2022
   244                                  	;jnz	short cat_r ; yes
   245                                  
   246                                  	; 16/06/2022
   247                                  	;and	edx, edx
   248                                  	;jz	short cat_exit ; end of stdin file
   249                                  
   250                                  	;xor	eax, eax
   251                                  	;inc	al
   252 000000C5 B001                    	mov	al, 1
   253                                  	; eax = 1	
   254 000000C7 803D[74010000]0D        	cmp	byte [iobuf], 0Dh ; carriage return ?
   255 000000CE 754D                    	jne	short cat_w
   256 000000D0 C605[75010000]0A        	mov	byte [iobuf+1], 0Ah ; line feed
   257 000000D7 FEC0                    	inc	al
   258                                  	; eax = 2
   259 000000D9 EB42                    	jmp	short cat_w
   260                                  
   261                                  cat_x:
   262 000000DB 80FB1B                  	cmp	bl, 1Bh ; 27 ; ESCape key ?
   263 000000DE 7467                    	je	short cat_exit ; yes, exit
   264                                  cat_p:
   265                                  	; edx = [stdinrw]
   266                                  	sys	_read, 0, iobuf
    73                              <1> 
    74                              <1> 
    75                              <1> 
    76                              <1>  %if %0 >= 2
    77 000000E0 BB00000000          <1>  mov ebx, %2
    78                              <1>  %if %0 >= 3
    79 000000E5 B9[74010000]        <1>  mov ecx, %3
    80                              <1>  %if %0 = 4
    81                              <1>  mov edx, %4
    82                              <1>  %endif
    83                              <1>  %endif
    84                              <1>  %endif
    85 000000EA B803000000          <1>  mov eax, %1
    86 000000EF CD30                <1>  int 30h
   267                                  		; read one char into [iobuf]
   268 000000F1 723F                    	jc	short cat_6 ; (ebx = 0)
   269                                  	
   270                                  	; eax = read count
   271                                  	; read (redirected) stdin at first then other files 
   272 000000F3 09C0                    	or	eax, eax
   273 000000F5 7526                    	jnz	short cat_w ; write bytes in buffer
   274                                  
   275                                  	; 16/06/2022
   276                                  	; trick to skip reading stdin file
   277 000000F7 31D2                    	xor	edx, edx
   278                                  	; edx = 0
   279 000000F9 8915[6C010000]          	mov	[stdinrw], edx  ; end of stdin file
   280                                  	;jmp	short cat_c ; read (input) file
   281                                  
   282                                  	; is there a file to read ?
   283 000000FF 21F6                    	and	esi, esi
   284 00000101 743C                    	jz	short cat_7 ; no
   285                                   
   286                                  cat_r:
   287                                  	; 05/03/2022
   288                                  	;mov	eax, [esi] ; file descriptor/number
   289                                  	;;mov	ax, [esi]
   290                                  	;
   291                                  	;sys	_read, eax, iobuf, 512 ; 16/07/2015
   292                                  	;;sys 	_read, eax, ibuf, 512 
   293                                  	;jc	short cat_6
   294                                  	; 15/06/2022
   295                                  	; 05/03/2022
   296                                  	; esi = file descriptor/number
   297                                  	sys	_read, esi, iobuf, [filerwc]
    73                              <1> 
    74                              <1> 
    75                              <1> 
    76                              <1>  %if %0 >= 2
    77 00000103 89F3                <1>  mov ebx, %2
    78                              <1>  %if %0 >= 3
    79 00000105 B9[74010000]        <1>  mov ecx, %3
    80                              <1>  %if %0 = 4
    81 0000010A 8B15[70010000]      <1>  mov edx, %4
    82                              <1>  %endif
    83                              <1>  %endif
    84                              <1>  %endif
    85 00000110 B803000000          <1>  mov eax, %1
    86 00000115 CD30                <1>  int 30h
   298                                  		; read 512 chars into [iobuf]
   299                                  	;jc	short cat_6
   300 00000117 721D                    	jc	short cat_k ; 05/03/2022
   301                                  
   302                                  	; NOTE: If input file is a tty (keyboard)
   303                                  	;	only 1 byte will be read, by ignoring
   304                                  	;	byte count (512).
   305                                  	;	Retro UNIX 8086 v1 kernel ('rtty')
   306                                  	;	has been modified fot that.
   307                                  	;       Erdogan Tan (16/07/2015)
   308                                  	;
   309                                  
   310                                  	; 15/06/2022
   311 00000119 21C0                    	and	eax, eax ; EAX = 1 for tty (keyboard)
   312                                  	;jz	short cat_6
   313 0000011B 7419                    	jz	short cat_k ; 05/03/2022
   314                                  
   315                                  ;	push	esi
   316                                  	;mov	esi, ibuf
   317                                  ;	mov	esi, ecx ; offset ibuf
   318                                  ;	mov	ecx, eax
   319                                  		;;mov	fin,r0
   320                                  		;;sys	read; ibuf; 512.
   321                                  		;;bes	3f
   322                                  		;;mov	r0,r4
   323                                  		;;beq	3f
   324                                  		;;mov	$ibuf,r3
   325                                  	 ; 16/07/2015
   326                                  ;	mov	edx, eax
   327                                  ;	;add	edx, obuf
   328                                  ;cat_4:
   329                                  ;	;;4:
   330                                  ;	lodsb
   331                                  	;call	putc
   332                                  cat_w:
   333                                  	; 16/07/2015
   334                                  	; write to console tty (stdout)
   335                                  	sys 	_write, 1, iobuf, eax
    73                              <1> 
    74                              <1> 
    75                              <1> 
    76                              <1>  %if %0 >= 2
    77 0000011D BB01000000          <1>  mov ebx, %2
    78                              <1>  %if %0 >= 3
    79 00000122 B9[74010000]        <1>  mov ecx, %3
    80                              <1>  %if %0 = 4
    81 00000127 89C2                <1>  mov edx, %4
    82                              <1>  %endif
    83                              <1>  %endif
    84                              <1>  %endif
    85 00000129 B804000000          <1>  mov eax, %1
    86 0000012E CD30                <1>  int 30h
   336                                  	;jc	short cat_6
   337                                  	; 05/03/2022
   338                                  	;jnc	short cat_3
   339                                  	; 15/06/2022
   340 00000130 731F                    	jnc	short cat_8
   341                                  
   342                                  ;	loop	cat_4
   343                                  ;	pop	esi
   344                                  cat_5:
   345                                  	;mov	eax, [esi] ; 05/03/2022
   346                                  	;;mov	ax, [esi]
   347                                  	;jmp	short cat_3
   348                                  		;;movb	(r3)+,r0
   349                                  		;;jsr	pc,putc
   350                                  		;;dec	r4
   351                                  		;;bne	4b
   352                                  		;;br	3b
   353                                  	;; 05/03/2022
   354                                  	;; ebx = file descriptor/input
   355                                  	;;and	ebx, ebx ; console input ?
   356                                  	;;jnz	short cat_3 ; no, file input
   357                                  	;;cmp	byte [quit], al ; 0
   358                                  	;;ja	short cat_7 ; ebx = 0
   359                                  	;;jmp	short cat_z
   360                                  	; 05/03/2022
   361                                  	;jmp	short cat_3
   362                                  		
   363                                  cat_6:	;;3:
   364                                  	; 05/03/2022
   365                                  	; ebx = file descriptor/number
   366                                  	;movzx	ebx, word [esi]
   367                                  	;
   368 00000132 09F6                    	or	esi, esi
   369 00000134 7409                    	jz	short cat_7
   370                                  cat_k:
   371                                  	sys	_close, esi
    73                              <1> 
    74                              <1> 
    75                              <1> 
    76                              <1>  %if %0 >= 2
    77 00000136 89F3                <1>  mov ebx, %2
    78                              <1>  %if %0 >= 3
    79                              <1>  mov ecx, %3
    80                              <1>  %if %0 = 4
    81                              <1>  mov edx, %4
    82                              <1>  %endif
    83                              <1>  %endif
    84                              <1>  %endif
    85 00000138 B806000000          <1>  mov eax, %1
    86 0000013D CD30                <1>  int 30h
   372                                  	;
   373                                  	;or	ebx, ebx
   374                                  	;jz	short cat_7
   375                                  	;sys 	_close
   376                                  		;;mov	fin,r0
   377                                  		;;beq	loop
   378                                  		;;sys	close
   379                                  		;;br	loop
   380                                  cat_7:	
   381                                  	;;loop:
   382 0000013F 4D                      	dec	ebp
   383                                  	;;jz	short cat_8
   384                                  	; 28/12/2015
   385                                  	;jg	short cat_0
   386                                  	; 05/03/2022
   387 00000140 7E05                    	jng	short cat_exit
   388 00000142 E9DBFEFFFF              	jmp	cat_0
   389                                  
   390                                  cat_exit:
   391                                  	sys	_exit
    73                              <1> 
    74                              <1> 
    75                              <1> 
    76                              <1>  %if %0 >= 2
    77                              <1>  mov ebx, %2
    78                              <1>  %if %0 >= 3
    79                              <1>  mov ecx, %3
    80                              <1>  %if %0 = 4
    81                              <1>  mov edx, %4
    82                              <1>  %endif
    83                              <1>  %endif
    84                              <1>  %endif
    85 00000147 B801000000          <1>  mov eax, %1
    86 0000014C CD30                <1>  int 30h
   392                                  here:
   393 0000014E 90                      	nop
   394 0000014F EBFD                    	jmp	short here
   395                                  	;;
   396                                  
   397                                  cat_8:
   398                                  	; 15/06/2022
   399 00000151 39D0                    	cmp	eax, edx
   400 00000153 72DD                    	jb	short cat_6
   401 00000155 8B15[6C010000]          	mov	edx, [stdinrw]
   402 0000015B 09D2                    	or 	edx, edx  ; end of stdin file
   403 0000015D 7405                    	jz	short cat_9
   404 0000015F E929FFFFFF              	jmp	cat_n
   405                                  
   406                                  cat_9:
   407                                  	; 16/06/2022
   408 00000164 21F6                    	and	esi, esi
   409 00000166 74CE                    	jz	short cat_k
   410 00000168 EB99                    	jmp	short cat_r
   411                                  
   412                                  ;cat_8:
   413                                  ;	;;done:
   414                                  ;	sub	di, obuf
   415                                  ;	jz	short cat_9
   416                                  ;	sys	_write, 1, obuf, di 
   417                                  		;;sub	$obuf,r2
   418                                  		;;beq	1f
   419                                  		;;mov	r2,0f
   420                                  		;;mov	$1,r0
   421                                  		;;sys	write; obuf; 0:..
   422                                  ;cat_9:	
   423                                  ;	;;1:
   424                                  ;	sys	_exit
   425                                  		;;sys	exit
   426                                  	;;
   427                                  ;putc:	
   428                                  ;	;;putc:
   429                                  ;	stosb
   430                                  ;	cmp	di, dx ; 16/07/2015
   431                                  	;cmp	di, obuf + 512
   432                                  ;	jb	short cat_10
   433                                  ;	push	cx
   434                                  	 ; 16/07/2015
   435                                  ;	mov	di, obuf
   436                                  ;	sub	dx, di ; byte (char) count
   437                                  	; 
   438                                  ;	sys 	_write, 1, obuf
   439                                  	;sys 	_write, 1, obuf, 512
   440                                  	;mov	di, obuf
   441                                  		;;movb	r0,(r2)+
   442                                  		;;cmp	r2,$obuf+512.
   443                                  		;;blo	1f
   444                                  		;;mov	$1,r0
   445                                  		;;sys	write; obuf; 512.
   446                                  		;;mov	$obuf,r2
   447                                  ;	pop	cx
   448                                  ;cat_10:	
   449                                  	;;1:
   450                                  ;	retn
   451                                  		;;rts	pc
   452                                  
   453 0000016A 0D0A                    nl:	db 0Dh, 0Ah ; , 0
   454                                  
   455                                  ;; 05/03/2022
   456                                  ;quit:	db 0
   457                                  ;consoletty:
   458                                  ;	db '/dev/tty', 0 ; (+)
   459                                  
   460                                  align 4
   461                                  
   462                                  bss_start:
   463                                  
   464                                  ABSOLUTE bss_start
   465                                  
   466                                  ; 15/06/2022
   467 0000016C ????????                stdinrw: resd 1
   468 00000170 ????????                filerwc: resd 1
   469                                  
   470 00000174 <res 200h>              iobuf:  resb 512
   471                                  ;ibuf:	resb 512
   472                                  ;obuf:	resb 512
   473                                  ;;fin:	resw 1
   474                                  ;fin:	resd 1 ; 05/03/2022	
   475                                  		;;.bss
   476                                  		;;ibuf:	.=.+512.
   477                                  		;;obuf:	.=.+512.
   478                                  		;;fin:	.=.+2
   479                                  		;;.text
   480                                  ;bss_end:
