1

am finding problem in dividing this number (23160148h) by(0026h) this is my code

.model small
.stack 100h
.data

x dd 23160148h
sum dw ?

.code
mov ax,@data
mov ds,ax

mov ax,x
mov dx,x+2
mov bx,0026h
div bx


mov sum,ax
mov sum+2,dx

end 

when I run this program I get an error that says division error (overflow )

any one have an idea about what's wrong with it ? note : am working on assembly 8086

tania miah
  • 15
  • 1
  • 5
  • The quotient, `0x23160148 / 0x26 = 0xec5e59`, doesn't fit in AX, so `div` raises a #DE error. http://www.felixcloutier.com/x86/DIV.html. You need extended-precision division to avoid overflow. – Peter Cordes Dec 21 '18 at 23:21
  • and how do I do this? – tania miah Dec 21 '18 at 23:23
  • Found a duplicate which shows how to use two `div` instructions to get a 32-bit quotient and 16-bit remainder from 32b / 16b division. – Peter Cordes Dec 21 '18 at 23:32
  • 1
    For constants, multiply instead of dividing. For example (for 32-bit unsigned integers), `x/26 == x * 1/26 == (x * (1<<32)/26) >> 32 == (x * 0x9D89D8A) >> 32`. – Brendan Dec 22 '18 at 01:00

0 Answers0