



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 44
main
reverse
len
reverse(s,r)
len(s) (^12)
N/A
How can we do this with assembly?
CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 45
CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 46
CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 47
# procedure reverse($a0,$a1) reverse: move $t7,$ra # save return address jal len # get length of source string blt $v0,$0,rev_exit # exit if empty string add $t0,$a1,$v0 # null terminate target string sb $0,0($t0) # put null into end of string addi $v0,$v0,-1 # decrement length (written /0) add $t0,$a0,$v0 # $t0 holds p (source string) add $t1,$a1,$0 # $t1 holds t (target string) rev_loop: lbu $t2,0($t0) # get char from source string sb $t2,0($t1) # save char to target string addi $t0,$t0,-1 # decrement source string ptr addi $t1,$t1,1 # increment target string ptr addi $v0,$v0,-1 # decrement length slt $t2,$v0,$0 # is l < 0? beq $t2,$0,rev_loop rev_exit: move $ra,$t jr $ra
CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 50
CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 51
CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 52
CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 53
Stack pointer ($sp)
Procedure frame
CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 56
See factorial.asm