-2

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

dela
  • 3
  • 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. – Erik Eidt Feb 08 '20 at 17:27

1 Answers1

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:
robindust
  • 16
  • 2