There is a program for counting odd elements. How to write a count of elements not equal to zero?

Turbo assembler

mov ax, data mov ds, ax lea bx, mas ;берём в bx адрес первого элемента mov cx, len ;счетчик цикла xor ax, ax ;обнуляем регистр cikl: mov al, [bx] ;прибавляем к al байт, адрес которого хранится в bx test ax,1 ;проверяем на четность jnz next inc numb; увеличиваем, если четно next: inc bx ;переходим к следующему элементу loop cikl 
  • Comments do not match the code: mov al, [bx] not an "append", it is an assignment. test ax, 1 is not a parity check, it is a test for equality to one. - yeputons
  • one
    @yeputons, test ax, 1 is the low bit test for equality to one. It so happens that even numbers have a low bit of 0, and odd numbers have a 1 bit. So, this is quite a parity check. - insolor
  • Well, for example or ax,ax and perkhod on the presence / absence of the flag Z - Mike
  • @insolor is really confused with cmp . - yeputons

1 answer 1

  1. Change the parity check to check to 0:

     test ax, ax ; эквивалентно cmp ax, 0, но в скомпилированном виде короче 
  2. After the check, there should be a transition if the check has set the flag Z (that is, if we hit the zero element):

     jz next