-
Notifications
You must be signed in to change notification settings - Fork 351
asm-5: Rework of the 5th chapter #47
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
Conversation
Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
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.
Comments after re-reading
|
||
In the macro's body, we initialize the registers according to the [ABI](https://refspecs.linuxbase.org/elf/x86_64-abi-0.99.pdf) to make [system calls](https://en.wikipedia.org/wiki/System_call). The only difference you may notice is that instead of using direct values, we use input parameters. These parameters start with the `%` symbol, followed by the number of the parameter (`%1`, `%2`, etc). | ||
|
||
Another syntax ability in the multi-line NASM macros is the possibility to define labels inside a macro. In this case, the label name should be prefixed with `%%`. For example: |
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.
Should we mention why anyone would need to define labels? Or is it rather obvious?
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.
Yay! Please apply the comment with formatting and merge. Well done! 🎉
content/asm_5.md
Outdated
The loop in this macro consists of two lines of code: | ||
|
||
- The first line contains the `%rotate` directive, which rotates the arguments by 1 position at each iteration of the loop. It moves the second argument to the first position, the third argument to the second position, and so on. | ||
- The second line has the invocation of the %%f macro, which was previously defined to expand into the first argument of the REPX macro. It also replaces x in the first argument of REPX with the parameter given to the %%f macro. By passing %1 to %%f, the macro expands to the original first argument of the REPX macro, replacing the placeholder x with each of the subsequent arguments of the REPX. On each iteration of the loop, x is substituted with the next argument of the REPX macro starting from the second because of the previous rotate definition — so the first iteration uses the second argument, the second iteration uses the third, and so on. This is repeated until all arguments are processed. |
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.
- The second line has the invocation of the %%f macro, which was previously defined to expand into the first argument of the REPX macro. It also replaces x in the first argument of REPX with the parameter given to the %%f macro. By passing %1 to %%f, the macro expands to the original first argument of the REPX macro, replacing the placeholder x with each of the subsequent arguments of the REPX. On each iteration of the loop, x is substituted with the next argument of the REPX macro starting from the second because of the previous rotate definition — so the first iteration uses the second argument, the second iteration uses the third, and so on. This is repeated until all arguments are processed. | |
- The second line invokes the `%%f` macro, which was previously defined to expand into the first argument of the REPX macro. It also replaces `x` in the first argument of REPX with the parameter given to the `%%f` macro. By passing `%1` to `%%f`, the macro expands to the original first argument of the REPX macro, replacing the placeholder `x` with each of the subsequent arguments of REPX. On each iteration of the loop, `x` is substituted with the next argument of the REPX macro starting from the second because of the previous rotate definition — so the first iteration uses the second argument, the second iteration uses the third, and so on. This is repeated until all arguments are processed. |
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.
Pull Request Overview
This PR reworks the fifth chapter of the project by updating its reference in the README file. The updated README now labels chapter 5 as "Part 5. Macros".
- Updated the chapter title in the README
- Adjusted the chapter naming for consistency with the rework
Comments suppressed due to low confidence (1)
README.md:28
- The chapter title has been updated to 'Part 5. Macros', which may be misleading based on the PR title and description indicating a broader rework of chapter 5. Consider verifying that the title accurately reflects the chapter's content.
* [Part 5. Macros](https://github.com/0xAX/asm/blob/master/content/asm_5.md)
Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
Description
This PR provides rework of the 5th chapter.