You are on page 1of 2

.

kdata
temp1: .word 0 # set temp to 0
temp2: .word 0
temp3: .word 0
.ktext 0x80000080
sw $a0,temp1
# save
mfc0 $a0, $13 # send
andi $a0, $a0, 0x003c
srl $a0, $a0, 2
bne $a0, $0, L1 #check
e is 0. If it is not then send

a0 to temp1
refgister 13 to a0
# mask unwanted bits
# shift two bits to right to find ex.no
if external interrupt. It is external if the valu
to L1

# check if counter is running or not. If count_or = 0 then it is running


.
sw $a1, temp2 #store a1 to temp2
la $a0, count_pr #load address of count_pr
lw $a1, 0($a0) #load to check later that counter in writing
bne $a1, $0, L2 # check if not counting. If not 0 then it is NOT countin
g.Hence START counting.
# else it was counting, so STOP COUNTING
sw 0xffffffff, count_pr # store the value into count_pr. This will stop
the counter as it was currently 0, hence it was running.
j L1 # exit
L2:
sw, $0, count_pr # set to 0 as it was not 0. This will start the counter
from next cycle. START COUNTING
j L1 # exit now that the count_pr has been set to counter to count
L1:

lw $a1, temp2 # restore a1


lw $a0, temp1 # restore a0
rfe

.data
count_pr: .word
count_read: .word
pulse_width .word

0xffffffff
0x00000000
0

.text
.globl main
main:
la $t0, count_pr #load address of count_pr
lw $t1, 0($t0) #load value of count_pr
beq $t1, $0, main # if count_pr value is 0, so its counting, the
n loop back to main as the count_read is not readable yet.
# if the counter has stopped now then get the count read value
la $t0, count_read #load address of count_read
lw $t2, 0($t0) #load value of count_read
# now divide the count_read value by 10
addi $t3, $0, 10
div $t2, $t3 # divide count_read by 10. Stored quotient in LO. u

se mflo
mflo pulse_width

You might also like