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

## Start of file funct2.a ## ## MIPSMARK 1.1 21/4/99 Copyright 1998 J. Waldron.

ID: 3679202 • Letter: #

Question

## Start of file funct2.a
##
## MIPSMARK 1.1 21/4/99 Copyright 1998 J. Waldron.
## All Rights Reserved. See the file README for
## a full copyright notice.
##
## Question:
## Write a function "hexint" that takes the address
## of an ascii character string in $a0.
## The string will represent a number in
## hexadecimal and will only contain '0' to '9'
## and 'A' to 'F'.
## Return the actual number in the register $v0.
## Remember that the most significant nibble
## will be first in the string.
##
## Output format must be:
## "Number is = 1960"

#################################################
#                      #
#       text segment           #
#                       #
#################################################

   .text      
    .globl main
main:       # execution starts here


   la $a0,ans
   li $v0,4
   syscall

   la $a0,str
   jal hexint   # call hexint function

   move $a0,$v0
   li $v0,1
   syscall

   la $a0,endl   # system call to print
   li $v0,4   # out a newline
   syscall

exit:   li $v0,10
   syscall       # au revoir...

# Any changes above this line will be discarded by
# mipsmark. Put your answer between dashed lines.
#-------------- start cut -----------------------

#-------------- end cut -----------------------
# Any changes below this line will be discarded by
# mipsmark. Put your answer between dashed lines.

#################################################
# #
# data segment #
# #
#################################################

.data
str:   .asciiz "7A8"
ans:   .asciiz "Number is = "
endl:   .asciiz " "
##
## End of file funct2.a

Explanation / Answer

Well, I dont have MIPS compiler (forgive for that), but I tried my best to not make any mistakes:

Here you go:

hexint:

zero :

li   v0, 1

jr $ra

one :

li $v0, 16

jr $ra

two:

li $v0, 256

jr $ra