This repository has been archived by the owner on Jul 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Div_test.go
83 lines (79 loc) · 2.53 KB
/
Div_test.go
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
package asm_test
import (
"testing"
"github.com/akyoto/asm"
"github.com/akyoto/assert"
)
func TestDivRegister(t *testing.T) {
usagePatterns := []struct {
Register string
Code []byte
}{
{"rax", []byte{0x48, 0xf7, 0xf8}},
{"eax", []byte{0xf7, 0xf8}},
{"ax", []byte{0x66, 0xf7, 0xf8}},
{"al", []byte{0xf6, 0xf8}},
{"rcx", []byte{0x48, 0xf7, 0xf9}},
{"ecx", []byte{0xf7, 0xf9}},
{"cx", []byte{0x66, 0xf7, 0xf9}},
{"cl", []byte{0xf6, 0xf9}},
{"rdx", []byte{0x48, 0xf7, 0xfa}},
{"edx", []byte{0xf7, 0xfa}},
{"dx", []byte{0x66, 0xf7, 0xfa}},
{"dl", []byte{0xf6, 0xfa}},
{"rbx", []byte{0x48, 0xf7, 0xfb}},
{"ebx", []byte{0xf7, 0xfb}},
{"bx", []byte{0x66, 0xf7, 0xfb}},
{"bl", []byte{0xf6, 0xfb}},
{"rsi", []byte{0x48, 0xf7, 0xfe}},
{"esi", []byte{0xf7, 0xfe}},
{"si", []byte{0x66, 0xf7, 0xfe}},
{"rdi", []byte{0x48, 0xf7, 0xff}},
{"edi", []byte{0xf7, 0xff}},
{"di", []byte{0x66, 0xf7, 0xff}},
{"rsp", []byte{0x48, 0xf7, 0xfc}},
{"esp", []byte{0xf7, 0xfc}},
{"sp", []byte{0x66, 0xf7, 0xfc}},
{"rbp", []byte{0x48, 0xf7, 0xfd}},
{"ebp", []byte{0xf7, 0xfd}},
{"bp", []byte{0x66, 0xf7, 0xfd}},
{"r8", []byte{0x49, 0xf7, 0xf8}},
{"r8d", []byte{0x41, 0xf7, 0xf8}},
{"r8w", []byte{0x66, 0x41, 0xf7, 0xf8}},
{"r8b", []byte{0x41, 0xf6, 0xf8}},
{"r9", []byte{0x49, 0xf7, 0xf9}},
{"r9d", []byte{0x41, 0xf7, 0xf9}},
{"r9w", []byte{0x66, 0x41, 0xf7, 0xf9}},
{"r9b", []byte{0x41, 0xf6, 0xf9}},
{"r10", []byte{0x49, 0xf7, 0xfa}},
{"r10d", []byte{0x41, 0xf7, 0xfa}},
{"r10w", []byte{0x66, 0x41, 0xf7, 0xfa}},
{"r10b", []byte{0x41, 0xf6, 0xfa}},
{"r11", []byte{0x49, 0xf7, 0xfb}},
{"r11d", []byte{0x41, 0xf7, 0xfb}},
{"r11w", []byte{0x66, 0x41, 0xf7, 0xfb}},
{"r11b", []byte{0x41, 0xf6, 0xfb}},
{"r12", []byte{0x49, 0xf7, 0xfc}},
{"r12d", []byte{0x41, 0xf7, 0xfc}},
{"r12w", []byte{0x66, 0x41, 0xf7, 0xfc}},
{"r12b", []byte{0x41, 0xf6, 0xfc}},
{"r13", []byte{0x49, 0xf7, 0xfd}},
{"r13d", []byte{0x41, 0xf7, 0xfd}},
{"r13w", []byte{0x66, 0x41, 0xf7, 0xfd}},
{"r13b", []byte{0x41, 0xf6, 0xfd}},
{"r14", []byte{0x49, 0xf7, 0xfe}},
{"r14d", []byte{0x41, 0xf7, 0xfe}},
{"r14w", []byte{0x66, 0x41, 0xf7, 0xfe}},
{"r14b", []byte{0x41, 0xf6, 0xfe}},
{"r15", []byte{0x49, 0xf7, 0xff}},
{"r15d", []byte{0x41, 0xf7, 0xff}},
{"r15w", []byte{0x66, 0x41, 0xf7, 0xff}},
{"r15b", []byte{0x41, 0xf6, 0xff}},
}
for _, pattern := range usagePatterns {
a := asm.New()
t.Logf("idiv %s", pattern.Register)
a.DivRegister(pattern.Register)
assert.DeepEqual(t, a.Code(), pattern.Code)
}
}