-
Notifications
You must be signed in to change notification settings - Fork 16
/
vowel_consonant_in_string.asm
106 lines (87 loc) · 1.51 KB
/
vowel_consonant_in_string.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
; Given an input string (upper case letters only). Count the number of vowels and
; consonants in the string. For example, if the user gives “this is a string.” Then your
; program should print
; “Given input: this is a string”
; “Vowels: 8 Consonants: 15”
segment .data
a: dq 2
b: dq -1
fmt: dq "%s %s ",10,0
fmt_in: dq "%s", 0
fmt_out: dq "The String is: %s", 10, 0
fmt_out_nxt: dq "Vowels: %lld, Consonants: %lld", 10, 0
fmt_character: dq "The character is: %c", 10, 0
fmt_debug: dq "HERE : %c", 10, 0
new_line: dq "", 10, 0
cnt: dq 0
tmp: dq 0
vowel: dq 0
consonant: dq 0
section .bss
str: resb 20
segment .text
global main
extern printf
extern scanf
main:
push RBP
mov RAX, 0
mov RSI, str
mov RDI, fmt_in
call scanf
mov RAX, 0
mov RBX, 0
mov RCX, 0
SCAN_STRING:
cmp byte[str + RCX], 0
jz PRINT
mov [cnt], RCX
mov RAX, 0
mov AL, [str + RCX]
mov [tmp], RAX
mov RAX, 0
mov RBX, 0
mov RAX, qword[tmp]
mov RBX, 65
cmp RAX, RBX
jz INC_VOWEL
mov RBX, 69
cmp RAX, RBX
jz INC_VOWEL
mov RBX, 73
cmp RAX, RBX
jz INC_VOWEL
mov RBX, 79
cmp RAX, RBX
jz INC_VOWEL
mov RBX, 85
cmp RAX, RBX
jz INC_VOWEL
jmp INC_CONS
INC_VOWEL:
inc qword[vowel]
mov RCX, [cnt]
inc RCX
jmp SCAN_STRING
INC_CONS:
inc qword[consonant]
mov RCX, [cnt]
inc RCX
jmp SCAN_STRING
PRINT:
mov RAX, 0
mov RDI, fmt_out
mov RSI, str
call printf
mov RDI, new_line
call printf
mov RDI, fmt_out_nxt
mov RSI, [vowel]
mov RDX, [consonant]
call printf
mov RDI, new_line
call printf
END:
mov RAX, 0
pop RBP
ret