-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyboard.asm
35 lines (28 loc) · 968 Bytes
/
keyboard.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
##############################################################################
# Example: Keyboard Input
#
# This file demonstrates how to read the keyboard to check if the keyboard
# key q was pressed.
##############################################################################
.data
ADDR_KBRD:
.word 0xffff0000
.text
.globl main
main:
li $v0, 32
li $a0, 1
syscall
lw $t0, ADDR_KBRD # $t0 = base address for keyboard
lw $t8, 0($t0) # Load first word from keyboard
beq $t8, 1, keyboard_input # If first word 1, key is pressed
b main
keyboard_input: # A key is pressed
lw $a0, 4($t0) # Load second word from keyboard
beq $a0, 0x71, respond_to_Q # Check if the key q was pressed
li $v0, 1 # ask system to print $a0
syscall
b main
respond_to_Q:
li $v0, 10 # Quit gracefully
syscall