Discussion Locked

Division in Assembly

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

i have a packed bcd number in al register and another packed bcd number in bl register now i want to divide al by bl as follows
div bl
however on running the program i'm getting a divide error however on debugiing the program and stepping into theprogram with degug.com's -p option the progran\m is running fine.what could be the cause?

2 replies

by wayne m.

What is the specific error? For most machines the only division error likely to be returned (i.e. via a software interrupt) is a divide by zero error. What error handler is getting called.

I would verify you are correctly setting the register and it is not being overwritten. The debugger may be hiding that. Try copying your register values into some well defined memory area at various important steps. Then try running your program with a break point on the error handler (instead of single stepping through the program). At you breakpoint, you can look at your memory copies of your registers and see if and where the values might be getting changed.

Also, if you have interrupts running, make sure your interrupt handlers preserve your al and bl registers.

One other thing (this is probably a separate issue) is you use of packed BCD. Unless your assembly language supports BCD arithmetic, you will probably need to convert to binary before your division and then restore the result to BCD.

I hope this helps.

by wls

Maybe I missed something here, does the divide operation work on BCD numbers? It may be treating it as standard binary...

This discussion is closed to new replies.