x86 16 - Counting spaces in a string, it prints the string and CX stays 0. assembly 8086 -


.model  small .stack  100h .data    db   '      test $'  .code        mov ax, @data     mov ds, ax       mov si, 0     mov cx, 0    myloop:       cmp a[si], '$'     je final      cmp  a[si], ' '        inc si     je count     jmp myloop  count:      inc cx     jmp myloop  final:      mov dx, cx     mov ah, 9     int 21h  end 

you override flags "is blank" comparison subsequent "inc si"

.model  small .stack  100h .data    db   '      test $'  .code        mov ax, @data     mov ds, ax       mov si, 0     mov cx, 0    myloop:       cmp a[si], '$'     je final      cmp  a[si], ' '        jne do_not_count   ; skip count if it's not blank  count:     inc cx             ; blank, count  do_not_count:     inc si     jmp myloop  final:      ;mov dx, cx                     ; not print cx     ;mov ah, 9     ;int 21h      mov dl, cl                      ; workaround: works cx < 10     add dl, '0'     mov ah, 2     int 21h  end