The IN instruction reads the first character from the input buffer, converts it to an unsigned integer value (the low-order 8-bits store the character value), and pushes it onto the stack. If there is nothing in the input buffer then a value of zero is pushed onto the stack.
The memory location at word-address 0x3FFD serves as a memory-mapped input/output port. When the microprogram reads this address, the simulator checks the input buffer. If there is at least one character in the buffer, the first character is removed, converted to a 4-byte unsigned integer, and returned as the result of the read operation. If there are no characters in the buffer, the simulator returns a value of 0.
Note: the simulator word address space is 0x0000 to 0x3FFF. The I/O port address, 0x3FFD, corresponds to decimal -3. The microcode that interprets this instruction generates this address by performing the signed arithmetic (-1) + (-1) + (-1).
The microinstructions are listed in the order in which they are executed; not the order in which they are stored in the control store.
0x0fc H=OPC=-1; goto 0x8d ... 0x08d OPC=H+OPC; goto 0x8e 0x08e MAR=H+OPC; rd; goto 0x8f 0x08f SP=MAR=SP+1; goto 0x90 0x090 TOS=MDR; wr; goto 0x2
//--------------------------------------------- // Demonstrate the IN instruction. // // 1. Clear Memory // 2. Assemble this program. // 3. Reset the computer. // 4. Click the "Display Words" radio button // below the memory display. // 5. Click the "Run" button. // // This program loops until you type something // at the keyboard. When you type in a // character, the program will terminate and // the ASCII code of that character will be // stored at 4097, the top of the stack. //--------------------------------------------- .main top: in // Push character onto the stack dup // Push a copy onto the stack bipush 0 // Push 0 for comparison if_icmpeq clear // If there was no character branch to clear goto end // Otherwise, branch to the end of loop clear: pop // Clear the stack goto top // Loop until a character is entered end: halt .end-main