title: How can I implement if(condition1 && condition2) in MIPS?
body: <p>I have written the following function to check whether a character is a digit or not:</p>
  
  <pre><code># IsDigit - tests a if a character a digit or not 
  # arguments:
  #   $a0 = character byte
  # return value:
  #   $v0 =   1 - digit
  #           0 - not a digit
  IsDigit:
      lb $t0, ($a0) # obtain the character
      li $t1, 48 # '0' - character
      li $t2, 57 # '9' - character
      bge $t0, $t1, condition1
  condition1:
      ble $t0, $t2, condition2
  
      li $v0, 0
      j return
  
  condition2:
      li $v0, 1
  
  return:                                                                                 
      # return 
      jr $ra 
  </code></pre>
  
  <p>Is there any better way to do or write this?</p>
  
  <p><strong>Edit:</strong> The following is the version-2</p>
  
  <pre><code>IsDigit:
      lb $t0, ($a0) # obtain the character
      li $t1, 48 # '0' - character
      li $t2, 57 # '9' - character
      bge $t0, $t1, condition1
  
      j zero
  
  condition1: 
  
      ble $t0, $t2, condition2
  
  zero:
      li $v0, 0
      j return
  
  condition2:
      li $v0, 1
      j return
  
  return:                                                                                 
      # return 
      jr $ra 
  </code></pre>
  
  <p><strong>Edit-2</strong>: the following is version-3</p>
  
  <pre><code>IsDigit:
      lb $t0, ($a0) # obtain the character
      li $t1, 48 # '0' - character
      li $t2, 57 # '9' - character
  
  
      bge $t0, $t1, con1_fulfilled #bigger tha or equal to 0  
      j con1_not_fulfilled
  
  con1_fulfilled:
      ble $t0, $t2, con2_fullfilled #less than or equal to 9
      j con2_not_fulfilled
  
  con2_fullfilled:
      li $v0, 1
      j return
  
  con1_not_fulfilled:
  con2_not_fulfilled:
      li $v0, 0
  
  return:                                                                     
      # return 
      jr $ra 
  </code></pre>