Divide Overflow Assembly Error
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 hiring developers or posting ads with divide by zero or overflow error us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow
Divide Error Overflow Emu8086
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 your program caused a divide overflow error Divide overflow in Assembly language up vote 0 down vote favorite I have a simple assembly program, where I want to divide two numbers (two byte sized) and print remainder. Here's my code .model small .stack 256 .data ten dw 10 .code divide overflow is generated when main proc mov ax, @data mov ds, ax mov ax, 12 ; divident div ten ; ax/10 mov ah, 9 ; for printing dx int 21h mov ax, 4c00h ; ending program int 21h main endp end main So when I run this code the result is "Divide overflow" and I have no idea why does overflow happens. Any ideas? assembly x86 division share|improve this question edited Apr 6 '13 at 11:52 nrz 7,71721453 asked Apr 6 '13 at 11:34 nabroyan 1,2121526 1
Division Overflow Error
Have you tried searching for assembly division problems/questions? Your question is not the first one. It's a duplicate of others. –Alexey Frunze Apr 6 '13 at 11:50 add a comment| 3 Answers 3 active oldest votes up vote 1 down vote accepted DIV mem16 divides DX:AX by the given operand. So you need to sign-extend AX into DX, which you easily can do with the CWD instruction prior to the division (in your case MOV DX,0 or XOR DX,DX would also work). I.e.: mov ax,12 cwd div ten Another problem with your code is that you seem to assume that int 21h / ah=9 can be used to print numeric values. That is not the case. If you want to print the value of DX (i.e. the remainder) you'll have to convert it into a string first and print that string. Otherwise you'll just get garbage output, and your program might even crash. share|improve this answer edited Apr 6 '13 at 11:46 answered Apr 6 '13 at 11:40 Michael 33.7k82863 The interesting thing is that when I debug my code everything is correct, but when it tries to print value, it prints garbage in debug mode and "Divide overflow" in normal mode –nabroyan Apr 6 '13 at 12:01 Debugger clears DX for you. –Harold Apr 6 '13 at 12:06 In some environments you might end up with DX being 0 when your program starts. In those instances the division would work correctly, but you
Join INTELLIGENT WORK FORUMSFOR COMPUTER PROFESSIONALS Log In Come Join Us! Are you aComputer / IT professional?Join Tek-Tips Forums! Talk With Other Members Be Notified Of ResponsesTo Your Posts Keyword divide overflow in computer architecture Search One-Click Access To YourFavorite Forums Automated SignaturesOn Your Posts Best Of All, assembly language program to divide two numbers It's Free! Join Us! *Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive
How To Divide In Assembly Language
e-mail. Posting Guidelines Promoting, selling, recruiting, coursework and thesis posting is forbidden.Tek-Tips Posting Policies Jobs Jobs from Indeed What: Where: jobs by Link To This Forum! Add Stickiness To Your Site By http://stackoverflow.com/questions/15850409/divide-overflow-in-assembly-language Linking To This Professionally Managed Technical Forum.Just copy and paste the BBCode HTML Markdown MediaWiki reStructuredText code below into your site. Assembly Forum at Tek-Tips HomeForumsProgrammersLanguagesAssembly Forum predicting a divide overflow. 2 thread272-1123341 Forum Search FAQs Links MVPs predicting a divide overflow. predicting a divide overflow. denc4 (Programmer) (OP) 15 Sep 05 18:09 let's say you got this code:; 20002h \ 2.mov ax,2mov dx,axmov http://www.tek-tips.com/viewthread.cfm?qid=1123341 bx,axdiv bxresult would be 10001h, which ofcourse does not fit in ax:a divide overflow error is generated.Is it possible to predict a divide overflow before itoccurs? RE: predicting a divide overflow. 2 TessaBonting (TechnicalUser) 22 Sep 05 03:48 Yes, do a compare on dx with bx and if ae then its anoverflow.movax,2movdx,axmovbx,2cmpdx,bxjaeerrordivbxok:error:succes, Tessa RE: predicting a divide overflow. denc4 (Programmer) (OP) 22 Sep 05 12:16 That makes sense.I'm not a math person myself, so I am strugling with thelogic behind it. But I have executed some experimental codebased on your example and it seems to work fine.thank you. RE: predicting a divide overflow. TessaBonting (TechnicalUser) 23 Sep 05 11:34 Look it like this:100.000/10 gives 10.000 if you now look at the three zeros afther the dot then that is the ax registerand the 100 is the dx register.by dividing you see that afther the division ax can't hold the whole 10.000.so when you divide the 100.000 by 200 it gives .500 and that can be holded in ax.try it with dividing by 100 and the result will be 1.000with is just 1 to much to hold since the maximum in thisexxamp
Thread Tools Display Modes Dec 8th, 2004, 10:45 PM #1 saxman Newbie Join Date: Dec 2004 Posts: 7 Rep http://www.programmingforums.org/post12771.html Power: 0 I'm not new to x86 ASM, but I am new to the square-root-related instructions that Intel has provided. I don't know what I'm doing wrong in my program, http://www.programmersheaven.com/discussion/94598/divide-overflow-error but I get a divide overflow. Perhaps someone could take a look at my code and see what is causing this. This program isn't finished yet, but it's going to divide overflow draw a sphere. I am doing it purely out of experimental interest. Right now I am just trying to get it to draw pixels to the screen, but I won't know if my algorithms and such are right or not if I can't see anything but an error. I wonder if it's the way I've used the square-root. This divide overflow assembly is the first time I've made use of it in ASM, so I don't even know if I did it right or not. Anyway, any help would be appreciated. BTW: If you find the below code to be hard to read due to the lack of 'tabs' on these forums, you can download the source file -- http://shadowsoft-games.com/saxman/3D.ASM (Toggle Plain Text) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; This program is designed to draw a sphere using the following: ; ; Ymax = (Ry/Rx) SQRT(Rx^2 - X^2) ; Zmax = (Rz/Ry) SQRT(Ry^2 - Y^2) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; jmp start xpos* dw ?*; X position (0-319) ypos* db ?*; Y position (0-199) zpos* db ?*; Z position (0-255) xrad* db 64*; X radius (0-255) yrad* db 64*; Y radius (0-255) zrad* db 64*; Z radius (0-255) store1 dd ?*; Used to store a floating-point ymax* db ?*; Ymax = (Ry/Rx) SQRT(Rx^2 - X^2) zmax* db ?*; Zmax = (Rz/Ry) SQRT(Ry^2 - Y^2) palette db 00, 00, 00, 01, 01, 01, 02, 02, 02, 03, 03, 03 * db 04, 04, 04, 05, 05, 05, 0
Unanswered Best Of... Categories 141.8K All Categories104.8K Programming Languages 6.4K Assembler Developer 1.9K Basic 39.9K C and C++ 4.3K C# 7.9K Delphi and Kylix 4 Haskell 9.6K Java 4.1K Pascal 1.3K Perl 2K PHP 524 Python 37 Ruby 4.4K VB.NET 1.6K VBA 20.8K Visual Basic 2.6K Game programming 312 Console programming 89 DirectX Game dev 1 Minecraft 110 Newbie Game Programmers 2 Oculus Rift 9K Applications 1.8K Computer Graphics 732 Computer Hardware 3.5K Database & SQL 526 Electronics development 1.6K Matlab 628 Sound & Music 257 XML Development 3.3K Classifieds 198 Co-operative Projects 189 For sale 190 FreeLance Software City 1.9K Jobs Available 601 Jobs Wanted 201 Wanted 2.9K Microsoft .NET 1.7K ASP.NET 1.1K .NET General 3.3K Miscellaneous 5 Join the Team 0 User Profiles 354 Comments on this site 62 Computer Emulators 2.1K General programming 187 New programming languages 613 Off topic board 177 Mobile & Wireless 51 Android 124 Palm Pilot 335 Multimedia 151 Demo programming 184 MP3 programming 6.9K Operating Systems & Platforms 0 Bash scripts 22 Cloud Computing 365 Embedded / RTOS 53 FreeBSD 1.7K LINUX programming 368 MS-DOS 0 Shell scripting 320 Windows CE & Pocket PC 4.1K Windows programming 906 Software Development 408 Algorithms 68 Object Orientation 89 Project Management 90 Quality & Testing 250 Security 7.6K WEB-Development 1.8K Active Server Pages 61 AJAX 2 Bootstrap Themes 55 CGI Development 19 ColdFusion 224 Flash development 1.4K HTML & WEB-Design 1.4K Internet Development 2.2K JavaScript 35 JQuery 290 WEB Servers 153 WEB-Services / SOAP divide overflow error! toaster Member Posts: 4 January 2002 in x86 Assembly this piece of code is supposed to find the slope of a line, wich will be later used to texture a polygon, my problem is that it always causes a divide overflow error, ive checked plenty of times, and just before the devision eax is 18688, and ebx is 86i dont get it!!!heres the piece thats been troubling me(written for tasm 4.1) mov ebx, 4 mov ax, [y + ebx] mov ebx, 0 mov dx, [y + ebx] sub eax, edx mov ebx, 4 mov dx, [x + ebx] mov ebx, 0 mov cx, [x + ebx] sub edx, ecx mov ebx, edx shl eax, 7 div ebx push eax 0 · Share on Facebook Comments protektor Member Posts: 116 January 2002 : this pi