string - MIPS Questions: Returning ($v0), Arguments, jal and jr $ra (Code Included) -


so i've been bouncing around site site (sites helped me out: http://www.cs.uiuc.edu/class/fa05/cs232/html/l4.pdf ) can't seem find answer in simplistic terms. (oddly enough, i'm not shabby @ coding mips in mars , such, i'm not getting concept much. i'm quite knowledgeable language itself, or i'd think. after realizing i'm getting stuck on this, i'd i'm not confident. lol.)

i want understand returning in mips. understand there 2 return registers ($v0, $v1) yet of time end getting "clobbered"/overwritten when end doing syscall or something. why helpful @ all?

another question, arguments stored in $a0-$a3 registers. yet overwritten in print , such system calls. why so? how keep original argument stored in 1 register (such $a0) yet when want print out, have overwrite it?

so, difficulty here: i'm working on homework cpts 260 class, , i'm doing pretty simplistic project. i'm creating function counts length of string. here is:

.data string: .asciiz "hello" message: .asciiz "the string length is: "  .text  main: #  ** test case! ** la $a0, string jal strlen  li $v0, 4       # prints message string length la $a0, message syscall  li $v0, 1       # moves length of string $a0, print. move $a0, $t0 syscall  li $v0, 10 #exit syscall  strlen: li $t0, 0       #initializes counter len jal loop jr $ra      #infinitely loops here when compiled.  loop: lbu $t1, 0($a0) beqz $t1, done # branches "done" @ null character. addi $a0, $a0, 1 #increment character addi $t0, $t0, 1 #increment counter j loop  done: jr $ra 

i've seen one: (string length mips assembly) , gotten ideas it. yet, mine decides infinitely loop on segment i've labeled infinitely looping. why so? need use stack this?

additionally, teacher grades these projects bypassing main block, , creating own. him doing bunch of different test cases inserting different arguments. wants return $v0 answer of length. simple: move $v0, $t0 (where i'm moving length of string return register) @ end of 1 of blocks? have in code besides "main:" since bypasses mine.

edit: 1 task of multiple throughout project. later, i'll have include project , incorporate in project i'm writing. (specifically, palindrome-checker.) better start using $sp , stack?

any appreciated! knowledge briefing. if wasn't specific enough, please feel free ask questions!

thank time!

-cozmonaught

first remember function calls dealing stack (like in java or c++ or hll), in recursive call values of , v registers depend on stack level, must save them if not want lose them level another.

in first (and second) code on complicating things, don't need many jr

.data string: .asciiz "hello"  message: .asciiz "the string length is: "  .text  main: #  ** test case! ** la $a0, string jal strlen  li $v0, 4       # prints message string length la $a0, message syscall  li $v0, 1       # moves length of string $a0, print. move $a0, $t0 syscall  li $v0, 10 #exit syscall  strlen: li $t0, 0       #initializes counter len  loop: lbu $t1, 0($a0) beqz $t1, done # branches "done" @ null character. addi $a0, $a0, 1 #increment character addi $t0, $t0, 1 #increment counter j loop  done: jr $ra 

you had added 2 lines don't need , create infinite loop (you call , return @ same address infinitely).


Comments

Popular posts from this blog

visual studio - vb.net filter binding source by time -

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -