The _strLength function should return the length of a null-terminated string. Ar
ID: 3584971 • Letter: T
Question
The _strLength function should return the length of a null-terminated string.
Argument: $a0 = address of a null-terminated string
Return value: $v0 = length of the specified string
Note that the null character has a value equal to 0. You can load the value of a byte at a given address in memory using the lbu (“load byte unsigned”) instruction. Combined with the loop, comparison, and branching constructs discussed in previous labs, you can detect when a null character is reached, then simply return the number of characters in the string to the caller.
This should be done in MIPS.
Homework 3 pdf My Pitt Home × e Chegg Study Guided S: × / D Lab 4.pdf (--> d Secure | https://coursewebpitt.edu/bbcswebdav/pid-240601 91-dt-content-rid-22008127 2/courses/2181 UPITT CS 0447 SEC1070/Lab%204.pdf Lab 4.pdf The ten $t registers are "temporary registers." A caller should save the values of these registers to the stack before calling a function if they will still be needed after the function returns, at which point it should restore them. Save your answer as "lab4 C.asm" D. Implement the strLength Function The_strLength function should return the length of a null-terminated string. Argument: Sa0- address of a null-terminated string Return value: Sv0 length of the specified string Note that the null character has a value equal to 0. You can load the value of a byte at a given address in memory using the lbu "load byte unsigned") instruction. Combined with the loop, comparison, and branching constructs discussed in previous labs, you can detect when a null character is reached, then simply return the number of characters in the string to the caller Save your answer as "lab4 D.asm Save "lab4 B.asm" "lab4_C.asm" and lab4 D.asm" as First name_Last name_Lab4.zip" and submit it on CourseWeb. 12:01 PM 1022017 lype here to search 70%AExplanation / Answer
.text
main:
la $a0, input # load user's string into 'input'
li $a1, 80
li $v0, 8
syscall
la $a0, input # call strlen(input)
jal strlen
nop
move $a0, $v0 # display result of strlen
li $v0, 1
syscall
li $v0, 10 # exit program
syscall
strlen: li $v0, -1 # $v0 has length - start at -1 because '' counted
slen_0: lbu $t0, ($a0) # load current byte, move to next (LOOP)
addi $a0, $a0, 1
bne $t0, $zero, slen_0 # if current byte isn't '', repeat
addi $v0, $v0, 1 # but first increment result
jr $ra # return to caller
nop
.data
input: .space 80
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.