-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcode.asm
83 lines (71 loc) · 1.14 KB
/
code.asm
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
%define REG(r) [REGS + r * 4]
%define PTR(p) [MEM + p]
U5_LE:
mov ecx, 0x200
mov edi, MEM
mov esi, DISK
rep movsb
SPIN:
mov edx, REG(63)
mov edx, PTR(edx)
add WORD REG(63), 4
mov WORD REG(0), 0
mov ebp, edx
shr ebp, 21
and ebp, 77o
mov esi, edx
shr esi, 15
and esi, 77o
mov edi, edx
shr edi, 9
and edi, 77o
mov eax, edx
shr eax, 27
mov eax, [OP_TABLE + eax * 4]
jmp eax
OP_TABLE:
dd OP_LOAD_B, OP_LOAD_H, OP_LOAD_W, 0, OP_STORE_B, OP_STORE_H, OP_STORE_W, \
0, OP_ADD, OP_MUL, OP_DIV, OP_NOR, 0, 0, 0, 0, OP_MOVI, 0, OP_CMOV, 0, 0, \
0, 0, 0, OP_IN, OP_OUT, OP_READ, OP_WRITE, 0, 0, 0, OP_HALT
OP_LOAD_W:
mov eax, REG(esi)
add eax, REG(edi)
mov eax, PTR(eax)
mov REG(ebp), eax
jmp SPIN
OP_MUL:
mov eax, REG(esi)
mul DWORD REG(edi)
mov REG(ebp), eax
jmp SPIN
OP_MOVI:
mov eax, edx
mov ecx, edx
shr eax, 5
and eax, 0xffff
and ecx, 37o
shl eax, cl
mov REG(ebp), eax
jmp SPIN
OP_CMOV:
mov eax, REG(edi)
test eax, eax
jz .F
mov eax, REG(esi)
mov REG(ebp), eax
.F:
jmp SPIN
OP_OUT:
push DWORD REG(ebp)
call putchar
add esp, 4
jmp SPIN
OP_READ:
mov ecx, 0x200
mov esi, REG(esi)
shl esi, 9
lea esi, [DISK + esi]
mov edi, REG(ebp)
lea edi, PTR(edi)
rep movsb
jmp SPIN