lundi 24 février 2020

How do you add more than one condition to a loop in MIPS assembly language?

I am currently working on a homework problem for asssembly code that requires us to check whether a number is even or odd. I am thinking of making an if/else loop that subtracts the given number by two until the number equals either 1 or 0, then checking which one it is so it can tell you that the number is odd or even (even if 0, odd if 1). One problem I am having, however, is that I do not know how to add a condition that checks if the number is either 1 or 0. Also, I'm not sure if I'm jumping to each loop correctly, as well as write up code that will tell the user in text that the number is even or odd. Here is the code I am thinking up currently:

    addi s0,0,x                  #x is substituted with whatever number the user wants to check
    addi s1,0,2
    addi s2,0,0 
    addi s3,0,0

    bne s0, s2,else OR s0, s3,else       #Here, I want the code to check if s0 equals s2 or s3.  If so,
                                         #I want itt to jump to a second if statement that will tell you 
                                         #if the number is even or odd.  If it is not, I want it to jump 
                                         #a loop that subtracts by 2 again.
   else:                                  
       sub s0, s0, s1                      # Here I'm pretty sure I have my subtraction right, but how do 
                                           # I jump back to the for loop to check if it is 1 or 0 again?                    

Aucun commentaire:

Enregistrer un commentaire