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
36
37
38
39
40
41
42
43
44
45
46
|
.section .text
.align 2
.global set_LED
.include "memory_map.inc"
.include "gpio.inc"
.equ NOERROR, 0x0
.equ ERROR, 0x1
.equ LEDON, 0x1
# a0 contains LED to set, desired LED state in a1
# a0 is also the return value...
set_LED:
addi sp, sp, -16 # Allocate stack frame
sw ra, 12(sp) # save return address to the stack
li t0, GPIO_CTRL_ADDR # load base GPIO address
lw t1, GPIO_OUTPUT_VAL(t0) # load state
beqz a1, ledOff # branch if == 0
li t2, LEDON # load up on val into t2
beq a1, t2, ledOn # branch if on requested
li a0, ERROR # bad status request, return error
j exit
ledOn:
or t1, t1, a0 # only change the value of the requested LED (xor in the video)
sw t1, GPIO_OUTPUT_VAL(t0) # write new LED values to the right address
li a0, NOERROR # success
j exit
ledOff:
xor a0, a0, 0xffffffff # invert bits so off bits are off
and t1, t1, a0 # turn of LEDs
sw t1, GPIO_OUTPUT_VAL(t0) # write new LED values to the right address
li a0, NOERROR # success
exit:
lw ra, 12(sp) # load return address
addi sp, sp, 16 # deallocate stack frame
ret
|