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
/
Push_test.go
102 lines (96 loc) · 2.59 KB
/
Push_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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package asm_test
import (
"testing"
"github.com/akyoto/asm"
"github.com/akyoto/assert"
)
func TestPushRegister(t *testing.T) {
usagePatterns := []struct {
Register string
Code []byte
}{
{"rax", []byte{0x50}},
{"ax", []byte{0x66, 0x50}},
{"rcx", []byte{0x51}},
{"cx", []byte{0x66, 0x51}},
{"rdx", []byte{0x52}},
{"dx", []byte{0x66, 0x52}},
{"rbx", []byte{0x53}},
{"bx", []byte{0x66, 0x53}},
{"rsi", []byte{0x56}},
{"si", []byte{0x66, 0x56}},
{"rdi", []byte{0x57}},
{"di", []byte{0x66, 0x57}},
{"rsp", []byte{0x54}},
{"sp", []byte{0x66, 0x54}},
{"rbp", []byte{0x55}},
{"bp", []byte{0x66, 0x55}},
{"r8", []byte{0x41, 0x50}},
{"r8w", []byte{0x66, 0x41, 0x50}},
{"r9", []byte{0x41, 0x51}},
{"r9w", []byte{0x66, 0x41, 0x51}},
{"r10", []byte{0x41, 0x52}},
{"r10w", []byte{0x66, 0x41, 0x52}},
{"r11", []byte{0x41, 0x53}},
{"r11w", []byte{0x66, 0x41, 0x53}},
{"r12", []byte{0x41, 0x54}},
{"r12w", []byte{0x66, 0x41, 0x54}},
{"r13", []byte{0x41, 0x55}},
{"r13w", []byte{0x66, 0x41, 0x55}},
{"r14", []byte{0x41, 0x56}},
{"r14w", []byte{0x66, 0x41, 0x56}},
{"r15", []byte{0x41, 0x57}},
{"r15w", []byte{0x66, 0x41, 0x57}},
}
for _, pattern := range usagePatterns {
a := asm.New()
t.Logf("push %s", pattern.Register)
a.PushRegister(pattern.Register)
assert.DeepEqual(t, a.Code(), pattern.Code)
}
}
func TestPopRegister(t *testing.T) {
usagePatterns := []struct {
Register string
Code []byte
}{
{"rax", []byte{0x58}},
{"ax", []byte{0x66, 0x58}},
{"rcx", []byte{0x59}},
{"cx", []byte{0x66, 0x59}},
{"rdx", []byte{0x5a}},
{"dx", []byte{0x66, 0x5a}},
{"rbx", []byte{0x5b}},
{"bx", []byte{0x66, 0x5b}},
{"rsi", []byte{0x5e}},
{"si", []byte{0x66, 0x5e}},
{"rdi", []byte{0x5f}},
{"di", []byte{0x66, 0x5f}},
{"rsp", []byte{0x5c}},
{"sp", []byte{0x66, 0x5c}},
{"rbp", []byte{0x5d}},
{"bp", []byte{0x66, 0x5d}},
{"r8", []byte{0x41, 0x58}},
{"r8w", []byte{0x66, 0x41, 0x58}},
{"r9", []byte{0x41, 0x59}},
{"r9w", []byte{0x66, 0x41, 0x59}},
{"r10", []byte{0x41, 0x5a}},
{"r10w", []byte{0x66, 0x41, 0x5a}},
{"r11", []byte{0x41, 0x5b}},
{"r11w", []byte{0x66, 0x41, 0x5b}},
{"r12", []byte{0x41, 0x5c}},
{"r12w", []byte{0x66, 0x41, 0x5c}},
{"r13", []byte{0x41, 0x5d}},
{"r13w", []byte{0x66, 0x41, 0x5d}},
{"r14", []byte{0x41, 0x5e}},
{"r14w", []byte{0x66, 0x41, 0x5e}},
{"r15", []byte{0x41, 0x5f}},
{"r15w", []byte{0x66, 0x41, 0x5f}},
}
for _, pattern := range usagePatterns {
a := asm.New()
t.Logf("pop %s", pattern.Register)
a.PopRegister(pattern.Register)
assert.DeepEqual(t, a.Code(), pattern.Code)
}
}