Question: The first three problems in this Exercise refer to the following function, given in MIPS assembly. Unfortunately, the programmer of this function has fallen prey

The first three problems in this Exercise refer to the following function, given in MIPS assembly. Unfortunately, the programmer of this function has fallen prey to the pitfall of assuming that MIPS is a word-addressed machine, but in fact MIPS is byte-addressed.; int f(int *a, int n, int x); f: move $v0,$0 : ret=0 move $t0,$a0 : ptr-a add $t1,$al, $a0; &(a[n]) $t2,0b. ; void f(int a[], int n); f: move $t0,$0 ; i=0; ; n-1 ; address of a[i] : read a[i+1] : a[i]-a[i+1] ;

Note that in MIPS assembly the “;” character denotes that the remainder of the line is a comment.


If “a” was a pointer to the beginning of an array of 1-byte elements, and if we replaced lw and sw with lb (load byte) and sb (store byte), respectively, would this function be correct? Note: lb reads a byte from memory, sign-extends it, and places it into the destination register, while sb stores the least significant byte of the register into memory.

; int f(int *a, int n, int x); f: move $v0,$0 : ret=0 move $t0,$a0 : ptr-a add $t1,$al, $a0; &(a[n]) $t2,0 ($t0) $t2,$a2, S L: lw : read *p ; if(*p=x) $v0, $v0,1 ; ret++; : p=p+1 bne addi S: addi $t0,$t0,1 bne $t0,$t1, L $ra : repeat if p!-&(a[n]) return ret ;

Step by Step Solution

3.46 Rating (153 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

If we replace the lw load word and sw store word instructions with lb load byte and sb store byte in... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Computer Organization Design Questions!