Compare commits

...

3 Commits

Author SHA1 Message Date
andromeda
50964e945e encode register tokens 2026-03-07 16:44:40 +01:00
andromeda
46bdc91966 clear tables 2026-03-07 15:51:51 +01:00
andromeda
7df3d25727 design token work 2026-03-07 15:43:41 +01:00
2 changed files with 300 additions and 2 deletions

View File

@@ -16,8 +16,7 @@ I want to compile Bootler and Twasm with the Twasm assembler
+------ 0x00070000 ------+
| token table |
+------ 0x00060000 ------+
| |
| |
| stack (rsp) |
+------------------------+
| input |
+------------------------+ this is lined up to a sector
@@ -30,3 +29,102 @@ I want to compile Bootler and Twasm with the Twasm assembler
```
each word represents a token on the token table.
#### token table (TT)
each token gets loaded into the token table with the following form:
```
+----------+-----------------------+
| 31 16 | 15 0 |
+----------+-----------------------+
| reserved | token id |
+----------+-----------------------+
```
### token IDs
supported tokens are listed below
| token | id | notes |
|-------|--------|-|
| rax | 0x0000 | |
| rbx | 0x0001 | |
| rcx | 0x0002 | |
| rdx | 0x0003 | |
| rsi | 0x0004 | |
| rdi | 0x0005 | |
| rsp | 0x0006 | |
| rbp | 0x0007 | |
| r8 | 0x0008 | |
| r9 | 0x0009 | |
| r10 | 0x000A | |
| r11 | 0x000B | |
| r12 | 0x000C | |
| r13 | 0x000D | |
| r14 | 0x000E | |
| r15 | 0x000F | |
| eax | 0x0010 | |
| ebx | 0x0011 | |
| ecx | 0x0012 | |
| edx | 0x0013 | |
| esi | 0x0014 | |
| edi | 0x0015 | |
| esp | 0x0016 | |
| ebp | 0x0017 | |
| r8d | 0x0018 | |
| r9d | 0x0019 | |
| r10d | 0x001A | |
| r11d | 0x001B | |
| r12d | 0x001C | |
| r13d | 0x001D | |
| r14d | 0x001E | |
| r15d | 0x001F | |
| ax | 0x0020 | |
| bx | 0x0021 | |
| cx | 0x0022 | |
| dx | 0x0023 | |
| si | 0x0024 | |
| di | 0x0025 | |
| sp | 0x0026 | |
| bp | 0x0027 | |
| r8w | 0x0028 | |
| r9w | 0x0029 | |
| r10w | 0x002A | |
| r11w | 0x002B | |
| r12w | 0x002C | |
| r13w | 0x002D | |
| r14w | 0x002E | |
| r15w | 0x002F | |
| al | 0x0030 | |
| bl | 0x0031 | |
| cl | 0x0032 | |
| dl | 0x0033 | |
| sil | 0x0034 | |
| dil | 0x0035 | |
| spl | 0x0036 | |
| bpl | 0x0037 | |
| r8b | 0x0038 | |
| r9b | 0x0039 | |
| r10b | 0x003A | |
| r11b | 0x003B | |
| r12b | 0x003C | |
| r13b | 0x003D | |
| r14b | 0x003E | |
| r15b | 0x003F | |
| ah | 0x0040 | |
| bh | 0x0041 | |
| ch | 0x0042 | |
| dh | 0x0043 | |
| cs | 0x0044 | |
| ds | 0x0045 | |
| es | 0x0046 | |
| fs | 0x0047 | |
| gs | 0x0048 | |
| ss | 0x0049 | |
| cr0 | 0x004A | |
| cr2 | 0x004B | |
| cr3 | 0x004C | |
| cr4 | 0x004D | |
| cr8 | 0x004E | |
| | 0xFFFF | unrecognised token |

View File

@@ -22,6 +22,8 @@ start:
call run_tests
call clear_token_table
jmp halt
; ------------------------------------------------------------------------------
@@ -178,6 +180,34 @@ elemb:
.f db "found", 0x0D, 0x0A, 0x00
.nf db "not found", 0x0D, 0x0A, 0x00
; ------------------------------------------------------------------------------
; clear_token_table
;
; description:
; clears the token table as specified by TOKEN_TABLE_SIZE and TOKEN_TABLE_ADDR
; ------------------------------------------------------------------------------
clear_token_table:
xor rax, rax ; value to write
mov rcx, TOKEN_TABLE_SIZE / 4 ; number of double words
mov rdi, TOKEN_TABLE_ADDR ; address to start
rep stosd
ret
; ------------------------------------------------------------------------------
; clear_test_arena
;
; description:
; clears the test arena as specified by TEST_ARENA_SIZE and TEST_ARENA_ADDR
; ------------------------------------------------------------------------------
clear_test_arena:
xor rax, rax ; value to write
mov rcx, TOKEN_TABLE_SIZE / 4 ; number of double words
mov rdi, TOKEN_TABLE_ADDR ; address to start
rep stosd
ret
; ------------------------------------------------------------------------------
; tests
; ------------------------------------------------------------------------------
@@ -193,8 +223,13 @@ run_tests:
mov rsi, .msg
call print
call clear_test_arena
call test_copy_byte
call clear_test_arena
call test_copy_token
call clear_test_arena
call test_elemb
ret
@@ -353,6 +388,171 @@ test_elemb:
; data
; ------------------------------------------------------------------------------
tokens:
.length2
db "r8"
dw 0x0008
db "r9"
dw 0x0009
db "ax"
dw 0x0020
db "bx"
dw 0x0021
db "cx"
dw 0x0022
db "dx"
dw 0x0023
db "si"
dw 0x0024
db "di"
dw 0x0025
db "sp"
dw 0x0026
db "bp"
dw 0x0027
db "al"
dw 0x0030
db "bl"
dw 0x0031
db "cl"
dw 0x0032
db "dl"
dw 0x0033
db "ah"
dw 0x0040
db "bh"
dw 0x0041
db "ch"
dw 0x0042
db "dh"
dw 0x0043
db "cs"
dw 0x0044
db "ds"
dw 0x0045
db "es"
dw 0x0046
db "fs"
dw 0x0047
db "gs"
dw 0x0048
db "ss"
dw 0x0049
.length3
db "rax"
dw 0x0000
db "rbx"
dw 0x0001
db "rcx"
dw 0x0002
db "rdx"
dw 0x0003
db "rsi"
dw 0x0004
db "rdi"
dw 0x0005
db "rsp"
dw 0x0006
db "rbp"
dw 0x0007
db "r10"
dw 0x000A
db "r11"
dw 0x000B
db "r12"
dw 0x000C
db "r13"
dw 0x000D
db "r14"
dw 0x000E
db "r15"
dw 0x000F
db "eax"
dw 0x0010
db "ebx"
dw 0x0011
db "ecx"
dw 0x0012
db "edx"
dw 0x0013
db "esi"
dw 0x0014
db "edi"
dw 0x0015
db "esp"
dw 0x0016
db "ebp"
dw 0x0017
db "r8d"
dw 0x0018
db "r9d"
dw 0x0019
db "r8w"
dw 0x0028
db "r9w"
dw 0x0029
db "sil"
dw 0x0034
db "dil"
dw 0x0035
db "spl"
dw 0x0036
db "bpl"
dw 0x0037
db "r8b"
dw 0x0038
db "r9b"
dw 0x0039
db "cr0"
dw 0x004A
db "cr2"
dw 0x004B
db "cr3"
dw 0x004C
db "cr4"
dw 0x004D
db "cr8"
dw 0x004E
.length4
db "r10d"
dw 0x001A
db "r11d"
dw 0x001B
db "r12d"
dw 0x001C
db "r13d"
dw 0x001D
db "r14d"
dw 0x001E
db "r15d"
dw 0x001F
db "r10w"
dw 0x002A
db "r11w"
dw 0x002B
db "r12w"
dw 0x002C
db "r13w"
dw 0x002D
db "r14w"
dw 0x002E
db "r15w"
dw 0x002F
db "r10b"
dw 0x003A
db "r11b"
dw 0x003B
db "r12b"
dw 0x003C
db "r13b"
dw 0x003D
db "r14b"
dw 0x003E
db "r15b"
dw 0x003F
.length5
.end
msg_welcome db "Welcome to Twasm", 0x0D, 0x0A, 0x00
msg_halt db "halted.", 0x0D, 0x0A, 0x00
msg_pass db "passed.", 0x0D, 0x0A, 0x00