diff options
Diffstat (limited to 'software/first/delay.S')
-rw-r--r-- | software/first/delay.S | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/software/first/delay.S b/software/first/delay.S new file mode 100644 index 0000000..cb49ba1 --- /dev/null +++ b/software/first/delay.S @@ -0,0 +1,26 @@ +.section .text +.align 2 +.global delay +.include "memory_map.inc" + + +# a0 is delay in milliseconds argument + +delay: + addi sp, sp, -16 # Allocate stack frame + sw ra, 12(sp) # save return address to the stack + + li t0, MTIME # load the timer register + lw t1, 0(t0) # load value of the timer + + li t2, MTIME_FREQUENCY # get clock freq (approx.) + mul t2, t2, a0 # multiply milliseconds with freq + add t2, t1, t2 # target mtime is now in t2 + +1: + lw t1, 0(t0) # load value of the timer + blt t1, t2, 1b # keep looping until target mtime has been reached + + lw ra, 12(sp) # load return address + addi sp, sp, 16 # deallocate stack frame + ret |