diff options
| author | andromeda <andromeda@lenovo> | 2026-03-18 16:53:35 +0100 |
|---|---|---|
| committer | andromeda <andromeda@lenovo> | 2026-03-18 16:53:35 +0100 |
| commit | d5c2dde221650a601fe4fa873b719400c4038dd1 (patch) | |
| tree | 8d646b307a687555dabea22d8a30fc825a2e0f64 /twasm/asm/main.asm | |
| parent | de60e52c5af08d57cf83b5b110ec19562aa41b17 (diff) | |
identify some tokens
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 ; ------------------------------------------------------------------------------ |
