I have made a simple program inside assembly which compares two numbers. For some reason, when the numbers are equal, the program works as expected. However, when the numbers are not equal, there is a segmentation fault.
Here is my code:
1 section .data
2 entermsg db 'Enter a Number: '
3 lenenter equ $-entermsg
4
5 equalmsg db 'The two numbers are equal'
6 lenequal equ $-equalmsg
7
8 nemsg db 'The two numbers ARE NOT equal '
9 lennemsg equ $-nemsg
10
11 section .text
12 global _start
13
14 _start:
15 mov ax, 1
16 mov bx, 4 ; When values inside ax and bx are equal, the program works
17
18 cmp ax,bx
19 je equal
20
21 cmp ax,bx
22 jne unequal
23
24 mov eax, 1
25 int 0x80
26
27 equal:
28 mov eax, 4
29 mov ebx, 1
30 mov ecx, equalmsg
31 mov edx, lenequal
32 int 0x80
33
34 mov eax, 1
35 int 0x80
36
37 unequal:
38 mov eax, 4
39 mov ebx, 1
40 mov ecx, nemsg
41 mov edx, lennemsg
42 int 0x08
43
44 mov eax, 1
45 int 0x80
I am using NASM and linker on Ubuntu 16.04LTS
Any help is appreciated! Thanks