I have a below code when executed i see Floating point exception
.section .data
var1:
.int 20
.section .text
.globl _start
_start:
movl $var1, %edx
movl (%edx), %eax
movl $5, %ecx
div %ecx
movl %eax, %ebx
movl $1, %eax
int $0x80
when i execute the above code i get Floating point exception
../../bin/a49
Floating point exception (core dumped)
But in the above code if i change the register storing the address of var1 from edx to ecx, It works as expected
.section .data
var1:
.int 20
.section .text
.globl _start
_start:
movl $var1, %ecx
movl (%ecx), %eax
movl $5, %ecx
div %ecx
movl %eax, %ebx
movl $1, %eax
int $0x80
When i execute the above code i don't see the FPE.
$ ../../bin/a49
$ echo $?
4
I am unable to understand the above behaviour.