ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I tried to make a program that converts an integer to a string (for nasm) but I get an error(Floating point exception) because of the "div edx". Do you have any idea how to solve that?
Code:
section .data
numar: resw 1
string: resb 6
msg1: db "15 => "
len_msg1 equ $ - msg1
len_string: resb 4
section .text
global _start
int2str: ; eax = number to convert, di = the result(string)
pusha
mov ebx,1
mov cx,0
iar:
mov edx,10
div edx ;there is a problem
mov [di],edx
mov bx,48
add [di],bx
mov bx,0
inc di
inc cx
cmp eax,ebx
jne iar
mov bx,0xa
mov [di],bx
popa
mov eax,ecx
ret
exit:
mov eax,1
int 0x80
_start:
mov edx,len_msg1
mov ecx,msg1
mov ebx,1
mov eax,4
int 0x80
lea di,[string]
mov eax,15
call int2str
mov edx,eax
mov ecx,string
mov ebx,1
mov eax,4
int 0x80
call exit
* 32 bit operand: (which edx is): EDX:EAX is divided by the given operand. So, if you set EDX to 10, then, obviously EDX:EAX goes out of bounds. Try something like this:
mov ebx, 10
div bx
Also, DI is not initialized. It's not recommended to use [di] before that. I think you want this:
mov di, bx
You're also trying to use edx later (after div, as "mov [di], edx"). What are you trying to achieve? You do know that edx would have been unchanged even if "div edx" had worked, don't you?
Well... If all your code is asm, I don't know how you could implement itoa. If not however, its easy.
I am sorry, I am not too much help here, because I know nothing (or very little) of asm.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.