I have a question on assembly x86 architecture.
INCLUDE Irvine32.inc
.data
day BYTE 0
month BYTE 0
year BYTE 0
a BYTE 0
y BYTE 0
m BYTE 0
count BYTE 0
prompt1 BYTE "enter month: ",0
prompt2 BYTE "enter day: ",0
prompt3 BYTE "enter an year: ",0
prompt4 BYTE " the day of the week is ",0
.code
main PROC
mov edx, OFFSET prompt1
call writeString
mov eax, OFFSET month
mov ecx, 19
call readInt
call crlf
mov edx, OFFSET prompt2
call writeString
mov eax, OFFSET day
mov ecx, 19
call readInt
call crlf
mov edx, OFFSET prompt3
call writeString
mov eax, OFFSET year
mov ecx, 19
call readInt
call crlf
mov al, 14
sub al, month
mov bl, 12
div bl
mov a, al
mov al, 0
mov ah, year
sub ah, a
mov y, ah
mov ah, 0
mov bh, 12
mul a
add bh, a
mov ch, 2
sub bh, ch
mov m, bh
mov bh, 0
mov ch, 0
mov al, 31
mul m
mov ah, 12
div ah
mov bl, y
mov bh, day
add bh, y
mov cl, y
mov ch, 4
div ch
add bh, cl
mov dl, y
mov dh, 4
div dh
add bh, cl
add bh, al
mov al, 0
mov al, 7 // mod 7
div al
exit
main ENDP
END main
So I am supposed to do these arithmetic equations:
a = (14 - month) / 12
y = year - a
m = month + (12 * a) - 2
d = (day + y + y/4 - y/100 + y/400 + (31 * m / 12)) % 7
For the last equation of mod 7
, I got an error, "integer overflow", this is due to using bl
I think.
If I do something like this
mov ax, "thing in parenthesis"
mov cl, 7
div cl
then I would get al
is quotient, ah
is remainder.
But how would I do mod
without having to use ax
register?