How Do Divisions and Modulus Work in Assembly for Calculating Days?

  • Thread starter Thread starter dohsan
  • Start date Start date
  • Tags Tags
    Assembly
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 2K views
dohsan
Messages
7
Reaction score
0

Homework Statement


I'm writing a program to calculate the number of days. I'm really confused on how divisions or modulus works in assembly... but I tried =/

Given that the day, month, and year value of a particular date are d, m, y. The day number of that date is calculated:

m = (m + 9) % 12
y = y - m/10
day_num = 365*y + y/4 - y/100 + y/400 + (m*306 + 5)/10 + ( d - 1 )

Homework Equations


The Attempt at a Solution


;month 1
mov eax, m1
add eax, 9
mov edx,0
mov ecx,12
div ecx
mov eax, 0
mov m1,edx

;month 2
mov eax, m2
add eax, 9
mov edx,0
mov ecx,12
div ecx
mov eax, 0
mov m2,edx
 
Physics news on Phys.org
In x86 assembly, there isn't a modulus operator, but there might be a macro command for it in MASM. I did most of my x86 assembly some years back, using the Borland assembler, TASM.

Where did you get these formulas?
dohsan said:
m = (m + 9) % 12
y = y - m/10
day_num = 365*y + y/4 - y/100 + y/400 + (m*306 + 5)/10 + ( d - 1 )

Let's consider a day this year, Apr 1, 2011.
There were 31 days in January, 28 days in Feb (not a leap year), and 31 days in Mar, so the day number of Apr 1 should be 31 + 28 + 31 + 1 = 91.

From your formulas, m = (4 + 9) % 12 = 13 % 12 = 1 ?
y = 2011 - 1/10 = 2011
I'm not even going to attempt to calculate the day from your formula.