.loop:
movzx rcx, byte [rsi + 8 + 1] ; Length of word being looked at
cmp rcx, [.search_length]
- jne .next ; If the words don't have the same length, we have the wrong word
+ jne .next ; If the words don't have the same length, we have the
+ ; wrong word
;; Otherwise, we need to compare strings
- lea rdx, [rsi + 8 + 1 + 1] ; Location of character being compared in entry
- mov rdi, [.search_buffer] ; Location of character being compared in search buffer
+ lea rdx, [rsi + 8 + 1 + 1] ; Location of character being compared in entry
+ mov rdi, [.search_buffer] ; Location of character being compared in
+ ; search buffer
.compare_char:
mov al, [rdx]
mov ah, [rdi]
cmp al, ah
- jne .next ; They don't match; try again
- inc rdx ; These characters match; look at the next ones
+ jne .next ; They don't match; try again
+ inc rdx ; These characters match; look at the
+ ; next ones
inc rdi
loop .compare_char
- jmp .found ; They match! We are done.
+ jmp .found ; They match! We are done.
.next:
- mov rsi, [rsi] ; Look at the previous entry
+ mov rsi, [rsi] ; Look at the previous entry
cmp rsi, 0
- jnz .loop ; If there is no previous word, exit and return 0
+ jnz .loop ; If there is no previous word, exit and return 0
.found:
ret
-;; Read a word from a buffer. Returns the buffer without the word, as well as
-;; the word that was read (including lengths).
+;; Read a word from a buffer. Returns the buffer without the word, as
+;; well as the word that was read (including lengths).
;;
;; Inputs:
;; * rsi = Input buffer
je .got_whitespace
jmp .alpha
.got_whitespace:
- ;; The buffer starts with whitespace; discard the first character from the buffer.
+ ;; The buffer starts with whitespace; discard the first character
+ ;; from the buffer.
inc rsi
dec rcx
jmp .skip_whitespace
.alpha:
- ;; We got a character that wasn't whitespace. Now read the actual word.
+ ;; We got a character that wasn't whitespace. Now read the actual
+ ;; word.
mov rdi, rsi ; This is where the word starts
mov rdx, 1 ; Length of word
parse_number:
mov r8, 0 ; Result
- ;; Add (10^(rcx-1) * parse_char(rdi[length - rcx])) to the accumulated value
- ;; for each rcx.
+ ;; Add (10^(rcx-1) * parse_char(rdi[length - rcx])) to the
+ ;; accumulated value for each rcx.
mov [.length], rcx
.loop:
;; First, calcuate 10^(rcx - 1)
cmp rbx, 10
jae .error
- ;; Multiply this value by rax to get (10^(rcx-1) * parse_char(rdi[length - rcx])),
+ ;; Multiply this value by rax to get
+ ;; (10^(rcx-1) * parse_char(rdi[length - rcx]))
;; then add this to the result.
mul rbx