I'm learning some basic arithmetic using NASM on Linux. I need to divide two numbers using variables NUMBER1 and NUMBER2. My code works if I type in actual value instead of variables. For example if I type in '6' instead of NUMBER2 and '2' instead of NUMBER1, the program does division and gives me answer of 3. Running code with variables gives FLOATING EXCEPTION (CORE DUMPED). could please explain how correctly use variables in this code? While debugging, I see that the problem is in DIV line. Thank you !
section .text
global main ;must be declared for using gcc
main: ;tell linker entry point
mov ax,[NUMBER2]
sub ax, '0'
mov bl, [NUMBER1]
div bl
add ax, '0'
mov [res], ax
mov ecx,msg
mov edx, len
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
nwln
mov ecx,res
mov edx, 1
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
NUMBER1: dw 2
NUMBER2: dw 6
msg db "The result is:", 0xA,0xD
len equ $- msg
segment .bss
res resb 1