forked from M-Ammar1112/x86-Assembly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
count_words.ASM
87 lines (62 loc) · 1.21 KB
/
count_words.ASM
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
.model small
.stack 100h
.data
A db ' This is a test $'
count dw 0
.code
main proc
mov ax, @data
mov ds, ax
mov si, offset A
mov cx, 0
word_count:
mov al, [si]
cmp al, ' '
je skip
cmp al, '$'
je end_word_count
inc si
cmp byte ptr [si-1], ' '
jne word_count
incr:
inc cx
jmp word_count
skip:
inc si
jmp word_count
end_word_count:
mov [count], cx
mov cx, [count]
mov dl, ' '
mov ah, 2
int 21h
mov dx, cx
call print_number
mov ax, 4C00h
int 21h
main endp
print_number proc
push bx
push cx
push dx
mov bx, 10
xor cx, cx
print_no:
xor dx, dx
div bx
push dx
inc cx
or ax, ax
jnz print_no
number_pop:
pop dx
add dl, '0'
mov ah, 02h
int 21h
loop number_pop
pop dx
pop cx
pop bx
ret
print_number endp
end main