0

I have a problem with division in assembly TASM. It looks good but program give me an information about divide overflow. How to solve the problem?

  Data Segment  

 val db ?    

Data ends
Code Segment

assume CS:Code,DS:Data
Start:    

 MOV AX,DATA
 MOV DS,AX


 mov al,4
 mov bl,2
 div bl


 MOV AH,4CH
 INT 21H

 Code ends
END Start
MaronFive
  • 39
  • 4
  • 2
    You need to clear `ah` prior to the division. And you should of course download _Intel® 64 and IA-32 Architectures Software Developer’s Manual_ so that you can look up the behavior of every instruction. – Michael May 15 '18 at 20:45
  • 1
    depending on where the DOS loads your code exactly, you are dividing value from range 10000..40000 by 2, so the result will not fit into 8 bits and the division exception is emitted by CPU. I.e. your code works exactly as the CPU was designed and as it should. It's not clear why you would expect something else. BTW for positive binary values you can divide them by 2 with `shr ax,1` instead of `div`. – Ped7g May 15 '18 at 21:00

0 Answers0