944,212 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 1072
  • Assembly RSS
Oct 18th, 2009
0

divide overflow problem

Expand Post »
Assembly Syntax (Toggle Plain Text)
  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..
Assembly Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
urbancalli is offline Offline
14 posts
since Jul 2008
Oct 18th, 2009
0
Re: divide overflow problem
Try this:
Assembly Syntax (Toggle Plain Text)
  1. MOV AL, DAY
  2. CBW
  3. DIV DIVISOR
Reputation Points: 99
Solved Threads: 5
Junior Poster
Evenbit is offline Offline
140 posts
since Mar 2005
Oct 19th, 2009
0
Re: divide overflow problem
This may make your issue more obvious...
Assembly Syntax (Toggle Plain Text)
  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
Assembly Syntax (Toggle Plain Text)
  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.
Reputation Points: 546
Solved Threads: 99
Practically a Posting Shark
wildgoose is offline Offline
891 posts
since Jun 2009
Nov 2nd, 2009
0
Re: divide overflow problem
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;
Assembly Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
urbancalli is offline Offline
14 posts
since Jul 2008
Nov 5th, 2009
0
Re: divide overflow problem
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.
Reputation Points: 36
Solved Threads: 19
Junior Poster
NotNull is offline Offline
198 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: Detect Multicore processors
Next Thread in Assembly Forum Timeline: Use string to call variable





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC