Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions casm/casm1/casm.asm
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
;; Definition of the `data` section
section .data
;; String variable with the value `hello world!`
msg db "hello, world!"
;; `10` is the ASCII code of the new line symbol.
msg db "hello, world!", 10

;; Reference to the C stdlib functions that we will use
extern write, exit
Expand All @@ -17,8 +18,8 @@ _start:
mov rdi, 1
;; Set the second argument of the `write` function to the reference of the `msg` variable.
mov rsi, msg
;; Set the third argument to the length of the `msg` variable's value (13 bytes).
mov rdx, 13
;; Set the third argument to the length of the `msg` variable's value (14 bytes).
mov rdx, 14
;; Call the `write` function.
call write

Expand Down
2 changes: 1 addition & 1 deletion content/asm_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Let's write our first assembly program based on this code sample:
;; Definition of the `data` section
section .data
;; String variable with the value `hello world!`.
;; `10` is the ASCII code for the line feed character (LF), i.e., '\n'.
;; `10` is the ASCII code of the new line symbol.
msg db "hello, world!", 10

;; Definition of the text section
Expand Down
6 changes: 3 additions & 3 deletions content/asm_2.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ To get the actual value located in the given address, we need to specify the var

```assembly
;; Move the value of num1 to the al register
mov al, [num1]
mov al, [rel num1]
```

### Stack
Expand Down Expand Up @@ -433,9 +433,9 @@ section .text
;; Entry point
_start:
;; Set the value of num1 to rax
mov rax, [num1]
mov rax, [rel num1]
;; Set the value of num2 to rbx
mov rbx, [num2]
mov rbx, [rel num2]
;; Get the sum of rax and rbx. The result is stored in rax.
add rax, rbx
.compare:
Expand Down
9 changes: 5 additions & 4 deletions content/asm_3.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,10 @@ section .data
;; ASCII code of the new line symbol ('\n')
NEW_LINE db 0xa
;; Error message that is printed in a case of not enough command-line arguments
WRONG_ARGC_MSG db "Error: expected two command-line arguments", 0xa
;; `10` is the ASCII code of the new line symbol.
WRONG_ARGC_MSG db "Error: expected two command-line arguments", 10
;; Length of the WRONG_ARGC_MSG message
WRONG_ARGC_MSG_LEN equ 42
WRONG_ARGC_MSG_LEN equ 43

;; Definition of the .text section
section .text
Expand Down Expand Up @@ -223,7 +224,7 @@ str_to_int:
mov rcx, 10
__repeat:
;; Compare the first element in the given string with the `NUL` terminator (end of the string).
cmp [rsi], byte 0
cmp byte [rsi], 0
;; If we reached the end of the string, return from the procedure. The result is stored in the rax register.
je __return
;; Move the current character from the command-line argument to the bl register.
Expand Down Expand Up @@ -436,7 +437,7 @@ str_to_int:
mov rcx, 10
__repeat:
;; Compare the first element in the given string with the `NUL` terminator (end of the string).
cmp [rsi], byte 0
cmp byte [rsi], 0
;; If we reached the end of the string, return from the procedure. The result is stored in the rax register.
je __return
;; Move the current character from the command-line argument to the bl register.
Expand Down
2 changes: 1 addition & 1 deletion content/asm_6.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ _parse_first_float_vector:
call strtod
;; Preserve the pointer to the next floating-point value from the input buffer
;; in the rax register.
mov rax, [end_buffer_1]
mov rax, [rel end_buffer_1]
;; Check whether it is the end of the input string.
cmp rax, rdi
;; Proceed with the second vector if we reached the end of the first vector.
Expand Down
12 changes: 7 additions & 5 deletions content/asm_7.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Let's go back to the [`hello world`](./asm_1.md) example from the very first cha
;; Definition of the `data` section
section .data
;; String variable with the value `hello world!`
msg db "hello, world!"
;; `10` is the ASCII code of the new line symbol.
msg db "hello, world!", 10

;; Definition of the text section
section .text
Expand All @@ -34,7 +35,7 @@ _start:
;; Set the second argument of `sys_write` to the reference of the `msg` variable.
mov rsi, msg
;; Set the third argument of `sys_write` to the length of the `msg` variable's value (13 bytes).
mov rdx, 13
mov rdx, 14
;; Call the `sys_write` system call.
syscall

Expand Down Expand Up @@ -62,7 +63,8 @@ Let's take a look at the implementation:
;; Definition of the `data` section
section .data
;; String variable with the value `hello world!`
msg db "hello, world!"
;; `10` is the ASCII code of the new line symbol.
msg db "hello, world!", 10

;; Reference to the C stdlib functions that we will use
extern write, exit
Expand All @@ -78,8 +80,8 @@ _start:
mov rdi, 1
;; Set the second argument of the `write` function to the reference of the `msg` variable.
mov rsi, msg
;; Set the third argument to the length of the `msg` variable's value (13 bytes).
mov rdx, 13
;; Set the third argument to the length of the `msg` variable's value (14 bytes).
mov rdx, 14
;; Call the `write` function.
call write

Expand Down
4 changes: 2 additions & 2 deletions float/dot_product.asm
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ _parse_first_float_vector:

;; Preserve the pointer to the next floating-point value from the input buffer
;; in the rax register.
mov rax, [end_buffer_1]
mov rax, [rel end_buffer_1]
;; Check whether it is the end of the input string.
cmp rax, rdi
;; Proceed with the second vector if we reached the end of the first vector.
Expand Down Expand Up @@ -197,7 +197,7 @@ _parse_second_float_vector:

;; Preserve the pointer to the next floating-point value from the input buffer
;; in the rax register.
mov rax, [end_buffer_2]
mov rax, [rel end_buffer_2]
;; Check whether it is the end of the input string.
cmp rax, rdi
;; Calculate the dot product after we have both vectors.
Expand Down
4 changes: 2 additions & 2 deletions hello/hello.asm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
;; Definition of the `data` section
section .data
;; String variable with the value `hello world!`.
;; `10` is the ASCII code for the line feed character (LF), i.e., '\n'.
;; `10` is the ASCII code of the new line symbol.
msg db "hello, world!", 10

;; Definition of the text section
Expand All @@ -27,4 +27,4 @@ _start:
;; 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
syscall
7 changes: 4 additions & 3 deletions stack/stack.asm
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ section .data
;; ASCII code of the new line symbol ('\n')
NEW_LINE db 0xa
;; Error message that is printed in a case of not enough command-line arguments
WRONG_ARGC_MSG db "Error: expected two command-line arguments", 0xa
;; `10` is the ASCII code of the new line symbol.
WRONG_ARGC_MSG db "Error: expected two command-line arguments", 10
;; Length of the WRONG_ARGC_MSG message
WRONG_ARGC_MSG_LEN equ 42
WRONG_ARGC_MSG_LEN equ 43

;; Definition of the .text section
section .text
Expand Down Expand Up @@ -79,7 +80,7 @@ str_to_int:
mov rcx, 10
__repeat:
;; Compare the first element in the given string with the `NUL` terminator (end of the string).
cmp [rsi], byte 0
cmp byte [rsi], 0
;; If we reached the end of the string, return from the procedure. The result is stored in the rax register.
je __return
;; Move the current character from the command-line argument to the bl register.
Expand Down
4 changes: 2 additions & 2 deletions sum/sum.asm
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ section .text
;; Entry point
_start:
;; Set the value of num1 to rax
mov rax, [num1]
mov rax, [rel num1]
;; Set the value of num2 to rbx
mov rbx, [num2]
mov rbx, [rel num2]
;; Get the sum of rax and rbx. The result is stored in rax.
add rax, rbx
.compare:
Expand Down
Loading