-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharmstrong.asm
More file actions
76 lines (67 loc) · 972 Bytes
/
Copy patharmstrong.asm
File metadata and controls
76 lines (67 loc) · 972 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
67
68
69
70
71
72
73
74
75
76
section .data
msg1 db "Given number is Armstrong Number", 0xa, 0xc
len1 equ $ - msg1
msg2 db "Given Number is not an Armstrong Number", 0xa, 0xc
len2 equ $ - msg2
num dq 1634 ;input your number
sum dq 0
digits dq 3
it dq 0
section .text
global _start
power:
mov ecx, [digits]
mov esi, eax
mov eax, 1
p_loop:
dec ecx
mul esi
cmp ecx, 0
jg p_loop
ret
_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
mov [digits], ecx
mov [it], ecx
sum_it:
mov ecx, [it]
dec ecx
mov [it], ecx
pop eax
call power
add [sum], eax
mov ecx, [it]
cmp ecx, 0
jnz sum_it
mov eax, [sum]
check:
mov eax, [sum]
mov ebx, [num]
cmp eax, ebx
jne non_armstrong
armstrong:
mov eax, 4
mov ebx, 1
mov ecx, msg1
mov edx, len1
int 0x80
jmp exit
non_armstrong:
mov eax, 4
mov ebx, 1
mov ecx, msg2
mov edx, len2
int 0x80
exit:
mov eax, 1
mov ebx, 0
int 0x80