Memory-Mapped Input/Output

MARS Has a "Keyboard and Display MMIO Simulator" Tool that We Can Use as an Example

We Will Concentrate on the Display Part. The Keyboard Part is Similar

Think of the Display as an Old-Fashioned Printer That Prints One Character at a Time

Here is a diagram of these registers that shows the (comparatively few) bits that get used.

                                # The character we want to print is in $s0.
      wl: lw $t0 DISPCTRL       # Copy the control register into a CPU register.
          andi $t0 $t0 1        # Mask off (turn to zero) all of the bits in $t0 except the ready bit.
                                # At this point the value in $t0 is zero if the ready bit was clear or nonzero if it was set.
          beq $t0 $zero wl      # Test $t0 against $zero and branch back to step 1 if they are equal.
                                # Once you get to the instruction after the branch, you are sure that the ready bit is set.
          sb $s0 DISPDATA       # Now it is safe to copy the character code into the data register.
      

Real operating systems don't use wait loops. They use interrupts; this allows them to get useful work done while they are waiting for the ready bit.

The CPU needs to wait on the keyboard, too.