Search code examples
assemblymipsmips32mars-simulator

Decimal to Octal using MIPS


What is the simplest way to convert Decimal to Octal using MIPS assembly?


Solution

  • I wrote it this way:

        #the octal number is $t2
        li $t6,0 #remainder
        li $t7,0 #final octal number
        li $t8,1 #placeInNumber
        octalToDecimalLoop:
            rem $t6,$t2,8
            div $t2,$t2,8
            mul $t6,$t6,$t8
            add $t7,$t7,$t6
            mul $t8,$t8,10
            bnez $t2,octalToDecimalLoop