" cat: cat arg1 [arg2 ...] " Load the pointer pointer in 017777 to see if we have any arguments lac 017777 i sad d4 " Skip if we have more than four argument words jmp nofiles " Only four argument words, so no arguments lac 017777 " Move five words past the argument word count tad d1 " so that AC points at the first argument tad d4 " and save the pointer in name dac name loop: sys open; name:0; 0 " Open file, get fd back spa jmp badfile " Negative fd, exit with an error message dac fi " Save file descriptor in fi 1: jms getc " Get a character in AC sad o4 jmp 1f " Break the loop when we get a ctrl-D jms putc " Write the character on stdout jmp 1b " and loop back 1: lac fi " Close the file descriptor in fi sys close loop1: -4 tad 017777 i " Subtract 4 from the count of argument words dac 017777 i sad d4 " Is the value 4, i.e. no args left? jmp done " Yes, so exit lac name " Still an argument, so move up tad d4 " to the next filename argument dac name jmp loop " and loop back to cat this file badfile: lac name " Get the pointer to the filename dac 1f " Store it in 1f below lac d1 " Load fd 1 which is stdout sys write; 1:0; 4 " Write the four words of the filename lac d1 sys write; 1f; 2 " and then write " ?\n" jmp loop1 " Now try doing the next argument 1: 040;077012 " String literal: " ?\n" nofiles: lac d1 sys write; 1f; 5 " Write "No files\n" to stderr sys exit " and exit 1: ; 040; ;;