1 segment readable executable
3 ;; Find the given word in the dictionary of words. If no such word exists,
7 ;; * [find.search_length] = Length of the word in bytes.
8 ;; * [find.search_buffer] = Pointer to the string containing the word.
9 ;; * rsi = Pointer to the last entry in the dictionary.
12 ;; * rsi = Pointer to the found entry in the dictionary or 0.
14 ;; Clobbers rcx, rdx, rdi, rax.
16 ;; RSI contains the entry we are currently looking at
18 movzx rcx, byte [rsi + 8 + 1] ; Length of word being looked at
19 cmp rcx, [.search_length]
20 jne .next ; If the words don't have the same length, we have the wrong word
22 ;; Otherwise, we need to compare strings
23 lea rdx, [rsi + 8 + 1 + 1] ; Location of character being compared in entry
24 mov rdi, [.search_buffer] ; Location of character being compared in search buffer
29 jne .next ; They don't match; try again
30 inc rdx ; These characters match; look at the next ones
34 jmp .found ; They match! We are done.
37 mov rsi, [rsi] ; Look at the previous entry
39 jnz .loop ; If there is no previous word, exit and return 0
44 ;; Read a word from standard input. Returns pointer to string containing word as
48 ;; * rdx = Length of string
49 ;; * rdi = Pointer to string buffer
51 ;; Clobbers pretty much everything.
54 ;; Read characters into .char_buffer until one of them is not whitespace.
61 ;; We consider newlines and spaces to be whitespace.
62 cmp [.char_buffer], ' '
64 cmp [.char_buffer], $A
68 ;; We got a character that wasn't whitespace. Now read the actual word.
72 mov al, [.char_buffer]
85 cmp [.char_buffer], ' '
87 cmp [.char_buffer], $A
99 ;; * rcx = Length of string
100 ;; * rdi = Pointer to string buffer
109 ;; Add (10^(rcx-1) * parse_char(rdi[length - rcx])) to the accumulated value
113 ;; First, calcuate 10^(rcx - 1)
125 ;; Now, rax = 10^(rcx - 1).
127 ;; We need to calulate the value of the character at rdi[length - rcx].
131 movzx rbx, byte [rbx]
134 ;; Multiply this value by rax to get (10^(rcx-1) * parse_char(rdi[length - rcx])),
135 ;; then add this to the result.
138 ;; Add that value to r8
148 segment readable writable
150 find.search_length dq ?
151 find.search_buffer dq ?
153 read_word.max_size = $FF
154 read_word.buffer rb read_word.max_size
155 read_word.length db ?
156 read_word.char_buffer db ?
158 parse_number.length dq ?