Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

When you arrived at UMass you were given a unique student ID number. You may hav

ID: 3895747 • Letter: W

Question

When you arrived at UMass you were given a unique student ID number. You may have wondered how this number was chosen. In this assignment you will develop a MIPs program to replace the mechanism used by UMass to assign student ID numbers. The new approach assigns a number to each letter of the alphabet. The letters in the student name are then converted to numbers and they are summed to form a new ID number. For example, each of the 26 English letters can be assigned a number associated with its place in the alphabet (e.g. ‘a,-1, ‘z,-26, etc). The numbers associated with the letters in the student name can then be summed to determine the final student ID number (e.g. abe 'a, + ‘b, + ‘e' = 1 + 2 + 5-8). Of course, in reality, issues regarding duplicate ID numbers for students would need to be resolved, but for the purposes of this assignment let's assume that each student generates a unique number. The number of digits in the final number isn't important either. For this lab assignment, you are asked to calculate the "sum" of your name in MIPS assembly code. The MIPs code will be developed by translating two C functions. In earlier courses, you learned how to define and use groups of characters stored in an array. For example, in C language an array is defined to store all the letters in "russell

Explanation / Answer

ScreenShot

-----------------------------------------------------------

Code

#main declaration
.globl main
#Variable declaration , here your name is in string
.data
      Name: .asciiz "yourname" # address 0x10010000
#Main program
.text
      #stack starting point address
      lui $sp,0x8000
main:
      #Stack space allocation to store values of variables
      addiu $sp,$sp,-20
      #store return address
      sw $ra,16($sp)
      #Read the string
      lui $t0,0x1001
      ori $t0,$t0,0x0000
      #store starting address of the string
      sw $t0,12($sp)
      #length of the string
      addi $t1,$0,8
      #store length in stack
      sw $t1,8($sp)
      #result variable
      addiu $s0,$0,0
      #store in stack
      sw $s0,4($sp)
#loop to call getNumber function and calculate sum to generate Id
loop:
      #compare to get all characters in name
      beq $t1,0,exit
      #Each character by character
      lb $a0,0($t0)
      #call charcter corresponding number getting function
      jal getNumber
      #store result in t2
      move $t2,$v0
      #calculate all character sum
      add $s0,$s0,$t2
      #increment to get next character
      addi $t0,$t0,1
      #decrement counter
      addi $t1,$t1,-1
      j loop
#Exit from the program
exit:
     #to display sum
     move $a0,$s0
     addiu $v0,$0,1
     syscall
     #restore all stored values from stack
     lw $s0,4($sp)
     lw $t1,8($sp)
     lw $t0,12($sp)
     lw $ra,16($sp)
     #clear the stack
     addiu $sp,$sp,20
     #end of the program
     addiu $v0,$0,10
     syscall
#Function to get each character corresponding number  
getNumber:
      sub $v0,$a0,97
      addi $v0,$v0,1
      jr $ra

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote