ALUFTW
ALUFTW

Reputation: 2492

Decimal to Octal using MIPS

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

Upvotes: 1

Views: 2247

Answers (1)

ALUFTW
ALUFTW

Reputation: 2492

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

Upvotes: 1

Related Questions