title: 8086 assembly language program to find number of odd and even numbers in an array of 16-bit hexadecimal numbers
body: <p>In order to determine if the hexadecimal no is even, the program would divide the number by 2 and the remainder should be equal to zero. If not, then it is an odd number. Initially, my plan was to I have a variable or register that will increment when a hexadecimal is proven to be even. Then afterwards I would just subtract the number of even nos. to five to get the number of odd nos. But since I had to use three registers to hold the dividend and divisor (<code>AX &amp; BX</code>), plus another for the array counter (<code>CX</code>), I ran out of registers to hold the value of the &quot;even counter&quot;.</p>
  <p>I revised the program so that it can still satisfy the instruction (see title). This time, the program would display the character <code>E</code> for even and <code>O</code> for odd. My problem now is the program only recognizes up to the second array item, meaning the value of <code>SI</code> remains the same and does not increment after the second array item. This makes the output of the program <code>EOOOO</code> instead of <code>EOOOE</code>.</p>
  <p>My questions are:
  1.) How will I increment the value of <code>SI</code> from its memory and pass it to <code>AX</code> to be divided
  2.) Is it possible to make my initial plan work? If yes, what register can I use to hold the &quot;even counter&quot;</p>
  <p>Here is the code:</p>
  <pre><code>.MODEL SMALL
   
  READ MACRO MSG
      MOV AH,0AH
      LEA DX,MSG
      INT 21H
  ENDM
  
  SET MACRO MSG
      MOV AH,09H
      LEA DX,MSG
      INT 21H
  ENDM
  
  .DATA 
   
   CR EQU 0DH
   LF EQU 0AH
      ARR DW 100h,16Fh,191h,10Fh,120h 
      MSG1 DB CR,LF,&quot;Array of 16 bit hexadecimals: 100h,16Fh,191h,10Fh,120h$&quot;
      MSG2 DB CR,LF,&quot;E=EVEN   O=ODD$&quot;
      
      NUMERALEVEN DB CR,LF,&quot;E$&quot;
      NUMERALODD DB CR,LF,&quot;O$&quot;
      
   COUNT EQU 5H
   
  
  DATA ENDS
  
      
  .CODE
  ASSUME CS:CODE,DS:DATA 
  
  START:
          MOV AX,DATA
          MOV DS,AX
      
          SET MSG1
          SET MSG2
          
          MOV SI,OFFSET ARR
          MOV CL,COUNT
          MOV AX,[SI]
          
          MOV DX,0000
  
                  
  CHECK:  
          MOV DX,0000                       
          MOV BH,00
          MOV BL,02H     ;divide by 2  
          DIV BX         
          
          CMP DX,0       ;checks if there is a remainder by comparing the remainder to 0
          JE EVEN
          JNE ODD        
          
          
  EVEN:   
          SET NUMERALEVEN
          
          MOV DX,00 
          DEC CL
          MOV AX,[SI+1]
          MOV [SI],AX 
          
          CMP CL,0
          JNZ CHECK
          
           
  ODD:    
          SET NUMERALODD
          
          DEC CL
  
          MOV AX,00
          MOV AX,[SI+1]
          MOV [SI],AX
          
          CMP CL,0
          JNZ CHECK
                  
  CODE ENDS
  END START 
  </code></pre>