/ / Main procedure to test the writen subroutine / ORG 100 WRTEST, BSA WRITEN / HEX BUF HEX 104 DEC 14 HLT BUF, HEX 41 HEX 42 HEX 43 HEX 44 HEX 0A HEX 45 HEX 46 HEX 47 HEX 48 HEX 0A HEX 49 HEX 4A HEX 4B HEX 4C / / WRITEN subroutine / Prototype: / BSA WRITEN / HEX BUFFER_ADDRESS / HEX n / Explanation: / The above subroutine prints n characters. Each character / is ASCII coded in the bottom order byte of each of the n / 16 bit words beginning at the address symbolized by BUFFER_ADDRESS / Warning: / Like the subroutines in Mano's chapter 6, WRITEN does not save / the ACC and E registers. The caller must save and restore these / registers if it needs to keep the values in them during a call / to WRITEN. / Usage Example: / BSA WRITEN / HEX BUF / HEX 6 /For the 6 chars in HELLO\n / HLT / BUF, HEX 48 / HEX 45 / HEX 4C / HEX 4C / HEX 4F / HEX 0D / / Implementation / WRITEN, HEX 0 /Return address stored here the calling BSA instruction LDA WRITEN I /ACC=address of the output buffer STA PCHAR /m[PCHAR]=address of word holding 1st char to write. ISZ WRITEN /m[WRITEN]=address of word holding the count LDA WRITEN I /ACC=current number of chars left to write. LDA WRITEN I /Harmless repetition in case the ISZ does skip. CMA /ACC=1s complement of curr. number of chars to write. INC /ACC=-(curr. number of chars to write) STA NNTOGO /m[NNTOGO]=-(curr. number of chars left to write). SNA /DONT SKIP if ACC<=0 BUN WEXIT /EXIT if char count was neg or zero. WOLP, LDA PCHAR I /ACC=char to write now. WBLP, SKO /check if printer is ready. BUN WBLP /if not, busy wait. I.E., check again. OUT /send the character to the printer. ISZ PCHAR /PCHAR=address of next word to write. BUN WJNK /Harmless instr in case ISZ does skip. WJNK, ISZ NNTOGO /m[NNTOGO]=-(curr. number of chars not sent out). BUN WOLP /Loop to print another if needed. WEXIT, ISZ WRITEN /m[WRITEN]=return address BUN WRITEN I /return if ISZ doesn't skip. BUN WRITEN I /Return OK even if ISZ does skip. NNTOGO, HEX 0 /Variable to hold neg. of number of chars to print. PCHAR, HEX 0 /Variable to hold address of next char to print.