Assembly Programming Guide

Character Input & Buffer Management Techniques

📝
Subroutine IN2 - Character Input & Packing
Two-character input and bit manipulation
IN2,
-
Subroutine entry point
FST,
SKI
Skip if input flag is set
BUN FST
Branch to first character input
INP
Input first character
OUT
Echo first character to output
BSA SH4
Shift left four times (first nibble)
BSA SH4
Shift left four more times (total 8 bits)
SCD,
SKI
Skip if input flag is set
BUN SCD
Loop until input is ready
INP
Input second character
OUT
Echo second character to output
BUN IN2 I
Return to calling program

🔍 How it works:

This subroutine reads two characters and packs them into a single word. The first character is shifted left by 8 bits (two SH4 calls) to occupy the upper byte, then the second character is placed in the lower byte. This technique allows storing two ASCII characters in one 16-bit word.

💾
Buffer Storage Program
Character buffer management with pointer arithmetic
LDA ADS
Load first address of buffer
STA PTR
Initialize pointer to buffer start
LOP,
BSA IN2
Go to subroutine IN2 (Above Subroutine)
STA PTR I
Store double character word in buffer
ISZ PTR
Increment pointer to next location
BUN LOP
Branch to input more characters
ADS,
HEX 500
First address of buffer (address 500₁₆)
PTR,
HEX 0
Location for pointer storage

🎯 Program Flow:

This program creates a character input buffer system. It initializes a pointer to buffer location 500₁₆, then continuously calls the IN2 subroutine to get character pairs. Each packed character word is stored at the current pointer location, which is then incremented for the next storage operation. This creates an efficient text input system with automatic buffer management.

Start Learning Interrupts in I/O operation