won't redistribute TASM, TLINK, TD
[dos-tasm-exercises.git] / task1__6_6.2 / main.asm
blob1613a4175298129b6b0cc25e717ce3e65eb1a42a
2 ; Copyright (C) 2008 Alexander Potashev
4 ; Calculating of the number of zero words of 10 top words in the stack
7 .model small
8 .code
10 start:
11 push 0
12 push 20
13 push 30
14 push 40
15 push 50
16 push 60
17 push 70
18 push 0
19 push 90
20 push 0
22 ;-----------------------
23 mov ax, dgroup
24 mov ds, ax
26 ;-----------------------
27 mov bp, sp ; using "bp" to access stack variables
28 mov ax, 0
30 mov cx, 10
31 next_word:
33 cmp word ptr [bp], 0 ; educational way
34 jne not_zero ;
35 inc ax ;
36 not_zero: ;
38 ; mov dx, [bp] ; --- another, "cheat" way (without "cmp") ---
39 ; sub dx, 1 ; CF=1 if dx=0
40 ; adc ax, 0 ;
42 add bp, 2
43 loop next_word
45 ;-----------------------
46 ; now "ax" contains the result (possible values: 0..10)
47 lea dx, text
49 cmp ax, 10
50 je result_10
52 inc dx
53 add al, '0'
54 mov text[1], al
56 result_10:
58 mov ah, 09h
59 int 21h
61 ;-----------------------
63 add sp, 20
65 mov ax, 4c00h
66 int 21h
68 .data
69 text db "10", 13, 10, '$'
71 .stack 256
73 end start