Divide Overflow Error Assembly
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about divide by zero or overflow error hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask
Your Program Caused A Divide Overflow Error
Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join divide overflow is generated when them; it only takes a minute: Sign up Divide overflow error assembly emu8086 up vote 0 down vote favorite I have a homework on this, the purpose of the homework is to calculate in assembly (emu8086) this f(x)=x^2+2x-3. The
Division Overflow Error
problem is when I divide the result in order to print it I get a divide overflow error and I don't know why or how to fix it. Can anyone help? TITLE MYPROGRAM DEDOMENA SEGMENT protropimsg db "Dwsse arithmo x:",10,13,"$" apotelesmamsg db 10,13,"to apotelesma einai",10,13,"$" x_number db 0 tmp1 db 0 f_result dw 0 dekada db 0 monada db 0 DEDOMENA ENDS KODIKAS SEGMENT ARXH:MOV AX,DEDOMENA MOV DS,AX LEA DX,protropimsg MOV AH,09 INT 21h MOV AH,01h INT 21h spinrite division overflow error SUB AH,30h MOV x_number,AH MOV AH,x_number MOV BH,x_number ADD AH,BH MOV CH,3 SUB AH,CH MOV tmp1,AH MOV AL,x_number MOV DL,x_number MUL DL MOV BL,tmp1 MOV BH,0 ADD AX,BX MOV f_result,AX MOV AX,f_result MOV BL,10 DIV BL MOV dekada,AL MOV monada,AH LEA DX,apotelesmamsg MOV AH,09 INT 21h MOV DL,dekada ADD DL,30h MOV AH,02h INT 21h MOV DL,monada ADD DL,30h MOV AH,02h INT 21h MOV AH,4CH INT 21H KODIKAS ENDS END ARXH assembly x86 overflow divide share|improve this question edited Oct 23 '13 at 21:03 nrz 7,71721453 asked Oct 23 '13 at 14:43 Constantinos Ch 105 What value are you using for x when testing? The division overflow is something you'd get if AX/BL is >255, i.e. if f_result >= 2560. –Michael Oct 23 '13 at 14:50 the value of x is given by the user –Constantinos Ch Oct 23 '13 at 16:12 Sure, but what did you enter when you tested your program and got the division overflow? –Michael Oct 23 '13 at 16:14 even with the x=1 the error is still there –Constantinos Ch Oct 23 '13 at 16:19 add a comment| 1 Answer 1 active oldest votes up vote 0 down vote accepted This looks incorrect: MOV AH,01h INT 21h SUB AH,30h MOV x_number,AH Interrupt 21h/AH=01h returns the character in AL, not in AH. share|improve this answer answered Oct 23 '13 at 16:23 Michael 33
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us
Divide Overflow In Computer Architecture
Learn more about Stack Overflow the company Business Learn more about hiring developers
Assembly Language Program To Divide Two Numbers
or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack how to divide in assembly language Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up 8086 assembly - divide overflow up vote http://stackoverflow.com/questions/19544894/divide-overflow-error-assembly-emu8086 0 down vote favorite 1 I try to make a simple division in assembly but I get "Divide overflow" error. My simple code: cs:sum and cs:num is a byte variable. (db) mov ax, word ptr cs:sum mov cl, 10 xor dx,dx div cl ; divide by 10 mov cs:num, ah ; ger rightest Not sure why - but as I say - I fail to devide properly. http://stackoverflow.com/questions/12149560/8086-assembly-divide-overflow So do you know what is that problem and how to solve it? thanks ! (I'm using cs deference because that's a TSR program) assembly x86 8086 share|improve this question asked Aug 27 '12 at 21:02 iLoveC 37411 4 A TSR ? Are you working on something for a museum exhibit ? –Paul R Aug 27 '12 at 21:06 1 I'm not using assembly at all. I'm preparing to exam..=\ –iLoveC Aug 27 '12 at 21:17 add a comment| 1 Answer 1 active oldest votes up vote 4 down vote accepted For this to cause a division exception mov ax, word ptr cs:sum mov cl, 10 div cl the value in ax (coming from word ptr cs:sum) must be >= 2560. Either word ptr cs:sum isn't < 2560 or addressing is broken in your code and you're not storing the value in word ptr cs:sum or fetching it from there (e.g. you're not using the same segment value when referring to sum). Those are the only possibilities. share|improve this answer answered Aug 28 '12 at 10:59 Alexey Frunze 45k83787 I already solve it. because your answer is the best - I'll sing this answe
- The Netwide Assembler > NASM Forum > Example Code > program errors : divide overflow « previous next » Pages: [1] Print Author Topic: program errors : divide overflow (Read 4936 times) nobody Guest program errors : divide overflow « on: June 17, 2005, 12:51:29 PM » HI https://forum.nasm.us/index.php?topic=662.0 alli'm new to this site, but i'm hoping someone can help. I have a program to write http://www.asmcommunity.net/forums/topic/?id=24616 to input 6 numbers as ascii characters add them, divide by six and output the result. I have functions that convert to numeric and from numeric back to string, but when i ask for a keyboard input, i get a divide overflow.I know it must be in the num_to_str where i have idiv bx, but i cannot figure out why. WHen i don't ask for an input and start with '5' overflow error as input, i get the answer 9 on the screen no matter what. below is the code. thank you for any help you can provide. my email address is niri@ananzi.co.zaThanks and kind regards,NIRI-----------------------------------------------------------------bits 16org 0x100jmp maininit_mess: db 'Please enter the numbers you selected : ',0ah,0dh,'$'input_buf: db 2outputbuf: db ' ','$'blank: db ' ','$'next_mess: db 'Number ','$'store: db 'Stored value right now is',0ah,0dh,'$'input: db '2','$'line_ret: divide overflow error db 0ah,0dh,'$'display_number: mov dx,next_mess mov ah,09 int 21h retdisplay_lineret: mov dx,line_ret mov ah,09 ; Service - display of stringint 21hretdisplay_colon: mov ah,02 mov dl,3ah int 21h retdisplay_n1: mov ah,02 mov dl,31h int 21h retdisplay_n2: mov ah,02 mov dl,32h int 21h retdisplay_n3: mov ah,02 mov dl,33h int 21h retdisplay_dx: mov ah,09 ; Service - display of stringint 21hretread_string: mov ah,0ah mov dx,input_buf int 21h ret;{----------------------------- CONVERT STRING TO NUMBER ----------------------------; INPUT = DX; OUTPUT = AXstr_to_num: xor ax,ax ; Initial value of AX = 0 xor bh,bh ; Initial value of BH =
when you try to preform division by zero. This is an illegal operation and causes an exception. Posted on 2006-04-17 09:36:25 by Synfire Re: divide overflow From "Art of Assembly"Division by zero and Division Overflow (they're NOT the same thing):You cannot, on the 80x86, simply divide one eight bit value by another. If the denominator is an eight bit value, the numerator must be a sixteen bit value. If you need to divide one unsigned eight bit value by another, you must zero extend the numerator to sixteen bits. You can accomplish this by loading the numerator into the al register and then moving zero into the ah register. Then you can divide ax by the denominator operand to produce the correct result. Failing to zero extend al before executing div may cause the 80x86 to produce incorrect results! When you need to divide two 16 bit unsigned values, you must zero extend the ax register (which contains the numerator) into the dx register. Just load the immediate value zero into the dx register12. If you need to divide one 32 bit value by another, you must zero extend the eax register into edx (by loading a zero into edx) before the division. When dealing with signed integer values, you will need to sign extend al to ax, ax to dx or eax into edx before executing idiv. To do so, use the cbw, cwd, cdq, or movsx instructions. If the H.O. byte or word does not already contain significant bits, then you must sign extend the value in the accumulator (al/ax/eax) before doing the idiv operation. Failure to do so may produce incorrect results. There is one other catch to the 80x86’s divide instructions: you can get a fatal error when using this instruction. First, of course, you can attempt to divide a value by zero. Furthermore, the quotient may be too large to fit into the eax, ax, or al register. For example, the 16/8 division “8000h / 2??? produces the quotient 4000h with a remainder of zero. 4000h will not fit into eight bits. If this happens, or you attempt to divide by zero, the 80x86 will generate an int 0 trap. This usually means BIOS will print “division by zero??? or “divide error??? and abort your program. If this happens to you, chances are you didn’t sign or zero extend your numerator before executing the division operation. Since this error will cause your program to crash, you should be very careful about the values you select when using division. Posted on 2006-04-17 23:48:27 by ti_mo_n Re: divide overflow The "Divide Overflow" or "Divide by Zero" is an exception that occurs