-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathequality_of_strings.asm
More file actions
106 lines (90 loc) · 1.35 KB
/
equality_of_strings.asm
File metadata and controls
106 lines (90 loc) · 1.35 KB
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 2 input strings. Check if the two strings are equal (case sensitive).
; Example:
; Input: abcd abcd
; Output: Equal
; Input: abCd abcd
; Output: Not equal
segment .data
a: dq 2
b: dq -1
fmt: dq "%s %s ",10,0
fmt_in: dq "%s", 0
fmt_equal: dq "Equal", 10, 0
fmt_not_equal: dq "Not Equal", 10, 0
new_line: dq "", 10, 0
fmt_out: dq "%c", 0
cnt: dq 0
size: dq 0
size1: dq 0
section .bss
str1: resq 20
str2: resq 20
segment .text
global main
extern printf
extern scanf
main:
push RBP
mov RAX, 0
mov RSI, str1
mov RDI, fmt_in
call scanf
mov RAX, 0
mov RSI, str2
mov RDI, fmt_in
call scanf
mov RAX, 0
mov RCX, 0
SIZE_LOOP1:
cmp qword[str1 + RCX], 0
jz DONE
inc qword[size]
inc RCX
jmp SIZE_LOOP1
DONE:
mov RAX, 0
mov RCX, 0
SIZE_LOOP2:
cmp qword[str2 + RCX], 0
jz DONE_SIZE_CHECK
inc RAX
cmp RAX, [size]
jg NOT_EQUAL
inc RCX
mov [size1], RCX
jmp SIZE_LOOP2
DONE_SIZE_CHECK:
mov RAX, [size]
cmp RCX, [size]
jne NOT_EQUAL
mov RAX, 0
mov RBX, 0
mov RCX, 0
COMPARE:
cmp qword[str1 + RCX], 0
jz EQUAL
mov [cnt], RCX
mov RAX, 0
mov AL, [str1 + RCX]
mov RBX, 0
mov BL, [str2 + RCX]
cmp RAX, RBX
jne NOT_EQUAL
mov RCX, [cnt]
inc RCX
jmp COMPARE
EQUAL:
mov RDI, fmt_equal
call printf
mov RDI, new_line
call printf
jmp END
NOT_EQUAL:
mov RDI, fmt_not_equal
call printf
mov RDI, new_line
call printf
END:
mov RAX, 0
pop RBP
ret