aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2020-10-16 13:34:42 +0300
committerAleksey Veresov <aleksey@veresov.pro>2020-10-16 13:34:42 +0300
commit68ea390db8e5977dcc84dc93daeb467ee243cb35 (patch)
tree4d503843299b68da2fd55b3a212f7afecadf6e4a
parent405c4f104975e5456ce6b28ad31fd996d3f4b657 (diff)
downloadcryptrobber-68ea390db8e5977dcc84dc93daeb467ee243cb35.tar
cryptrobber-68ea390db8e5977dcc84dc93daeb467ee243cb35.tar.xz
cryptrobber-68ea390db8e5977dcc84dc93daeb467ee243cb35.zip
Restyled ia32.
-rw-r--r--ia32/arithmetic.sts103
-rw-r--r--ia32/branch.sts20
-rw-r--r--ia32/core.sts27
-rw-r--r--ia32/ia32.sts2
-rw-r--r--ia32/macro.sts48
-rw-r--r--ia32/math.sts63
-rw-r--r--ia32/memory.sts15
-rw-r--r--ia32/stack.sts21
-rw-r--r--ia32/syscall.sts61
-rw-r--r--main.sts32
10 files changed, 151 insertions, 241 deletions
diff --git a/ia32/arithmetic.sts b/ia32/arithmetic.sts
deleted file mode 100644
index c9b4bf8..0000000
--- a/ia32/arithmetic.sts
+++ /dev/null
@@ -1,103 +0,0 @@
-defasm +
-; pop eax
-# 58 ?'
-; add [esp], eax
-# 01 ?' # 04 ?' # 24 ?'
-next
-
-defasm -
-; pop eax
-# 58 ?'
-; sub [esp], eax
-# 29 ?' # 04 ?' # 24 ?'
-next
-
-defasm /
-; pop ebx
-# 5b ?'
-; pop eax
-# 58 ?'
-; xor edx, edx
-# 31 ?' # d2 ?'
-; div ebx
-# f7 ?' # f3 ?'
-; push edx
-# 52 ?'
-; push eax
-# 50 ?'
-next
-
-defasm =
-; pop ebx
-# 5b ?'
-; pop eax
-# 58 ?'
-; cmp eax, ebx
-# 39 ?' # d8 ?'
-; sete al
-# 0f ?' # 94 ?' # c0 ?'
-; movzx eax, al
-# 0f ?' # b6 ?' # c0 ?'
-; push eax
-# 50 ?'
-next
-
-defasm !=
-; pop ebx
-# 5b ?'
-; pop eax
-# 58 ?'
-; cmp eax, ebx
-# 39 ?' # d8 ?'
-; sete al
-# 0f ?' # 95 ?' # c0 ?'
-; movzx eax, al
-# 0f ?' # b6 ?' # c0 ?'
-; push eax
-# 50 ?'
-next
-
-defasm !=
-; pop ebx
-# 5b ?'
-; pop eax
-# 58 ?'
-; cmp eax, ebx
-# 39 ?' # d8 ?'
-; sete al
-# 0f ?' # 95 ?' # c0 ?'
-; movzx eax, al
-# 0f ?' # b6 ?' # c0 ?'
-; push eax
-# 50 ?'
-next
-
-defasm <
-; pop ebx
-# 5b ?'
-; pop eax
-# 58 ?'
-; cmp eax, ebx
-# 39 ?' # d8 ?'
-; setb al
-# 0f ?' # 92 ?' # c0 ?'
-; movzx eax, al
-# 0f ?' # b6 ?' # c0 ?'
-; push eax
-# 50 ?'
-next
-
-defasm >
-; pop ebx
-# 5b ?'
-; pop eax
-# 58 ?'
-; cmp eax, ebx
-# 39 ?' # d8 ?'
-; seta al
-# 0f ?' # 97 ?' # c0 ?'
-; movzx eax, al
-# 0f ?' # b6 ?' # c0 ?'
-; push eax
-# 50 ?'
-next
diff --git a/ia32/branch.sts b/ia32/branch.sts
index bedfbba..9c71217 100644
--- a/ia32/branch.sts
+++ b/ia32/branch.sts
@@ -1,19 +1,11 @@
defasm branch
-; mov esi, [esi]
-# 8b ?' # 36 ?'
-; go next
+ # 8b ?' # 36 ?' ; mov esi, [esi]
next
defasm 0branch
-; pop eax
-# 58 ?'
-; add esi, 4
-# 83 ?' # c6 ?' # 4 ?'
-; cmp eax, 0
-# 83 ?' # f8 ?' # 00 ?'
-; jne +3
-# 75 ?' # 3 ?'
-; mov esi, [esi - 4]
-# 8b ?' # 76 ?' # fc ?'
-; go next
+ # 58 ?' ; pop eax
+ # 83 ?' # c6 ?' # 4 ?' ; add esi, 4
+ # 83 ?' # f8 ?' # 00 ?' ; cmp eax, 0
+ # 75 ?' # 3 ?' ; jne +3
+ # 8b ?' # 76 ?' # fc ?' ; mov esi, [esi - 4]
next
diff --git a/ia32/core.sts b/ia32/core.sts
index fd2d062..fcb62ae 100644
--- a/ia32/core.sts
+++ b/ia32/core.sts
@@ -1,26 +1,17 @@
defasm docol
-; sub ebp, 4
-# 83 ?' # ed ?' # 4 ?'
-; mov [ebp], esi
-# 89 ?' # 75 ?' # 0 ?'
-; add eax, 4
-# 83 ?' # c0 ?' # 4 ?'
-; mov esi, eax
-# 89 ?' # c6 ?'
-; go next
-# ad ?' # ff ?' # 20 ?'
+ # 83 ?' # ed ?' # 4 ?' ; sub ebp, 4
+ # 89 ?' # 75 ?' # 0 ?' ; mov [ebp], esi
+ # 83 ?' # c0 ?' # 4 ?' ; add eax, 4
+ # 89 ?' # c6 ?' ; mov esi, eax
+ # ad ?' # ff ?' # 20 ?' ; go next
next
defasm exit
-; mov esi, [ebp]
-# 8b ?' # 75 ?' # 0 ?'
-; add ebp, 4
-# 83 ?' # c5 ?' # 4 ?'
+ # 8b ?' # 75 ?' # 0 ?' ; mov esi, [ebp]
+ # 83 ?' # c5 ?' # 4 ?' ; add ebp, 4
next
defasm lit
-; lodsd
-# ad ?'
-; push eax
-# 50 ?'
+ # ad ?' ; lodsd
+ # 50 ?' ; push eax
next
diff --git a/ia32/ia32.sts b/ia32/ia32.sts
index bedec54..4d9e426 100644
--- a/ia32/ia32.sts
+++ b/ia32/ia32.sts
@@ -3,5 +3,5 @@ module ia32/core.sts
module ia32/stack.sts
module ia32/branch.sts
module ia32/memory.sts
-module ia32/arithmetic.sts
+module ia32/math.sts
module ia32/syscall.sts
diff --git a/ia32/macro.sts b/ia32/macro.sts
index befcccb..efd062e 100644
--- a/ia32/macro.sts
+++ b/ia32/macro.sts
@@ -1,50 +1,50 @@
[ next 0
- # ad ?' # ff ?' # 20 ?'
+ # ad ?' # ff ?' # 20 ?'
]
[ defasm 1
- [ %1% 0
- _%0% ?.
- \]
- ?$ ?? _%1%
- ?$ # 4 ?+ ?.
+ [ %1% 0
+ _%0% ?.
+ \]
+ ?$ ?? _%1%
+ ?$ # 4 ?+ ?.
]
[ defword 1
- [ %1% 0
- _%0% ?.
- \]
- ?$ ?? _%1%
- _docol # 4 ?+ ?.
+ [ %1% 0
+ _%0% ?.
+ \]
+ ?$ ?? _%1%
+ _docol # 4 ?+ ?.
]
[ defarr 2
- _data_segment ?choose
- ?$ ?? _%1%_arr
- # %2% # 4 ?* ?res
- _code_segment ?choose
- defasm %1%
- ; push _%1%_arr
- # 68 ?' _%1%_arr ?.
- next
+ _data_segment ?choose
+ ?$ ?? _%1%_arr
+ # %2% # 4 ?* ?res
+ _code_segment ?choose
+ defasm %1%
+ ; push _%1%_arr
+ # 68 ?' _%1%_arr ?.
+ next
]
[ defvar 1
- defarr %1% 1
+ defarr %1% 1
]
[ literal 0
- lit # %1% ?.
+ lit # %1% ?.
]
[ set_entry 0
- ?$ _threaded_code_entry ?!
+ ?$ _threaded_code_entry ?!
]
[ if 0
- 0branch ?$ # 0 ?.
+ 0branch ?$ # 0 ?.
]
[ fi 0
- ?$ ?swap ?!
+ ?$ ?swap ?!
]
diff --git a/ia32/math.sts b/ia32/math.sts
new file mode 100644
index 0000000..1864a93
--- /dev/null
+++ b/ia32/math.sts
@@ -0,0 +1,63 @@
+defasm +
+ # 58 ?' ; pop eax
+ # 01 ?' # 04 ?' # 24 ?' ; add [esp], eax
+next
+
+defasm -
+ # 58 ?' ; pop eax
+ # 29 ?' # 04 ?' # 24 ?' ; sub [esp], eax
+next
+
+defasm /
+ # 5b ?' ; pop ebx
+ # 58 ?' ; pop eax
+ # 31 ?' # d2 ?' ; xor edx, edx
+ # f7 ?' # f3 ?' ; div ebx
+ # 52 ?' ; push edx
+ # 50 ?' ; push eax
+next
+
+defasm =
+ # 5b ?' ; pop ebx
+ # 58 ?' ; pop eax
+ # 39 ?' # d8 ?' ; cmp eax, ebx
+ # 0f ?' # 94 ?' # c0 ?' ; sete al
+ # 0f ?' # b6 ?' # c0 ?' ; movzx eax, al
+ # 50 ?' ; push eax
+next
+
+defasm !=
+ # 5b ?' ; pop ebx
+ # 58 ?' ; pop eax
+ # 39 ?' # d8 ?' ; cmp eax, ebx
+ # 0f ?' # 95 ?' # c0 ?' ; sete al
+ # 0f ?' # b6 ?' # c0 ?' ; movzx eax, al
+ # 50 ?' ; push eax
+next
+
+defasm !=
+ # 5b ?' ; pop ebx
+ # 58 ?' ; pop eax
+ # 39 ?' # d8 ?' ; cmp eax, ebx
+ # 0f ?' # 95 ?' # c0 ?' ; sete al
+ # 0f ?' # b6 ?' # c0 ?' ; movzx eax, al
+ # 50 ?' ; push eax
+next
+
+defasm <
+ # 5b ?' ; pop ebx
+ # 58 ?' ; pop eax
+ # 39 ?' # d8 ?' ; cmp eax, ebx
+ # 0f ?' # 92 ?' # c0 ?' ; setb al
+ # 0f ?' # b6 ?' # c0 ?' ; movzx eax, al
+ # 50 ?' ; push eax
+next
+
+defasm >
+ # 5b ?' ; pop ebx
+ # 58 ?' ; pop eax
+ # 39 ?' # d8 ?' ; cmp eax, ebx
+ # 0f ?' # 97 ?' # c0 ?' ; seta al
+ # 0f ?' # b6 ?' # c0 ?' ; movzx eax, al
+ # 50 ?' ; push eax
+next
diff --git a/ia32/memory.sts b/ia32/memory.sts
index f176c13..891fab0 100644
--- a/ia32/memory.sts
+++ b/ia32/memory.sts
@@ -1,15 +1,10 @@
defasm @
-; pop eax
-# 58 ?'
-; push dword [eax]
-# ff ?' # 30 ?'
+ # 58 ?' ; pop eax
+ # ff ?' # 30 ?' ; push dword [eax]
next
defasm !
-; pop ebx
-# 5b ?'
-; pop eax
-# 58 ?'
-; mov [ebx], eax
-# 89 ?' # 03 ?'
+ # 5b ?' ; pop ebx
+ # 58 ?' ; pop eax
+ # 89 ?' # 03 ?' ; mov [ebx], eax
next
diff --git a/ia32/stack.sts b/ia32/stack.sts
index a8ac749..56f4f07 100644
--- a/ia32/stack.sts
+++ b/ia32/stack.sts
@@ -1,25 +1,18 @@
defasm drop
-; pop eax
-# 58 ?'
+ # 58 ?' ; pop eax
next
defasm dup
-; push dword [esp]
-# ff ?' # 34 ?' # 24 ?'
+ # ff ?' # 34 ?' # 24 ?' ; push dword [esp]
next
defasm over
-; push dword [esp + 4]
-# ff ?' # 74 ?' # 24 ?' # 4 ?'
+ # ff ?' # 74 ?' # 24 ?' # 4 ?' ; push dword [esp + 4]
next
defasm swap
-; pop eax
-# 58 ?'
-; pop ebx
-# 5b ?'
-; push eax
-# 50 ?'
-; push ebx
-# 53 ?'
+ # 58 ?' ; pop eax
+ # 5b ?' ; pop ebx
+ # 50 ?' ; push eax
+ # 53 ?' ; push ebx
next
diff --git a/ia32/syscall.sts b/ia32/syscall.sts
index 58a6ffd..3bce0ff 100644
--- a/ia32/syscall.sts
+++ b/ia32/syscall.sts
@@ -1,50 +1,31 @@
defasm quit
-; mov eax, 1
-# b8 ?' # 1 ?.
-; xor ebx, ebx
-# 31 ?' # db ?'
-; int 0x80
-# cd ?' # 80 ?'
+ # b8 ?' # 1 ?. ; mov eax, 1
+ # 31 ?' # db ?' ; xor ebx, ebx
+ # cd ?' # 80 ?' ; int 0x80
+; no need in next since this is the last instruction
_data_segment ?choose
-?$ ?? _io_buffer
-# 0 ?'
+ ?$ ?? _iobuf # 0 ?'
_code_segment ?choose
defasm key
-; mov eax, 3
-# b8 ?' # 3 ?.
-; xor ebx, ebx
-# 31 ?' # db ?'
-; mov ecx, _io_buffer
-# b9 ?' _io_buffer ?.
-; mov edx, 1
-# ba ?' # 1 ?.
-; int 0x80
-# cd ?' # 80 ?'
-; xor ebx, ebx
-# 31 ?' # db ?'
-; mov bl, [_io_buffer]
-# 8a ?' # 1d ?' _io_buffer ?.
-; push ebx
-# 53 ?'
-; push eax
-# 50 ?'
+ # b8 ?' # 3 ?. ; mov eax, 3
+ # 31 ?' # db ?' ; xor ebx, ebx
+ # b9 ?' _iobuf ?. ; mov ecx, _iobuf
+ # ba ?' # 1 ?. ; mov edx, 1
+ # cd ?' # 80 ?' ; int 0x80
+ # 31 ?' # db ?' ; xor ebx, ebx
+ # 8a ?' # 1d ?' _iobuf ?. ; mov bl, [_iobuf]
+ # 53 ?' ; push ebx
+ # 50 ?' ; push eax
next
defasm emit
-; pop eax
-# 58 ?'
-; mov [_io_buffer], al
-# a2 ?' _io_buffer ?.
-; mov eax, 4
-# b8 ?' # 4 ?.
-; mov ebx, 1
-# bb ?' # 1 ?.
-; mov ecx, _io_buffer
-# b9 ?' _io_buffer ?.
-; mov edx, 1
-# ba ?' # 1 ?.
-; int 0x80
-# cd ?' # 80 ?'
+ # 58 ?' ; pop eax
+ # a2 ?' _iobuf ?. ; mov [_iobuf], al
+ # b8 ?' # 4 ?. ; mov eax, 4
+ # bb ?' # 1 ?. ; mov ebx, 1
+ # b9 ?' _iobuf ?. ; mov ecx, _iobuf
+ # ba ?' # 1 ?. ; mov edx, 1
+ # cd ?' # 80 ?' ; int 0x80
next
diff --git a/main.sts b/main.sts
index 7cbca9f..89b8697 100644
--- a/main.sts
+++ b/main.sts
@@ -1,26 +1,24 @@
module ia32/elf/begin.sts
-defword myword
-key if
- emit
-fi
-drop
+defword keyecho
+ key if emit fi
+ drop
exit
-defarr my_array 3
-defvar my_variable
+defarr numstr 3
+defvar char
set_entry
-31 my_variable !
-my_variable @ emit
-32 my_array !
-33 my_array 1 + !
-34 my_array 2 + !
-my_array @ emit
-my_array 1 + @ emit
-my_array 2 + @ emit
-35 36 swap emit emit
-myword
+ 31 char !
+ char @ emit
+ 32 numstr !
+ 33 numstr 1 + !
+ 34 numstr 2 + !
+ numstr @ emit
+ numstr 1 + @ emit
+ numstr 2 + @ emit
+ 35 36 swap emit emit
+ keyecho
quit
module ia32/elf/end.sts