-
Notifications
You must be signed in to change notification settings - Fork 16
/
palindrome_check.asm
107 lines (90 loc) · 1.43 KB
/
palindrome_check.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
107
; Given an input string containing alphanumeric characters.
; Check whether the string is a palindrome or not. Ignore case of letters in the input.
; For example:
; Input: AbBa
; Output: Palindrome
segment .data
a: dq 2
b: dq -1
mul: dw "The String is:",0
fmt: dq "%s %s ",10,0
fmt_in: dq "%s", 0
fmt_out: dq "%lld", 0
palin: dq "Palindrome", 10, 0
not_palin: dq "Not Palindrome", 10, 0
new_line: dq "", 10, 0
cnt: dq 0
string_sz: dq 0
section .bss
str: resq 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
LOWER_CASE_CONVERT:
cmp qword[str + RCX], 0
jz FINISH_CONVERT
mov RAX, 0
mov AL, [str + RCX]
cmp RAX, 97
jl CONVERT
DONE:
inc RCX
jmp LOWER_CASE_CONVERT
CONVERT:
mov RAX, 0
mov AL, [str + RCX]
sub RAX, 32d
mov [str + RCX], RAX
jmp DONE
FINISH_CONVERT:
mov RAX, 0
mov RBX, 0
mov RCX, 0
STRING_SIZE:
cmp qword[str + RCX], 0
jz FINISH
inc qword[string_sz]
inc RCX
jmp STRING_SIZE
FINISH:
mov RAX, 0
mov RBX, [string_sz]
mov RCX, 0
dec RBX
COMPARE:
cmp qword[str + RCX], 0
jz PALINDROME
mov [cnt], RCX
xor RAX, RAX
mov AL, [str + RCX]
xor RDX, RDX
xor DL, [str + RBX]
cmp RAX, RDX
jnz NOT_PALINDROME
mov RCX, [cnt]
inc RCX
dec RBX
jmp COMPARE
PALINDROME:
mov RDI, palin
jmp PRINT
NOT_PALINDROME:
mov RDI, not_palin
PRINT:
call printf
mov RDI, new_line
call printf
END:
mov RAX, 0
pop RBP
ret