Skip to content

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

Merged
merged 6 commits into from
Jun 21, 2025
Merged

asm-5: Rework of the 5th chapter #47

merged 6 commits into from
Jun 21, 2025

Conversation

0xAX
Copy link
Owner

@0xAX 0xAX commented Jun 1, 2025

Description

This PR provides rework of the 5th chapter.

0xAX added 3 commits June 1, 2025 18:18
Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
@0xAX 0xAX requested a review from klaudiagrz as a code owner June 1, 2025 16:24
Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
@0xAX 0xAX force-pushed the chapter-5-update branch from 1312d40 to 1d9250c Compare June 5, 2025 16:51
Copy link
Collaborator

@klaudiagrz klaudiagrz left a 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:
Copy link
Collaborator

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?

Copy link
Collaborator

@klaudiagrz klaudiagrz left a 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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 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.

@0xAX 0xAX requested a review from Copilot June 14, 2025 11:13
Copy link

@Copilot Copilot AI left a 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>
@0xAX 0xAX merged commit 28a9dd3 into master Jun 21, 2025
1 check passed
@0xAX 0xAX deleted the chapter-5-update branch June 21, 2025 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants