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 / Hello.s < prev    next >
Text File  |  2006-03-30  |  3KB  |  100 lines

  1. ! Hello World
  2. !
  3. ! Harry Porter, 11/20/02
  4. !
  5. ! This program prints a short message on the BLITZ terminal output and
  6. ! then executes the DEBUG instruction.
  7. !
  8. ! This program does not use interrupts; it uses busy-waiting for waiting
  9. ! for the output to become ready.
  10. !
  11.         .text
  12. _entry:
  13.  
  14.  
  15.  
  16. !
  17. ! Here is the interrupt vector, which will be loaded at address 0x00000000.
  18. ! Each entry is 4 bytes.  They are located at fixed, pre-defined addresses.
  19. ! This program will ignore all interrupts.  None of the interrupts should
  20. ! occur; if they do, this program will get stuck in an infinite loop. 
  21. !
  22. PowerOnReset:
  23.         jmp     main
  24. TimerInterrupt:
  25.         jmp    TimerInterrupt
  26. DiskInterrupt:
  27.         jmp    DiskInterrupt
  28. SerialInterrupt:
  29.         jmp    SerialInterrupt
  30. HardwareFault:
  31.         jmp     HardwareFault
  32. IllegalInstruction:
  33.         jmp     IllegalInstruction
  34. ArithmeticException:
  35.         jmp     ArithmeticException
  36. AddressException:
  37.         jmp     AddressException
  38. PageInvalidException:
  39.         jmp     PageInvalidException
  40. PageReadonlyException:
  41.         jmp     PageReadonlyException
  42. PrivilegedInstruction:
  43.         jmp     PrivilegedInstruction
  44. AlignmentException:
  45.         jmp     AlignmentException
  46. ExceptionDuringInterrupt:
  47.         jmp     ExceptionDuringInterrupt
  48. SyscallTrap:
  49.         jmp     SyscallTrap
  50.  
  51.  
  52. !
  53. ! main - This program prints a message and then terminates.
  54. !
  55. ! The algorithm is:
  56. !        Loop forever
  57. !          Initialize pointers
  58. !          Repeat the following in a loop:
  59. !            Wait (in a busy loop) until the output is ready
  60. !            Get the next character
  61. !            If it is '\0' then break
  62. !            Send the character to the terminal
  63. !          Execute the 'debug' instruction
  64. !        EndLoop
  65. !
  66. ! Here is how the registers are used:
  67. !   r1  = ptr to SERIAL_STAT
  68. !   r2  = ptr to SERIAL_DATA
  69. !   r3  = serial status word
  70. !   r4  = ptr to next character to be printed
  71. !   r5  = character
  72. !   r15 = stack pointer
  73. !
  74. main:                    ! MAIN LOOP:
  75.         set    STACK_START,r15    !   Initialize the stack reg
  76.         set    SERIAL_STAT,r1    !   Initialize ptr to SERIAL_STAT word
  77.         set    SERIAL_DATA,r2    !   Initialize ptr to SERIAL_DATA word
  78.         set    message,r4    !   r4 := & message
  79. loop:                    !   LOOP:
  80. busywait:                !     BUSYWAIT:
  81.         load    [r1],r3        !       r3 := serial status word
  82.         btst    0x00000002,r3   !       if status[outputReady] == 0 then
  83.         be    busywait    !       .    goto BUSYWAIT
  84.         loadb    [r4],r5        !     r5 := the next character ( := *r4)
  85.         cmp    r5,0        !     if (char == \0)
  86.         be    loopExit    !     .  then break
  87.         add    r4,1,r4        !     r4 := r4 + 1
  88.         store    r5,[r2]        !     send char in r5 to serial output
  89.         jmp    loop        !   END LOOP
  90. loopExit:
  91.         debug            !   return to emulator
  92.         jmp    main        ! END MAIN LOOP
  93.  
  94.  
  95. message:    .ascii    "Hello, world!\n\r\0"
  96.  
  97. STACK_START    =    0x00ffff00
  98. SERIAL_STAT    =    0x00ffff00
  99. SERIAL_DATA    =    0x00ffff04
  100.