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

  • Thread starter Thread starter dohsan
  • Start date Start date
  • Tags Tags
    Assembly
AI Thread Summary
The discussion centers on calculating the day number of a date using assembly language, specifically addressing the use of division and modulus operations. The formulas provided for calculating the day number involve adjusting the month and year values, but there is confusion regarding the implementation in x86 assembly, which lacks a direct modulus operator. Participants discuss how to perform these calculations using assembly instructions, particularly focusing on the division operation to derive the modulus. An example date, April 1, 2011, is used to illustrate the calculations, revealing discrepancies in the application of the formulas. The conversation highlights the challenges of translating mathematical operations into assembly language effectively.
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.
 
Back
Top