-
Notifications
You must be signed in to change notification settings - Fork 330
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
base: master
Are you sure you want to change the base?
Conversation
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.
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: |
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.
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: |
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.
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. |
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.
- 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. |
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.
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: |
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.
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 |
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.
;; 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 |
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.
;; Add the value of the rcx to rdx | |
;; Add the value of rcx to rdx |
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.
Not sure: incremets/adds (as we are talking about "this instruction that DOES these actions"), or increment/add as just an action 🤔
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'd leave just an action
content/asm_4.md
Outdated
- `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. |
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.
- `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. |
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 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.
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.
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 |
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.
;; 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 |
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.
;; 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>
Description
This PR provides rework of the 4th chapter.