-2

Similar to this problem: convert an integer number into an array but I don't know how this is implemented in MIPS.

1
  • Yes, it can be done. This is not special to MIPS, so try a C version first, once you have that working, then translate to assembly. Commented Feb 8, 2020 at 17:27

1 Answer 1

0

Of course there is a way. You divide by 10 for every digit in your number and store the remainder in your array. This will probably do the job:

.data
array: .word 

.text
.globl main

main:
la $t9, array
li $t1, 45            #number to be stored
li $t2, 10            #base 10

while:
beq $t1, $0, end     

div $t1, $t2        # divide by ten, $hi = $t1/$t2, $lo = $t1 mod $t2
mfhi $t3        
mflo $t1
sw $t3, 0($t9)      #store word into array
addi $t9, $t9, 4    #increment array index
j while
end:
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.