I'm a bit of a newcomer to ASM and I've run into a problem writing a function to convert a sector number to  Sector, Head and Cylinder data placed in the registers so that I can load that segment by calling BIOS interrupt 0x13 function 2 directly after running the function. however my code halted at a strange point when it was running, so I added some well-placed output instructions in my code to debug the issue and i find that it halts right on this DIV instruction in my clustertocsh function. Any ideas as to why it might be happening and possible methods to fix it?

code - compiled with NASM in 16-bit 8086 mode

clustertocsh:
  add ax, 34                          ;this offset is due to the fact that I'm actually 
                                          ;taking in FAT12 cluster numbers and the
                                          ;clusters are 1 sector each starting at segment
                                          ;34
 
  mov edx, gbd                      ;gbd is the address of my debug message
  call printstr                          ;I'll give you a penny if you can figure out
                                          ;what this does
 
  div word                       ;here's that damn div. spt is a word containing
                                          ;the number 18
 
  mov edx, gpd                      ;other debug message
  call printstr                          ;this never prints
 
  mov , ax              ;and therefore the rest of this never runs
  inc dx
  mov , dl
  mov ax,
  div word
  mov , al
  mov , dl
  mov dh,
  mov cl,
  mov ch,
  ret
 
  gbd db 10,13,' got to just before first divide',0
  gpd db 10,13,' passed first divide',0


I really have no idea what's going on, the code is complete, just to assure you. All of the memory references are supported properly with data. I'm sorry to bother you guys with this, but I've been working on this application since about 9:00 last night and it's now 5:37 in the morning and I can't think anymore. I need to sleep. Thank you much, and sorry again.
Posted on 2006-08-10 04:38:06 by LordSTITH
You must clear the edx register otherwise it will create an integer overflow exception. And be sure to check you are not trying to divide by zero :).
Posted on 2006-08-10 05:00:13 by mr.schyte
That's basically it in a nutshell.
DIV doesn't perform eax=eax/operand, it performs eax:edx=eax:edx/operand... always clear edx before you divide, or its value will be treated as a fractional component of the source operand.
Posted on 2006-08-10 05:24:36 by Homer
Thanks alot, it worked perfectly. I owe you guys.
Posted on 2006-08-10 05:40:01 by LordSTITH