title: Find SUM of ODD and EVEN digits in assembly language
body: <p>I have an assignment to find sum of even and odd digits of <code>123456789</code> by conditional jump. The sum of even digits will be stored in AX and sum of odd digits will be stored in BX register.</p>
  
  <p>I will use two arrays to solve this problem.</p>
  
  <p><code>2,4,6,8</code></p>
  
  <p><code>1,3,5,7,9</code></p>
  
  <p>The sum of first array will be save in AX and second array in BX in hexadecimal format.</p>
  
  <p>The problem is that I am beginner of Assembly Language and have no idea of conditional jumps to solve this problem. Can anyone help me to solve this assignment in a simple way?</p>
  
  <pre><code>    [org 0x0100]
      jmp start
      message: db '123456789'            ; string to be printed
      length: dw 20                        ; length of string
      clrscr:         push es
      push ax
      push cx
      push di
      mov ax, 0xb800
      mov es, ax                          ; point es to video base
      xor di, di                          ; point di to top left column
      mov ax, 0x0720                      ; space char in normal attribute
      mov cx, 2000                        ; number of screen locations
      cld                                 ; auto increment mode
      repstosw                            ; clear the whole screen
  
      pop di
      pop cx
      pop ax
      pop es
      ret
  
      ; subroutine to print a string
      ; takes the x position, y position, attribute, address of string and
      ; its length as parameters
  
      printstr:         push bp
      mov bp, sp
      push es
      push ax
      push cx
      push si
      push di
      mov ax, 0xb800
      mov es, ax                        ; point es to video base
      mov al, 80                        ; load al with columns per row
      mul byte [bp+10]                  ; multiply with y position
      add ax, [bp+12]                   ; add x position
      shl ax, 1                         ; turn into byte offset
  
      mov di,ax                         ; point di to required location
      mov si, [bp+6]                    ; point si to string
      mov cx, [bp+4]                    ; load length of string in cx
      mov ah, [bp+8]                    ; load attribute in ah
      cld                               ; auto increment mode
  
      nextchar: lodsb                   ; load next char in al
      stosw                             ; print char/attribute pair
      loopnextchar                      ; repeat for the whole string
      pop di
      pop si
      pop cx
      pop ax
      pop es
      pop bp
      ret 10
  
      start: call clrscr                ; call the clrscr subroutine
      mov ax, 10
      push ax                           ; push x position
      mov ax, 15
      push ax                           ; push y position
      mov ax, 0x12                      ; blue on black attribute
      push ax                           ; push attribute
      mov ax, message
      push ax                           ; push address of message
      push word [length]                ; push message length
      callprintstr                      ; call the printstr subroutine
      mov ax, 0x4c00                    ; terminate program
      int 0x21
  </code></pre>