home *** CD-ROM | disk | FTP | other *** search
/ ftp.ee.pdx.edu / 2014.02.ftp.ee.pdx.edu.tar / ftp.ee.pdx.edu / pub / users / Harry / Blitz / version-1-0 / OSProject / p1 / Echo.s < prev    next >
Text File  |  2006-03-30  |  4KB  |  121 lines

  1. ! Basic Character I/O: Echo characters
  2. !
  3. ! Harry Porter, 11/18/02
  4. !
  5. ! This program copies characters from the serial input to the serial
  6. ! output.  It does not bufffer them at all.  When a 'q' is entered, it
  7. ! suspends execution via the 'debug' instruction.
  8. !
  9. ! Here is the algorithm:
  10. !    while (1) {
  11. !      wait for an input character;
  12. !      send the character to the output;
  13. !      if (the char was 'q') {
  14. !        debug;
  15. !      }
  16. !    }
  17. !
  18. ! This program does not use interrupts; it uses busy-waiting for getting
  19. ! characters from the input and waiting for the output to be ready.
  20. !
  21. ! This program is useful as a test of the BLITZ serial I/O interface.
  22. ! When running in "cooked" mode, you should see every line echoed twice, once
  23. ! by the host OS and once by this program.
  24. !
  25. ! When running in "raw" mode, you should see each character echoed after it is
  26. ! typed.  Note that characters like \n and \r are echoed exactly.  Try typing
  27. ! control-J (for \n) and control-M (for \r).  All other non-printing characters
  28. ! (like tab and esc) are echoed as '?'.  Try hitting Control-C to suspend
  29. ! execution.
  30. !
  31.         .text
  32. _entry:
  33.  
  34.  
  35.  
  36. !
  37. ! Here is the interrupt vector, which will be loaded at address 0x00000000.
  38. ! Each entry is 4 bytes.  They are located at fixed, pre-defined addresses.
  39. ! This program will ignore all interrupts.  The asynchronous, hardware
  40. ! interrupts (i.e., TIMER, DISK, and SERIAL) will be ignored by returning
  41. ! immediately.  None of the other interrupts should occur; if they do, this
  42. ! program will get stuck in an infinite loop. 
  43. !
  44. PowerOnReset:
  45.         jmp     main
  46. TimerInterrupt:
  47.         reti
  48. DiskInterrupt:
  49.         reti
  50. SerialInterrupt:
  51.         reti
  52. HardwareFault:
  53.         jmp     HardwareFault
  54. IllegalInstruction:
  55.         jmp     IllegalInstruction
  56. ArithmeticException:
  57.         jmp     ArithmeticException
  58. AddressException:
  59.         jmp     AddressException
  60. PageInvalidException:
  61.         jmp     PageInvalidException
  62. PageReadonlyException:
  63.         jmp     PageReadonlyException
  64. PrivilegedInstruction:
  65.         jmp     PrivilegedInstruction
  66. AlignmentException:
  67.         jmp     AlignmentException
  68. ExceptionDuringInterrupt:
  69.         jmp     ExceptionDuringInterrupt
  70. SyscallTrap:
  71.         jmp     SyscallTrap
  72.  
  73.  
  74. !
  75. ! main - Repeat the following in an infinite loop:  Wait (in a busy loop)
  76. !        until an input character is available.  Read it in.  Then wait
  77. !        (in a busy loop) until the output is ready and write the character
  78. !        to the output.
  79. !
  80. ! r2 = character
  81. ! r3 = ptr to SERIAL_STAT word in the memory-mapped area.
  82. ! r4 = ptr to SERIAL_DATA word in the memory-mapped area.
  83. ! r5 = serial status word
  84. !
  85. main:
  86.         set    STACK_START,r15    ! Initialize the stack reg
  87.         set    SERIAL_STAT,r3    ! Initialize ptr to SERIAL_STAT word
  88.         set    SERIAL_DATA,r4    ! Initialize ptr to SERIAL_DATA word
  89. loop:                    ! LOOP:
  90. wait1:                    !   WAIT1:
  91.         load    [r3],r5        !     r5 := serial status word
  92.         btst    0x00000001,r5   !     if status[charAvail] == 0 then
  93.         be    wait1        !     .    goto WAIT1
  94.         load    [r4],r2        !   Get the character
  95.                 cmp    r2,'\n'        !   if char != \n
  96.         be    charOK        !   .
  97.                 cmp    r2,'\r'        !   .  and char != \r
  98.         be    charOK        !   .
  99.                 cmp    r2,' '        !   .  and char < ' ' char then
  100.                 bge    charOK        !   .
  101.                 mov    '?',r2        !     char := '?'
  102. charOK:                    !   endIf
  103.                 cmp    r2,0x7e        !   if char > 7e char then
  104.                 ble    charOK2        !   .
  105.                 mov    '?',r2        !     char := '?'
  106. charOK2:                !   endIf
  107. wait2:                    !   WAIT2:
  108.         load    [r3],r5        !     r5 := serial status word
  109.         btst    0x00000002,r5   !     if status[outputReady] == 0 then
  110.         be    wait2        !     .    goto WAIT2
  111.         store    r2,[r4]        !   send char in r2 to serial output
  112.                 cmp     r2,'q'          !   if char == 'q' then
  113.                 bne     cont            !   .
  114.                 debug            !     debug
  115. cont:                    !   endIf
  116.         jmp    loop        ! ENDLOOP        
  117.  
  118. STACK_START    =    0x00ffff00
  119. SERIAL_STAT    =    0x00ffff00
  120. SERIAL_DATA    =    0x00ffff04
  121.