Skip to content

Commit

Permalink
asm-2: unify the code and fix README
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Kuleshov <[email protected]>
  • Loading branch information
0xAX committed Dec 25, 2024
1 parent 518b492 commit b7b010c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
20 changes: 10 additions & 10 deletions content/asm_2.md
Original file line number Diff line number Diff line change
Expand Up @@ -431,29 +431,29 @@ section .text
;; Entry point
_start:
;; Set the value of the num1 to the rax
;; Set the value of num1 to rax
mov rax, [num1]
;; Set the value of the num2 to the rbx
mov rbx, [num2]
;; Get sum of the rax and rbx. The result is stored in the rax.
add rax, rbx
.compare:
;; Compare the value of the rax with `150`
;; Compare the rax value with 150
cmp rax, 150
;; Go to the .exit label if the values of the rax and 150 are not equal
;; Go to the .exit label if the rax value is not 150
jne .exit
;; Go to the .correctSum label if the values of the rax and 150 are equal
;; Go to the .correctSum label if the rax value is 150
jmp .correctSum
; Print message that the sum is correct
.correctSum:
;; Number of the system call. 1 - `sys_write`.
;; Specify the system call number (1 is `sys_write`).
mov rax, 1
;; The first argument of the `sys_write` system call. 1 is `stdout`.
;; Set the first argument of `sys_write` to 1 (`stdout`).
mov rdi, 1
;; The second argument of the `sys_write` system call. Reference to the message.
;; Set the second argument of `sys_write` to the reference of the `msg` variable.
mov rsi, msg
;; The third argument of the `sys_write` system call. Length of the message.
;; Set the third argument to the length of the `msg` variable's value (20 bytes).
mov rdx, 20
;; Call the `sys_write` system call.
syscall
Expand All @@ -462,9 +462,9 @@ _start:
; exit procedure
.exit:
;; Number of the system call. 60 - `sys_exit`.
;; Specify the number of the system call (60 is `sys_exit`).
mov rax, 60
;; The first argument of the `sys_exit` system call.
;; Set the first argument of `sys_exit` to `0`. The `0` status code is success.
mov rdi, 0
;; Call the `sys_exit` system call.
syscall
Expand Down
4 changes: 2 additions & 2 deletions sum/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Sum of numbers

This is a basic program that gets the sum of two integer numbers and check that it is correct. It prints the message if the sum is correct, otherwise just exits.
This is a basic program that sums two integer numbers and checks if it is correct. If the sum is correct, it prints the message; otherwise, it just exits.

To build the program, run:

```bash
make
```

For more details, read [Part 2. The `x86_64` concepts](https://github.com/0xAX/asm/blob/master/content/asm_2.md)
For more details, read [Part 2. The `x86_64` concepts](https://github.com/0xAX/asm/blob/master/content/asm_2.md).
20 changes: 10 additions & 10 deletions sum/sum.asm
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@ section .text

;; Entry point
_start:
;; Set the value of the num1 to the rax
;; Set the value of num1 to rax
mov rax, [num1]
;; Set the value of the num2 to the rbx
mov rbx, [num2]
;; Get sum of the rax and rbx. The result is stored in the rax.
add rax, rbx
.compare:
;; Compare the value of the rax with `150`
;; Compare the rax value with 150
cmp rax, 150
;; Go to the .exit label if the values of the rax and 150 are not equal
;; Go to the .exit label if the rax value is not 150
jne .exit
;; Go to the .correctSum label if the values of the rax and 150 are equal
;; Go to the .correctSum label if the rax value is 150
jmp .correctSum

; Print message that the sum is correct
.correctSum:
;; Number of the sytem call. 1 - `sys_write`.
;; Specify the system call number (1 is `sys_write`).
mov rax, 1
;; The first argument of the `sys_write` system call. 1 is `stdout`.
;; Set the first argument of `sys_write` to 1 (`stdout`).
mov rdi, 1
;; The second argument of the `sys_write` system call. Reference to the message.
;; Set the second argument of `sys_write` to the reference of the `msg` variable.
mov rsi, msg
;; The third argument of the `sys_write` system call. Length of the message.
;; Set the third argument to the length of the `msg` variable's value (20 bytes).
mov rdx, 20
;; Call the `sys_write` system call.
syscall
Expand All @@ -45,9 +45,9 @@ _start:

; exit procedure
.exit:
;; Number of the system call. 60 - `sys_exit`.
;; Specify the number of the system call (60 is `sys_exit`).
mov rax, 60
;; The first argument of the `sys_exit` system call.
;; Set the first argument of `sys_exit` to `0`. The `0` status code is success.
mov rdi, 0
;; Call the `sys_exit` system call.
syscall

0 comments on commit b7b010c

Please sign in to comment.