-
Notifications
You must be signed in to change notification settings - Fork 0
/
colours.asm
114 lines (87 loc) · 2.81 KB
/
colours.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
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
jmp start
; x86 Assembly Implementation
_customColourTextToInt:
push ebp
mov ebp, esp
sub esp, 16
mov dword ptr [ebp-4], 0 ; int red
mov dword ptr [ebp-8], 0 ; int green
mov dword ptr [ebp-12], 0 ; int blue
mov dword ptr [ebp-16], 0 ; int alpha
mov ecx, [ebp+8] ; ecx = text
xor ebx, ebx ; get red byte...
mov bl, byte ptr [ecx+3]
push ebx
call _colourDigitToByte
mov dword ptr [ebp-4], eax
xor ebx, ebx ; get green byte...
mov bl, byte ptr [ecx+4]
push ebx
call _colourDigitToByte
mov dword ptr [ebp-8], eax
xor ebx, ebx ; get blue byte...
mov bl, byte ptr [ecx+5]
push ebx
call _colourDigitToByte
mov dword ptr [ebp-12], eax
xor ebx, ebx ; get alpha byte...
mov bl, byte ptr [ecx+6]
push ebx
call _colourDigitToByte
mov dword ptr [ebp-16], eax
mov eax, dword ptr [ebp-16] ; argb = alpha
mov ebx, eax ; t = argb
shl ebx, 8 ; t <<= 8
add ebx, dword ptr [ebp-4] ; t += red
mov eax, ebx ; argb = t
mov ebx, eax ; t = argb
shl ebx, 8 ; t <<= 8
add ebx, dword ptr [ebp-8] ; t += green
mov eax, ebx ; argb = t
mov ebx, eax ; t = argb
shl ebx, 8 ; t <<= 8
add ebx, dword ptr [ebp-12] ; t += blue
mov eax, ebx ; argb = t
add esp, 16
pop ebp
ret 4
_colourDigitToByte:
push ebp
mov ebp, esp
sub esp, 12
mov dword ptr [ebp-4], 0xF ; int maxTypedValue = 0xF
mov dword ptr [ebp-8], 0xFF ; int maxEncodedValue = 0xFF
mov dword ptr [ebp-12], 0 ; DWORD temp
mov ebx, dword ptr [ebp+8] ; char ebx = typedValue
cmp ebx, 'a' ; if (ebx >= 'a') {
jge isLowerCaseHex ; treat as lowercase hex
cmp ebx, 'A' ; } else if (ebx >= 'A') {
jge isUpperCaseHex ; treat as uppercase hex
; } else {
jmp isDecimal ; treat as decimal
; }
isLowerCaseHex:
sub ebx, 'a' ; ebx = 10 + (ebx - 'a')
add ebx, 10
jmp done
isUpperCaseHex:
sub ebx, 'A' ; ebx = 10 + (ebx - 'A')
add ebx, 10
jmp done
isDecimal:
sub ebx, '0' ; ebx = ebx - '0'
jmp done
done:
mov dword ptr [ebp+8], ebx
finit
fild dword ptr [ebp+8] ; fpu <- typedValue
fidiv dword ptr [ebp-4] ; st(0) /= maxTypedValue
fimul dword ptr [ebp-8] ; st(0) *= maxEncodedValue;
fisttp dword ptr [ebp-12] ; fpu -> temp
mov eax, dword ptr [ebp-12] ; return temp
add esp, 12
pop ebp
ret 4
start:
push text
call _customColourTextToInt