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

  • Thread starter dohsan
  • Start date
  • Tags
    Assembly
In summary, the conversation discusses the use of divisions and modulus in assembly, specifically in calculating the day number of a particular date. The formulas provided use variables for the month, day, and year, and involve adding, subtracting, and dividing these variables to obtain the day number. The accuracy and reliability of these formulas is called into question based on the example provided.
  • #1
dohsan
7
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
  • #2
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.
 

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

1. How do I calculate the number of days using Assembly?

To calculate the number of days using Assembly, you will need to use the appropriate instructions and registers to perform the necessary calculations. This may involve converting the given date into a specific format and then using mathematical operations to determine the number of days.

2. What are the necessary steps for calculating days with Assembly?

The steps for calculating days with Assembly will vary depending on the specific program and requirements. However, generally, the steps involve converting the given date into a specific format, performing mathematical operations to determine the number of days, and then displaying the result.

3. Can I use Assembly to calculate leap years?

Yes, Assembly can be used to calculate leap years. You will need to follow the appropriate steps for converting the given date into a specific format and then use conditional statements to determine if the year is a leap year or not. Based on this, you can adjust the number of days accordingly in your calculation.

4. Is it possible to calculate days with Assembly for dates in the future?

Yes, it is possible to calculate days with Assembly for dates in the future. You will need to ensure that your program takes into account the varying number of days in each month and also accounts for leap years. Additionally, you may need to consider any future changes to the calendar system, such as the addition of leap seconds.

5. Are there any built-in functions or libraries for calculating days with Assembly?

No, there are no built-in functions or libraries specifically for calculating days with Assembly. You will need to write your own code or use existing code libraries to perform the necessary calculations. However, some Assembly compilers may have built-in functions for date and time calculations that could be useful in this task.

Similar threads

Back
Top