i need to count words, where is more big letters than numbers.
I use inr c if big letter is in word and dcr c if there is number. At the end of word i try c>0, if it is true, I do inr d. d is number of words with more big letters than numbers. Problem is, that c>0 is always true. (i think, because it count all words).
cpi 'A' ;find if it is letter
jnc mozno_pismeno
cpi '9'+1 :find if it is number
jc mozno_cislo
mozno_pismeno: ;maybe it is letter
cpi 'Z'+1 ;second chceck if it is letter
jc je_to_pismeno
jmp getchar_main
je_to_pismeno: ;it is letter so inr c
inr c
jmp getchar_main
mozno_cislo: ;maybe it is number
cpi '0' ;second check if it is number
jnc je_to_cislo
jmp getchar_main
je_to_cislo: ;it is number so dcr c
dcr c
jmp getchar_main
koniec_slova: ;it is end of the word
mov a,c
cpi 1 ;if c>0 that mean that there was more letters
jnc ma_viac_pismen
mvi c,0 ;prepare c for next one character
jmp getchar_main
ma_viac_pismen: ;c>0 so inr d
inr d
mvi c,0 ;prepare c for next one character
jmp getchar_main
CPIsets the carry flag according to the results of the unsigned comparison. In other words, if you have more digits than letters, then your negative number is actually treated as a big positive number.However, it also sets the Sign flag according to the sign of the subtraction result, which for the most part tends to be the same as the result of the signed comparison. So the first solution can be replacing
JNCandJCin your final part withJPandJMrespectively. This won't work correctly with some larger inputs though, as-128-1yields127and the Sign flag will incorrectly suggest that-128 > 1.Another way of doing signed comparison on Intel 8080 is doing
XRI 128 / CPI x+128and using the Carry flag again (so, shifting all numbers by 128 and doing an unsigned comparison). So the second solution you can try is replacingCPI 1withXRI 128 / CPI x+129. This is a bit slower, but it doesn't have the overflow issue like the first option.(Don't apply both solutions though, as it won't work).