Skip to content

asm-4: Rework of the 4th chapter #43

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

asm-4: Rework of the 4th chapter #43

wants to merge 3 commits into from

Conversation

0xAX
Copy link
Owner

@0xAX 0xAX commented Apr 12, 2025

Description

This PR provides rework of the 4th chapter.

Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
@0xAX 0xAX requested a review from klaudiagrz as a code owner April 12, 2025 13:24
Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
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.

First part of the review

content/asm_4.md Outdated

Some time ago i started to write series of blog posts about assembly programming for x86_64. You can find it by asm tag. Unfortunately i was busy last time and there were not new post, so today I continue to write posts about assembly, and will try to do it every week.
Building simple examples in the previous chapters, we have understood that a basic assembly program consists basically from two things:
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
Building simple examples in the previous chapters, we have understood that a basic assembly program consists basically from two things:
In the previous chapters, we built a few simple examples and figured out that a basic assembly program consists of just two main things:

content/asm_4.md Outdated

## Reverse string
We know that there many types of instructions:
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
We know that there many types of instructions:
We also learned that there are different types of instructions, like:

content/asm_4.md Outdated
- Logical instructions
- Control transfer instruction
- String instructions
- Other instructions like I/O instructions, flag control instructions, bits instructions.
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
- Other instructions like I/O instructions, flag control instructions, bits instructions.
- And others, like I/O, flag control, and bit manipulation instructions

content/asm_4.md Outdated

First of all, I define initialized data. It will be placed in data section (You can read about sections in part):
Some of them we have seen in the previous chapters already. In this chapter we will learn more details about them.
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
Some of them we have seen in the previous chapters already. In this chapter we will learn more details about them.
We’ve already seen some of them in action, but in this chapter, we’re going to dive a little deeper into how they work — especially when it comes to working with data.

content/asm_4.md Outdated

## Data transfer instructions

As you may guess based on the name, the data transfer instructions used to move data between memory and general-purpose registers. One of the most used and well know to us instruction is `mov`. We use it to move data between general-purpose registers, to move an immediate value to a general-purpose register, and to move data between memory and general purpose registers. The first two cases are simple. We just specify two general purpose registers which we want to use to move data. For example to copy value of the `rcx` register to `rax` we can with:
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
As you may guess based on the name, the data transfer instructions used to move data between memory and general-purpose registers. One of the most used and well know to us instruction is `mov`. We use it to move data between general-purpose registers, to move an immediate value to a general-purpose register, and to move data between memory and general purpose registers. The first two cases are simple. We just specify two general purpose registers which we want to use to move data. For example to copy value of the `rcx` register to `rax` we can with:
Data transfer instructions are used to move data between memory and general-purpose registers. One of the most commonly used and familiar instructions is `mov`. We use it to:
- Move data between general-purpose registers
- Move an immediate value to a general-purpose register
- Move data between memory and general-purpose registers
The first two cases are simple. We just specify two general-purpose registers we want to use to move data. For example, to copy the value of the `rcx` register into `rax`, we can use:

content/asm_4.md Outdated
inc rcx
;; loop again
jmp calculateStrLength
;; Increment the value of the rcx
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
;; Increment the value of the rcx
;; Increment the value of the rcx register

content/asm_4.md Outdated
;; Increment the value of the rcx
inc rcx

;; Add the value of the rcx to rdx
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
;; Add the value of the rcx to rdx
;; Add the value of rcx to rdx

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure: incremets/adds (as we are talking about "this instruction that DOES these actions"), or increment/add as just an action 🤔

Copy link
Owner Author

Choose a reason for hiding this comment

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

I'd leave just an action

content/asm_4.md Outdated
Comment on lines 81 to 84
- `and` - Logical *and*. The instruction takes two operands and performs the logical *and* operation on them. The result is stored in the first operand.
- `or` - Logical *or*. The instruction takes two operands and performs the logical *or* operation on them. The result is stored in the first operand.
- `xor` - Logical *xor*. The instruction takes two operands and performs the logical *xor* operation on them. The result is stored in the first operand.
- `not` - Logical *not*. The instruction takes two operands and performs the logical *not* operation on them. The result is stored in the first operand.
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
- `and` - Logical *and*. The instruction takes two operands and performs the logical *and* operation on them. The result is stored in the first operand.
- `or` - Logical *or*. The instruction takes two operands and performs the logical *or* operation on them. The result is stored in the first operand.
- `xor` - Logical *xor*. The instruction takes two operands and performs the logical *xor* operation on them. The result is stored in the first operand.
- `not` - Logical *not*. The instruction takes two operands and performs the logical *not* operation on them. The result is stored in the first operand.
- `and` - The instruction takes two operands and performs the logical *and* operation on them. The result is stored in the first operand.
- `or` - The instruction takes two operands and performs the logical *or* operation on them. The result is stored in the first operand.
- `xor` - The instruction takes two operands and performs the logical *xor* operation on them. The result is stored in the first operand.
- `not` - The instruction takes two operands and performs the logical *not* operation on them. The result is stored in the first operand.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would remove first part of the explanation, as you anyway explain in the second sentence what logical operation is performed. Also, the name of the instruction itself is quite self-explanatory.

Also, consider to move the last sentence repeated in all instructions into a separate sentence underneath:

The result of these operations is always stored in the first operand.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yes. This is very good suggestion.

content/asm_4.md Outdated
exitFromRoutine:
;; return to _start
ret
;; If rax = 1 and rbx = 0, rax will store 0
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
;; If rax = 1 and rbx = 0, rax will store 0
;; If rax = 1 and rbx = 0, rax stores 0

content/asm_4.md Outdated
;; If rax = 1 and rbx = 0, rax will store 0
and rax, rbx

;; If rax = 1 and rbx = 0, rax will store 1
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
;; If rax = 1 and rbx = 0, rax will store 1
;; If rax = 1 and rbx = 0, rax stores 1

Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
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