Miden assembly style guidelines #698
Replies: 12 comments 8 replies
-
Note: There is another relevant discussion about endianess, that goes over the stack order of elements: #656 |
Beta Was this translation helpful? Give feedback.
-
The question of inline comments documenting the stack just came up in one of my PRs, so I'll just comment on that: I find the "stack after instruction" really confusing:
There are in essence two types of inline comments:
Stack inline comments fall in the latter category rather than the former, so I think they should be placed at the point at which the stack is what the comment says it is. |
Beta Was this translation helpful? Give feedback.
-
There is a brief explanation of this here. One thing that is missing from the explanation is that |
Beta Was this translation helpful? Give feedback.
-
Regarding the documentation format. I'd prefer a slight variation on the second alternative:
The optional explanation is for cases when the initial short description is not sufficient. |
Beta Was this translation helpful? Give feedback.
-
I just realized that if we add a rule on how to group assembly opcodes, for example, opcodes that are not split by a comment are aligned on the same line up to 90 characters. When can write an formatter for MASM (I really like formatter because they save me tons of time while coding :) ) |
Beta Was this translation helpful? Give feedback.
-
Inline comments:
|
Beta Was this translation helpful? Give feedback.
-
When writing loops I like to add a tag and the expected stack state, for example:
I do this because for the next iteration of the loop, the stack state expects the stack position to be the same, that makes it easier to track the values down. |
Beta Was this translation helpful? Give feedback.
-
As documentation, it was decided a while ago to not use high-level like syntax to describe the procedure signature #668 (comment) |
Beta Was this translation helpful? Give feedback.
-
on cycle counting when counting cycles of a long procedure, it is useful to have intermediary values to add later, so one strategy that I use is to add a miden-vm/stdlib/asm/crypto/hashes/native.masm Lines 34 to 36 in 2690d5c |
Beta Was this translation helpful? Give feedback.
-
One notation that can be useful when using instead of:
becomes:
I actually made a mistake when doing the first example, that was obvious when writing the counter-example below, this can be super useful to check things at a glance. The downside of this is that when we have words in the stack, for example:
I'm not sure how to have a good notation for the case above. |
Beta Was this translation helpful? Give feedback.
-
When writing code that reads from the advice stack, we have to remember to validate the data. It can be useful to have notation to mark unverified values, e.g.:
|
Beta Was this translation helpful? Give feedback.
-
Some procedures also have failure conditions, e.g. division by zero. This should be documented. To follow the existing format it makes sense to have something like:
|
Beta Was this translation helpful? Give feedback.
-
The goal of this discussion is to document a preferred style for structuring and commenting code, so that we avoid confusion when reading it.
Documentation
https://0xpolygonmiden.github.io/miden-vm/user_docs/assembly/code_organization.html#comments
Documentation format
Do's
Input:
Output:
Cycles
:example: account.masm
Dont's:
What calling convention should we adopt for procedures?
Called procedure should consume all of its arguments and only return new computed values at the end, the stack may be empty if the procedure just asserts or save to memory.
Inline documentation
examples
Do's
Dont's
Beta Was this translation helpful? Give feedback.
All reactions