-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpalindrome.asm
More file actions
66 lines (59 loc) · 898 Bytes
/
Copy pathpalindrome.asm
File metadata and controls
66 lines (59 loc) · 898 Bytes
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
section .data
msg1 db "Given number is a Palindrome", 0xa, 0xc
len1 equ $ - msg1
msg2 db "Given number is not a Palindrome", 0xa, 0xc
len2 equ $ - msg2
num dq 15151 ;input your number here
rev_num dq 0
digits dq 3
it dq 0
section .text
global _start
_start:
mov eax, [num]
xor ecx, ecx
div_loop:
inc ecx
mov esi, 10
xor edx, edx
idiv esi
push edx
cmp eax, 0
jnz div_loop
xor edx, edx
mov esi, 1
mov ebx, 1
create_rev_number:
dec ecx
mov eax, esi
imul ebx
mov esi, eax
mov ebx, 10
pop eax
imul esi
mov edx, [rev_num]
add edx, eax
mov [rev_num], edx
cmp ecx, 0
jnz create_rev_number
check:
mov eax, [num]
cmp eax, edx
jne non_palindrome
palindrome:
mov eax, 4
mov ebx, 1
mov ecx, msg1
mov edx, len1
int 0x80
jmp exit
non_palindrome:
mov eax, 4
mov ebx, 1
mov ecx, msg2
mov edx, len2
int 0x80
exit:
mov eax, 1
mov ebx, 0
int 0x80