- ! Not So Simple Typing Program
- ! Blake Haas
- .begin
- ! Constants
- BASE .equ 0x3fffc0 ! Starting point of the memory mapped region
- CONSOLE .equ 0x0 ! 0xffff0000 Console Data Port
- CONSOLE_STATUS .equ 0x4 ! 0xffff0004 Console Status Port (-0x80 = Not Ready)
- KEYBOARD .equ 0x8 ! 0xffff0008 Keyboard in port
- KEYBOARD_STATUS .equ 0xc ! 0xffff000c Keyboard status port
- ! Push the contents of a register onto the stack.
- .macro PUSH arg1
- st arg1, %r14 ! Store the value
- sub %r14, 4, %r14 ! Decrement the stack pointer
- .endmacro
- ! Pop whatever is on the top of the stack and put it in arg1
- .macro POP arg1
- add %r14, 4, %r14 ! Incremement the stack
- ld %r14, arg1 ! Get the value
- .endmacro
- .macro POPESC arg1
- add %r17, 4, %r17 ! Incremement the stack
- ld %r17, arg1 ! Get the value
- .endmacro
- .macro PUSHESC arg1
- st arg1, %r17 ! Store the value
- sub %r14, 4, %r17 ! Decrement the stack pointer
- .endmacro
- .macro RETURN
- jmpl %r15 + 4, %r0
- .endmacro
- !-------------------------------------------------------
- ! Start
- !-------------------------------------------------------
- .org 2048
- mov %r0,%r14
- ld [SP], %r14 ! Load the address of our string onto the stack
- MAIN_LOOP:
- call READ_CHAR
- POP %r1
- subcc %r1, 0x1B, %r0 ! Compare with ESC
- be QUIT
- PUSH %r1
- call PRINT_CHAR
- ba MAIN_LOOP
- QUIT:
- addcc %r0, %r10, %r6
- loop:
- ! Grab the char to print
- call PRINT_CHAR_WAIT
- subcc %r6, 1, %r6
- bne loop
- halt
- !-------------------------------------------------------
- !-------------------------------------------------------
- ! READ_CHAR FUNCTION
- ! Reads a single char from the input console
- ! RETURN = Char Found
- !-------------------------------------------------------
- READ_CHAR:
- ! We never call out, so %r15 is safe- don't need to store it
- add %r0, %r0, %r4 ! %r4 Holds the base address
- sethi BASE, %r4 !
- READ_CHAR_WAIT:
- ldub [%r4 + KEYBOARD_STATUS], %r1 ! Get the status
- andcc %r1, 0x80, %r1 ! Add 0x80 - if we're ready, this is not zero
- be READ_CHAR_WAIT ! Loop
- ldub [%r4 + KEYBOARD], %r3 ! Get the char
- PUSH %r3
- ! Push the result on the stack and...
- RETURN ! Return
- !-------------------------------------------------------
- !-------------------------------------------------------
- ! PRINT_CHAR FUNCTION
- ! Prints a single char to the output console
- ! ARG1 = Char to print
- ! RETURN = Nothing
- !-------------------------------------------------------
- PRINT_CHAR:
- POP %r1 ! Grab the char to print
- ! We never call out, so we can assume %r15 stays put
- add %r0, %r0, %r4 ! %r4 Holds the base address
- sethi BASE, %r4 !
- PRINT_CHAR_WAIT: ! We have to wait for the console to be ready!
- ldub [%r4+ CONSOLE_STATUS], %r5
- ! Load the console status (as an unsigned byte) into %r5
- andcc %r5, 0x80, %r5 ! -0x80 = no console not ready, so add 0x80 to the value and compare against zero
- be PRINT_CHAR_WAIT ! Loop while we're not ready
- stb %r1, [%r4 + CONSOLE] ! We're ready - put the char to print into the console memory location
- add %r10, 1, %r10
- RETURN
- !-------------------------------------------------------
- SP: 0x7FFFFFFC
- .end
STACKS
By: microhaxo | Date: Jul 4 2009 03:15 | Format: None | Expires: never | Size: 3.25 KB | Hits: 1174
Latest pastes
2 days ago
3 days ago
3 days ago
4 days ago
5 days ago