From d5c2dde221650a601fe4fa873b719400c4038dd1 Mon Sep 17 00:00:00 2001 From: andromeda Date: Wed, 18 Mar 2026 16:53:35 +0100 Subject: identify some tokens --- twasm/asm/main.asm | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'twasm/asm/main.asm') 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 @@ -912,6 +912,71 @@ evaluate_constant: mov rdx, 0xFF ; unrecognised type 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 ; ------------------------------------------------------------------------------ -- cgit v1.3.1