-
Notifications
You must be signed in to change notification settings - Fork 0
/
specification.txt
137 lines (117 loc) · 4.33 KB
/
specification.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
bits numeration:
most significant bit - 0
instruction structure:
op [arg, ...]
operation structure:
size: 1 byte
0b00000000
bits:
0 - 2 => args count
2 => is using indirect addressing (if 1 it interprets last argument as address of value rather than value itself)
3 - 8 => opcode
preprocessor directive structure:
keyword [arg, ...]
preprocessor keywords:
db [value, ...]: define bytes
dw [value, ...]: define words
resb [count]: reserve given amount of bytes
resw [count]: reserve given amount of words
const [name type value]: define constant
types:
byte - 8 bits
word - 16 bits
address size: word
reserved address values:
0x0 -> accumulator
0x2 -> base register
0x4 -> count register
0x6 -> data register
0x8 -> stack pointer
0xa -> stack base pointer
0xc -> flags register
0xe - 0x40e -> stack (1 kb)
note that these values doesn't mean actual memory locations (except the stack)
but are used to index internal processor registers
base program address: 0x40f (just after end of stack)
address wildcard keyword: $
expands to the address of used instruction
example:
0x00 jmp $ is the same as
0x00 jmp 0x00
value at address keyword: [address]
expands to the value found at given address
example:
0x00 "h"
0x01 mov eax, [0x00] is the same as
0x00 "h"
0x01 mov eax, "h"
label structure:
.[label_name]
expands to address of instruction found right after the label
argument structure:
[type, value]
value structure:
0b00...
bits:
0 => is value or address (1 if value) (corelated with value at address keyword)
1 => argument type (0 for byte, 1 for word)
2 - n => value
in some cases specifying the type of argument is pointless as it will always use specific type
example:
0x0 jmp byte 0x6 ;argument will always be word size, even though we request it to be byte size
comment structure:
;[comment]
register size: word (except of flags register)
note: flags register cannot be accessed directly
it can be done only via pushf
registers literals:
ax - acummulator
bx - base register
cx - count register
dx - data register
sp - stack pointer register
bp - stack base pointer register
x replacements:
l - register's lower byte
h - register's higher byte
flags register structure:
0b00000000 (byte)
bits:
0 => zero flag (set if operation result is 0)
1 => sign flag (set if operation result is negative)
2 => parity flag (set if operation result is a multiple of 2)
3 => carry flag (set if addition result overflows register or subtraction result is negative)
4 => interruption flag (set if interrupts are enabled)
5 => overflow flag (set if operation overflows register)
6 => stack overflow flag (set if push* operation causes stack overflow)
7 => stack underflow flag (set if pop* operation causes stack underflow)
operations list:
add - add and store in ax, args: [register or value, register or value]
adc - add with carry and store in ax, args: same as add
div - divide and store in ax, args: same as adc
mul - multiply and store in ax, args: same as div
sub - subtract and store in ax, args: same as mul
sbb - subtract with borrow and store in ax, args: same as sub
and - logical AND ax with value and store in ax, args: [value]
or - logical OR ax with value and store in ax, same as and
xor - logical XOR ax with value and store in ax, same as or
sl - shift ax left and store in ax, args: same as xor
sr - shift ax right and store in ax, args: same as sl
not - logical NOT of ax and store in ax, args: None
call - call procedure and put address of next instruction on stack, args: [procedure address]
ret - return from procedure and pop address of next instruction after call from stack, args: None
sys - call a syscall, args: [syscall index]
inc - increment by one, args: [register]
dec - decrement by one, args: [register]
hlt - stop processor, args: None
int - call interupt, args: [interrupt index]
jmp - jump to address, args [address]
jeq - jump to address if zero flag set, args: same as jmp
jne - jump to address if zero flag not set, args: same as jeq
mov - move address to certain location to another, args: [register or memory address, register or memory address]
nop - no operation, args: None
pop - pop data from stack, args: [number of bytes to pop]
push - push data onto stack, args: [value]
pushf - push flags register onto stack, args: None
popf - pop flags register from stack, args: None
test - logical AND and set zero flag if not equal, args: [value or register, value or register]