I want to create a subroutine like this:
but we should not use register and memory to save the current number. we have to solve this by changing the code (self-modifying). Is there any way?
This is the solution which I found:
# subroutine
nextInt: # return value is in $v0
add $v0,$zero,0
la $t0,nextInt # load subroutine address
lw $t1,0($t0) # load content of address
addi $t1,$t1,1 # change content (increment)
sw $t1,0($t0) # save
jr $ra