Need Help With Floating Point Exception

Hi, I'm Trevor, Im currently a c/c++ programmer and im trying to teach myself assembly language programming. Not so much for any reason I just think it will be alot of fun. Which so far it has been.

I am trying to write a simple program that takes two cmd args and adds them together and prints it to the console. When i run this i get a floating point exception.

Unfortnatly for all of us not only am i new to assembler i am new to linux so i dont have decent debugger. I have tried several and havent gotten one yet that will allow me to step threw the code.

W/o further ado here is my nasm source code:


section .data
msg1 db "The answer is ", 0
msg1_len equ $ -msg1
errmsg db "This software takes two command line args(integers 0-9)",0xA, 0
errlen equ $ - errmsg

section .bss
decNumHun resw 1
decNumTens resw 1
decNumOnes resw 1

section .text
global _start

_start:
pop ebx
cmp ebx, 3
jnz printerrmsg
pop ebx
pop ebx
pop eax
sub ebx, 48
sub eax, 48 ;get decimal values from ascii values

add eax, ebx
call parseint

mov eax, 4
mov ebx, 1
mov ecx, msg1
mov edx, msg1_len
int 80h
;++++++++Print Solution++++++++++++++++++

mov ecx, [decNumHun]
cmp ecx, 48 ;48 = ascii char code for 0
jz printtens
call printf
printtens:
mov ecx, [decNumTens]
cmp ecx, 48
jz printones
call printf
printones:
mov ecx, [decNumOnes]
cmp ecx, 48
call printf


mov eax, 1
mov ebx, 0
int 80h

printerrmsg:
mov eax, 4
mov ebx, 1
mov ecx, errmsg
mov edx, errlen
int 80h

mov eax, 1
mov ebx, 0
int 80h

parseint:
mov ecx, eax ;preserve initial value
mov ebx, 100
div ebx
cmp eax, 0
jz GetTens
add eax, 48 ;put ascii char for digit in variable
mov [decNumHun], eax
mov eax, edx


GetTens:
mov ebx, 10
div ebx
cmp eax, 0
jz GetOnes
add eax, 48
mov [decNumTens], eax
mov eax, edx

GetOnes:
mov ebx, 1
div ebx
add eax, 48
mov [decNumTens], eax
mov eax, ecx
ret
;endp parseint

printf:
mov eax, 4
mov ebx, 1
mov edx, 1
int 80h
ret
;endp printf


Im guessing that my issues are steming from the parseint proc. Your thoughts?

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories