Question

In: Computer Science

Transfer in MIPS char * strtoupper(char s[]) { char c; c = s[0]; /* empty string...

Transfer in MIPS

char * strtoupper(char s[]) {

char c;

c = s[0];

      /* empty string */
      if (c == 0)
            return s;

/* convert the first character to upper case*/

if (c >= ‘a’ && d <= ‘z’) { c -= 32;

s[0] = c; }

/* convert the remaining characters*/

      strtoupper(s + 1);

return s; }

Solutions

Expert Solution

strtoupper:
        .frame  $fp,40,$31              # vars= 8, regs= 2/0, args= 16, gp= 8
        .mask   0xc0000000,-4
        .fmask  0x00000000,0
        .set    noreorder
        .cpload $25
        .set    nomacro
        addiu   $sp,$sp,-40
        sw      $31,36($sp)
        sw      $fp,32($sp)
        move    $fp,$sp
        .cprestore      16
        movz    $31,$31,$0
        sw      $4,40($fp)
        lw      $2,40($fp)
        nop
        lbu     $2,0($2)
        nop
        sb      $2,24($fp)
        lb      $2,24($fp)
        nop
        bne     $2,$0,$L2
        nop

        lw      $2,40($fp)
        b       $L3
        nop

$L2:
        lb      $2,24($fp)
        nop
        slt     $2,$2,97
        bne     $2,$0,$L4
        nop

        lb      $2,24($fp)
        nop
        slt     $2,$2,123
        beq     $2,$0,$L4
        nop

        lbu     $2,24($fp)
        nop
        addiu   $2,$2,-32
        andi    $2,$2,0x00ff
        sb      $2,24($fp)
        lw      $2,40($fp)
        lbu     $3,24($fp)
        nop
        sb      $3,0($2)
$L4:
        lw      $2,40($fp)
        nop
        addiu   $2,$2,1
        move    $4,$2
        lw      $2,%got(strtoupper)($28)
        nop
        move    $25,$2
        .reloc  1f,R_MIPS_JALR,strtoupper
1:      jalr    $25
        nop

        lw      $28,16($fp)
        lw      $2,40($fp)
$L3:
        move    $sp,$fp
        lw      $31,36($sp)
        lw      $fp,32($sp)
        addiu   $sp,$sp,40
        j       $31
        nop

Related Solutions

In C++ Consider the language L = { s$s' : s is a possibly empty string...
In C++ Consider the language L = { s$s' : s is a possibly empty string of characters other than $ , s' = reverse( s )} as defi ned in Chapter 6 . Write a recognition algorithm for this language that uses both a queue and a stack. Thus, as you traverse the input string, you insert each character of s into a queue and each character of s' into a stack. Assume that each input string contains exactly...
Write the MIPS assembly version of this C code: int weird(char[] s, int x) { int...
Write the MIPS assembly version of this C code: int weird(char[] s, int x) { int i; for (i = 0; i < x; i++) { if (s[i] == ‘A’) { return power(10, i); } } return -1; } int power(int base, int i) { int j = 0; while (j < base) { base = base * base; j++; } return base; }
[ Write in C, not C++] Define a function char* deleteSymbol(char *s, char x) that removes...
[ Write in C, not C++] Define a function char* deleteSymbol(char *s, char x) that removes the character x from string s. For s[] = “America”, a call to deleteSymbol(s, ‘a’) converts s[] = “Ame”
public static char mostFrequent(String str) {        if(str.length()==0) {            return '0';   ...
public static char mostFrequent(String str) {        if(str.length()==0) {            return '0';        }        String temp="";        for (int i = 0; i < str.length(); i++) {                 if(!temp.contains(String.valueOf(str.charAt(i)))) {                     temp += String.valueOf(str.charAt(i));                 }             }        char[] tempArray=stringToArray(temp);        int[] countArr=new int[tempArray.length];        int max=0;        for(int i=0;i<tempArray.length;i++) {            int cnt=numOccurences(tempArray[i],str);            countArr[i]=cnt;...
for C program 10 by 10 char array. char 0-9 as rows and char a-j as...
for C program 10 by 10 char array. char 0-9 as rows and char a-j as collumns.
Assume you already have a non-empty string S, which is guaranteed to contain only digits 0...
Assume you already have a non-empty string S, which is guaranteed to contain only digits 0 through 9. It may be of any length and any number of digits may occur multiple times. Starting from the front of the string, write a loop that jumps through the characters in the string according to the following rule: Examine the current character and jump that many characters forward in the string Stop if you jump past the end of the string, or...
Write a recursive Racket function "remove-char" that takes two string parameters, s and c, and evaluates...
Write a recursive Racket function "remove-char" that takes two string parameters, s and c, and evaluates to string s with all occurrences of c removed. The string c is guaranteed to be a length-1 string; in other words a single character string. For example (remove-char "abc" "b") should evaluate to "ac". Here is pseudocode that you could implement.
There is a C function decodeMorse(const String & string, char message[]). This function examines the binary...
There is a C function decodeMorse(const String & string, char message[]). This function examines the binary string and iteratively constructs a decimal value (val) and width of each binary pattern (separated by spaces), until a space or a null character ('\0') is encountered in the string. Once a space or a null character is found, this function should call the assembly code (decode_morse()) to obtain the corresponding ASCII value, for the current val and width, and place the ASCII value...
Implement function noVowel() that takes a string s as input and returns True if no char-...
Implement function noVowel() that takes a string s as input and returns True if no char- acter in s is a vowel, and False otherwise (i.e., some character in s is a vowel). >>> noVowel('crypt') True >>> noVowel('cwm') True >>> noVowel('car') False Implement function allEven() that takes a list of integers and returns True if all integers in the list are even, and False otherwise. >>> allEven([8, 0, -2, 4, -6, 10]) True >>> allEven([8, 0, -1, 4, -6, 10])...
public class StringTools {    public static int count(String a, char c) {          ...
public class StringTools {    public static int count(String a, char c) {           }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT