-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Approach/leap #206
Approach/leap #206
Conversation
Thanks you for these. The different approaches have a lot in common, in that they use similar instructions. The main difference is in how often they perform 1, 2 or 3 divisions. Wider variation in approach is possible. We can merge as-is, and leave approaches using Using macroExamples Using remRecent MIPS processors have the Example Only perform one division, by 100Use bitwise operations to check if we have a multiple of 4 Example |
Interesting! I didn't know any MIPS assembly until two days ago and it shows 😉 I have a few questions:
Looking back, I think you're right about the fact that the approaches are actually pretty similar. In the approaches for other tracks, they usually mention approaches that differ in the use of functions or language constructs; in that sense, my approaches are not as interesting, whereas writing some using a macro, the I like your submissions too. The trick with using All things considered, I think it might be a good idea to rework my submission:
I would maybe skip the approach that uses What do you think? If you agree, I can update the PR. |
Your suggestions all sound excellent. Regarding converting
Here are some references that mention When performing addition/subtraction or bitwise operations with immediate values, the relevant instruction ends with an i:
The assembler can understand what we are doing, and turn an So the references above didn't even mention the With regards to rem or remi, I wasn't sure, so I tested:
is accepted by the assembler.
is rejected.
Is |
Thanks for the detailed explanation. I'll update the PR later today. With luck this can be merged before the beginning of #48in24. (And sorry for not discussing this with you beforehand - it was kind of a "spur of the moment" thing, since Tuesday January 16th was coming soon. I'll try to think of it more in advance next time.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of thanks.
|
||
For more information, check the [approach using `rem`][approach-using-rem]. | ||
|
||
## Approach: Using the `andi` instruction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This heading should be something like
"Using a \"divisible by\" `macro`"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦 Looks like I was tired. 😅
|
||
```c | ||
int is_leap_year(int year) { | ||
return year % 4 == 0 && year % 100 != 0 || year % 400 == 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it, however in this case it is actually equivalent; but I think you are correct that it is easier to understand with proper grouping.
|
||
```c | ||
int is_leap_year(int year) { | ||
return year % 4 == 0 && year % 100 != 0 || year % 400 == 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
@keiravillekode I've fixed the issues you pointed out. Thanks for the review! |
Also of note: I noticed that I had left an empty "Which approach to use?" header, so I removed it. I don't really know if there's a "better" approach here; I don't have enough MIPS assembly experience unfortunately. But if you want I can add it back if there is something interesting to discuss. |
I don't think we need it SizeWe don't have measurements for the binary code size. SpeedWe haven't counted clock cycles for the different instructions, or taken measurements. I assume MaintainabilityMacros can have big advantages here. |
Looking at the approaches, the But great work! |
We could replace either the
Perhaps this could be the I don't think any solution in the video was branchless. |
Nope. That would be a perfect approach! |
@ErikSchierboom I uploaded a PR |
Four approaches to the Leap exercise in MIPS assembly.
A couple of notes:
asm
(which is probably the syntax coloring for x86_64 assembly). Close enough 😉