1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Asssmebly MASM

  1. Oct 18, 2011 #1
    1. The problem statement, all variables and given/known data
    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 )

    2. Relevant equations



    3. 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
     
  2. jcsd
  3. Oct 18, 2011 #2

    Mark44

    Staff: Mentor

    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?
    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook