diff options
Diffstat (limited to 'twasm/asm/main.asm')
| -rw-r--r-- | twasm/asm/main.asm | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/twasm/asm/main.asm b/twasm/asm/main.asm index ead107e..4b23759 100644 --- a/twasm/asm/main.asm +++ b/twasm/asm/main.asm @@ -913,6 +913,71 @@ evaluate_constant: ret ; ------------------------------------------------------------------------------ +; identify_register +; +; description: +; takes a register in ascii-encoded text and returns its token ID or +; UNRECOGNISED_TOKEN_ID if not recognised +; +; parameters: +; edi = register to be searched +; +; returned: +; ax = register's token ID or UNRECOGNISED_TOKEN_ID +; ------------------------------------------------------------------------------ + +identify_register: + xor eax, eax ; tokens.registers + eax -> entry in tokens.registers + .loop: + cmp eax, (tokens.registers_end - tokens.registers) + jge .not_found + + cmp edi, [tokens.registers + eax] + je .found + + add eax, 6 + jmp .loop + .found: + mov ax, [tokens.registers + eax + 4] + ret + .not_found: + mov ax, UNRECOGNISED_TOKEN_ID + ret + +; ------------------------------------------------------------------------------ +; identify_operator +; TODO combine with identify_register +; +; description: +; takes an operator in ascii-encoded text and returns its token ID or +; UNRECOGNISED_TOKEN_ID if not recognised +; +; parameters: +; edi = operator to be searched +; +; returned: +; ax = operator's token ID or UNRECOGNISED_TOKEN_ID +; ------------------------------------------------------------------------------ + +identify_operator: + xor eax, eax ; tokens.operators + eax -> entry in tokens.operators + .loop: + cmp eax, (tokens.operators_end - tokens.operators) + jge .not_found + + cmp edi, [tokens.operators + eax] + je .found + + add eax, 6 + jmp .loop + .found: + mov ax, [tokens.operators + eax + 4] + ret + .not_found: + mov ax, UNRECOGNISED_TOKEN_ID + ret + +; ------------------------------------------------------------------------------ ; utilities ; ------------------------------------------------------------------------------ |
