Divide Overflow Error Assembler
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 divide by zero or overflow error Learn more about Stack Overflow the company Business Learn more about hiring developers
Your Program Caused A Divide Overflow Error
or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack divide overflow assembly 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 Divide overflow in Assembly language up vote
Divide Overflow In Computer Architecture
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 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 assembly language program to divide two numbers 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 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 gar
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
How To Divide In Assembly Language
Overflow the company Business Learn more about hiring developers or posting ads with us
Division Of Two Numbers In Assembly Language
Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a division in assembly language programming community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Divide OverFlow ASM up vote 1 down vote favorite I'm doing a calculator project for http://stackoverflow.com/questions/15850409/divide-overflow-in-assembly-language school and all the thing work good , but Divide and Mod(%) are giving me a "Divide Overflow" error , how can i fix it? For the full code : http://pastebin.com/a9cuL0LJ Divide is line 158 Mod is line 166 Both Num1Int and Num2Int are numbers between 0-255 Or: DivideDo: push ax mov ax , word ptr Num1Int div Num2Int mov ResultInt , al pop ax ret ModDo: push ax mov ax http://stackoverflow.com/questions/15172656/divide-overflow-asm , word ptr Num1Int div Num2Int mov ResultInt , ah pop ax ret assembly overflow calculator modulo divide share|improve this question edited Feb 15 '14 at 9:13 Sumurai8 10.3k62352 asked Mar 2 '13 at 9:01 Ron Serruya 82 add a comment| 1 Answer 1 active oldest votes up vote 0 down vote accepted One obvious problem is that, while Num1Int is 8 bits wide: Num1Int db ? you treat it as if it were 16 bits wide: mov ax , word ptr Num1Int share|improve this answer answered Mar 2 '13 at 9:04 NPE 253k36553741 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged assembly overflow calculator modulo divide or ask your own question. asked 3 years ago viewed 836 times active 2 years ago Related 30Divide and Get Remainder at the same time?2ASM x86 integer overflow0ASM| Program exit after Mod(%) is 0 in a calculator project2Using Jump and Compare in Assembly Language0Divide overfl
- The Netwide Assembler > NASM Forum > Example Code > program errors : divide overflow « previous next » Pages: [1] Print Author Topic: program errors : divide overflow (Read 4933 times) nobody Guest program errors : divide overflow « on: June 17, 2005, 12:51:29 PM » HI alli'm https://forum.nasm.us/index.php?topic=662.0 new to this site, but i'm hoping someone can help. I have a program to write 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' as input, i get divide overflow 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: db 0ah,0dh,'$'display_number: in assembly language 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 = 0 mov cx,10