lundi 17 septembre 2018

Getting a loop to show all the powers of 2 from 2048 until 1, display 2048, 1024, 512,...,1

Using MIPS, I got code to show using SRL to registers all the powers of 2 starting with 2048 until 1. However, it will only display 1. What I want it to do is show all the powers of 2. So for example, I want it to display 2048, 1024, 512, 258, 128, 64, 32, 16, 8, 4, 2, 1. I would have to probably use a loop or something, but being new to MIPS I don't quite understand how I would get this done. Here is my code so far....

li $t1, 2048    #Intialize $t1 to 2048
srl $t1, $t1, 11    #Shift right 11 times
add $a0, $t1, $zero #Load contents of variable i to $a0 
li $v0, 1   #Print integer
syscall

I would probably want to run a loop saying like, "if $t1 doesn't equal 1, then display the value of $t1," and have that keep running until $t1 does equal 1, then stop the program right?

Aucun commentaire:

Enregistrer un commentaire