divide overflow problem

Reply

Join Date: Jul 2008
Posts: 10
Reputation: urbancalli is an unknown quantity at this point 
Solved Threads: 0
urbancalli urbancalli is offline Offline
Newbie Poster

divide overflow problem

 
0
  #1
Oct 18th, 2009
  1. MOV AH,DAY
  2. DIV DIVISOR
  3. CMP Al,'0'
  4. JE WEEK_
  5. JMP NOT_WEEK_

that is my code that tries to find out if the "DAY" is divisible by "7", which is the DIVISOR..

i initialized them as..
  1. DAY DB 1
  2. DIVISOR DB 7

when the "day" is divisible by 7, a 'divide oveflow' occurs..
how do i get this right? thanks
--there's a meaning in everything--
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 129
Reputation: Evenbit is on a distinguished road 
Solved Threads: 4
Evenbit's Avatar
Evenbit Evenbit is offline Offline
Junior Poster
 
0
  #2
Oct 18th, 2009
Try this:
  1. MOV AL, DAY
  2. CBW
  3. DIV DIVISOR
while (CPU is present) {some assembly required}
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark
 
0
  #3
Oct 19th, 2009
This may make your issue more obvious...
  1. Quotient : Remainder = Dividend / Divisor
  2. AL : AH = AX / (8-bit)
  3. AX : DX = DX:AX / (16-bit)
  4. EAX : EDX = EDX:EAX /(32-bit)
You needed to specfy a data type snce you're using a memory reference
  1. MOV AH,DAY
  2. CBW ; AX = Day
  3. DIV DIVISOR ; Byte ptr Divisor
  4. ;;;; WRONG CMP Al,'0'
; It's a decimal response not an ASCII '0'
; Note: AH is day of week (0...6)
; AL is week # (0..N)
Last edited by wildgoose; Oct 19th, 2009 at 12:08 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 10
Reputation: urbancalli is an unknown quantity at this point 
Solved Threads: 0
urbancalli urbancalli is offline Offline
Newbie Poster
 
0
  #4
21 Days Ago
I just would like to ask, what is the function of the 'CBW'?
Does it replace the
CMP al,'0' part?

I am really confused, since it does not seem to pass through the WEEK_:

Here's my code;
  1. ;increment the day (since it has to go first,
  2. ;to agree with my code I first made)
  3. INC DAY
  4.  
  5. MOV AH,DAY
  6.  
  7. ;I have to subtract 1 so that I will get the current day number
  8. SUB AH, 1
  9. CBW
  10. DIV DIVISOR
  11.  
  12. ;jumps to the WEEK_ function
  13. ;which summarizes the inventory for the week
  14. JE WEEK_
  15.  
  16. ;jumps to the NOT_WEEK_ function
  17. ;which makes it program loop until the sales reach zero
  18. JMP NOT_WEEK_

really, thanks a lot. Still hoping for your help. Thanks again.
--there's a meaning in everything--
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 131
Reputation: NotNull is an unknown quantity at this point 
Solved Threads: 13
NotNull's Avatar
NotNull NotNull is offline Offline
Junior Poster
 
0
  #5
17 Days Ago
CBW - Convert Byte to Word
Sign extends the byte in AL into the word in AX.
Sign extension is merely copying the sign bit into the rest
of a datatype when a signed value is moved into a larger
datatype.
When it is a byte being copied into a word, the value of bit 7
is copied into the 8 MSBs of the high byte of the word.
so 80 becomes FF80,
and 7F becomes 007F.
----------------------------------------------------------
To control a mind violates a man, and all it has been used for is
hurting and afflicting. Nowonder I progam in assembly...
--->Now available http://dotcoding.netai.net/
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the Assembly Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC