``````MOV AH,DAY
DIV DIVISOR
CMP Al,'0'
JE WEEK_
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..

``````DAY         DB 1
DIVISOR  DB 7``````

when the "day" is divisible by 7, a 'divide oveflow' occurs..
how do i get this right? thanks

## All 4 Replies

Try this:

``````MOV AL, DAY
CBW
DIV DIVISOR``````

This may make your issue more obvious...

``````Quotient : Remainder = Dividend / Divisor
AL : AH =  AX / (8-bit)
AX : DX = DX:AX / (16-bit)
EAX : EDX = EDX:EAX /(32-bit)``````

You needed to specfy a data type snce you're using a memory reference

``````MOV AH,DAY
CBW                       ;  AX = Day
DIV DIVISOR          ; Byte ptr Divisor
;;;; 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)

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;

``````;increment the day (since it has to go first,
;to agree with my code I first made)
INC DAY

MOV AH,DAY

;I have to subtract 1 so that I will get the current day number
SUB AH, 1
CBW
DIV DIVISOR

;jumps to the WEEK_ function
;which summarizes the inventory for the week
JE WEEK_

;jumps to the NOT_WEEK_ function
;which makes it program loop until the sales reach zero
JMP NOT_WEEK_``````

really, thanks a lot. Still hoping for your help. Thanks again.
:D

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.