Help numb 6
What is accomplished by the overall function? Be Specific! After the function call, what is the value of “Q”? Write out the contents of phrase exactly as they would appear. Translate the following C code into assembly code. Do NOT write your own strlen() function, just call it correctly. char phrase [] = “Almost DONE!”}//assume that “phrase” is already initialized int x = strlen(phrase), y = 0;//while (y
Expert Answer
6)
char phrase[] = “Almost DONE!”;
int x = strlen(phrase), y=0;
while(y<x) {
if(phrase[y] == ‘0’) break;
y++;
}
return y;
———————————————————————————————————–
sample():
addiu $sp,$sp,-56
sw $31,52($sp)
sw $fp,48($sp)
move $fp,$sp
lui $2,%hi($LC0)
lw $5,%lo($LC0)($2)
addiu $3,$2,%lo($LC0)
lw $4,4($3)
addiu $3,$2,%lo($LC0)
lw $3,8($3)
sw $5,32($fp)
sw $4,36($fp)
sw $3,40($fp)
addiu $2,$2,%lo($LC0)
lbu $2,12($2)
nop
sb $2,44($fp)
addiu $2,$fp,32
move $4,$2
jal strlen
nop
sw $2,28($fp)
sw $0,24($fp)
lw $3,24($fp)
lw $2,28($fp)
nop
slt $2,$3,$2
beq $2,$0,$L2
nop
lw $2,24($fp)
addiu $3,$fp,24
addu $2,$3,$2
lb $3,8($2)
li $2,48 # 0x30
beq $3,$2,$L6
nop
lw $2,24($fp)
nop
addiu $2,$2,1
sw $2,24($fp)
b $L4
nop
nop
lw $2,24($fp)
move $sp,$fp
lw $31,52($sp)
lw $fp,48($sp)
addiu $sp,$sp,56
j $31
nop