1

This is part of a homework assignment. I am not asking anyone to specifically do the homework for me because I would like to learn myself; however, can anyone elaborate as to how I would go about doing this? This is our second assignment, and personally, I think this is such an advanced task for a beginner. Anyways, any help would be GREATLY appreciated!

I know that the user should input the date in a "XX/XX/XXXX" format, but what about the calculation and displaying the day? Also, how should I handle the user input? Should I use three variables for input or just ask for the date at once?

  • Do you know how you'd implement this in C, or any other language? i.e. do you have an algorithm in mind already? – Peter Cordes Feb 25 '18 at 05:31
  • @PeterCordes I have the code for the program in C++, but the only useful part is the algorithm. We were told to use Zeller's rule for the algorithm. [Zeller's Rule](http://mathforum.org/dr.math/faq/faq.calendar.html) My problem is implementing this algorithm into MARIE and how would I ask the user for input... – Chase Burleson Feb 25 '18 at 06:07
  • I'd ask for the input as a single string, and "parse" it by looking at fixed byte positions within the string. So it doesn't handle leading spaces or anything, and doesn't check that the separators are `/`, and doesn't handle 1/2/1900, only 01/02/1900. – Peter Cordes Feb 25 '18 at 06:10
  • Other than that, you have an algorithm, but I don't know which part of implementing it is hard for you. I don't remember what it's like for it *not* to be obvious how to translate C++ or pseudocode into asm, so you need to describe in more detail which parts you're getting stuck on. You know exactly what you want to happen to the input data in every possible case, so write code that handles those cases and does that. – Peter Cordes Feb 25 '18 at 06:12
  • @PeterCordes Even if I used a string, asked a user for input all at once, and excluded separators, I would still need to find a way to implement the algorithm. From what I can see, there are multiple variables for the algorithm. Like I said, I'm very new to MARIE. I mean *verrrry* new. Is there a way to ask the user for input all at once, have the program break the string down into three variables, and then do the calculations? I think that would be far too excessive. I'm wondering... what is the most basic way to accomplish this assignment. To be honest, I've never heard of "parsing." – Chase Burleson Feb 25 '18 at 06:18
  • You've never heard of parsing? So I'm guessing you don't have much experience writing programs in other languages either? https://en.wikipedia.org/wiki/Parsing#Computer_languages – Peter Cordes Feb 25 '18 at 06:24
  • @PeterCordes After a google search, I assume breaking the string down into three variables is what you mean by parsing. In order to display the day of the week (which I cannot do in English), I would have to create a way for the program to display numbers for each day of the week. Example: Monday is a 1, Tuesday a 2, etc... all the way to 7. To do this I'll have to use the equivalent to an if statement, which, as far as I know, is "skipcond" in assembly. – Chase Burleson Feb 25 '18 at 06:25
  • Oh, do you have to print the day-of-week as a name like "Monday" instead of a number like "1"? If so, use a lookup table of pointers to strings that you index with the number. So you only need one block of code that prints, but the input to that block of code is a pointer to a string, rather than needing 7 separate blocks to print one of 7 day names. – Peter Cordes Feb 25 '18 at 06:28
  • @PeterCordes Freshman year C++, so not much experience at all. This is my second assembly program so everything is very new. The theory behind how programs work are discussed in classes I have yet to enroll in. Unfortunately, my teachers have only gone over syntax. – Chase Burleson Feb 25 '18 at 06:29
  • To get the day-of-month as a number from a string like DD/MM/YYYY, in C you'd do `(s[0] - '0') * 10 + s[1] - '0'`. In assembly, that's two byte loads and some multiply and add/subtract. If MARIE doesn't have multiply, then multiplying by 10 can be synthesized out of adds. (e.g. add to itself to multiply by 2, and 10 is 8+2. Or `(4+1) * 2` – Peter Cordes Feb 25 '18 at 06:32
  • @PeterCordes My instructor did not give specifics. I've discussed using a number system with classmates, and I think that should be fine. I just need to print a number that corresponds with the day of the week. I just wish MARIE could handle math as well as C++. Looping addition to multiply and looping subtraction to divide is going to throw me off with this algorithm. – Chase Burleson Feb 25 '18 at 06:32
  • I normally deal with asm for real CPUs (typically register machines like x86 or ARM), not stripped-down teaching languages like MARIE that only have an accumulator and no built-in multiply or divide. But multiplying by a constant is straightforward, like I said, especially a small / simple constant like `10`. – Peter Cordes Feb 25 '18 at 06:36
  • @PeterCordes Okay, so with looping I can work with the algorithm. How do I use if, elses in assembly. Skipcond has something to do with it, but how exactly does it work? This assignment isn't due until Mar 15th, but I figured it's best to get a head start. Thanks for your help Peter. – Chase Burleson Feb 25 '18 at 06:41
  • It sounds to me you may want to check few simpler examples of already working code in MARIE, and use the simulator+debugger to step over single instruction at time, meticulously checking how each instruction works, and how they are assembled together to achieve the target task. Also studying general principles about programming on regular basis will surely help, allocate like 1-2h every other day to read some book about algorithms/data structures/computer architecture, etc. It takes years of experience to get to some decent level and there's no fast forward way, but at start the gains are big. – Ped7g Feb 25 '18 at 12:20
  • And there's no need to loop for *10, writing all the additions in hard-coded way is acceptable for such small constant (((x+x)+(x+x))+x)+(((x+x)+(x+x))+x) (parentheses mark possible sub-results to accelerate the cumulation toward *10 result). – Ped7g Feb 25 '18 at 12:22

1 Answers1

0

i used the algorithm zeller , share my logic in javascript

 const weekdayNames = {
  1:'lunes',
  2:'Martes',
  3:'Miércoles',
  4:'Jueves',
  5:'Viernes',
  6:'Sábado',
  7:'Domingo',
}

function calculateDate (dd,mm,aaaa){
  const day = parseInt((14 - mm) / 12);
  const year = aaaa - day;
  const month = parseInt(mm + (12 * day) - 2);
  const dayResult = parseInt(dd + year + parseInt(year/4) - parseInt(year/100) + parseInt(year/400)+((31*month) / 12)) % 7;
return weekdayNames[dayResult];
}

console.log(calculateDate(6,3,1997));

hope help you