System Software – SIC/XE Program to Write a subroutine to read a record into a buffer

Problem Statement

Write a subroutine for SIC/XE that will read a record into a buffer. The record may be any length from 1 to 100 bytes. The end of record is marked with a “null” character (ASCII code 00). The subroutine should place the length of the record read into a variable named LENGTH. Use immediate addressing and register-to-register instructions to make the process as efficient as possible.

Solution

Line NumberCodeComments
1JSUB RDREC 
2RDREC LDX #0 
3LDT #100 
4LDS #0 
5RLOOP TD INDEV 
6JEQ RLOOP 
7RD INDEV 
8COMPR A, S 
9JEQ EXIT 
10STCH BUFFER, X 
11TIXR T 
12JLT RLOOP 
13EXIR STX LENGTH 
14RSUB 
15INDEV BYTE X ‘F1’ 
16LENGTH RESW 1 
17BUFFER RESB 100