-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencode.asm
158 lines (126 loc) Β· 3.69 KB
/
encode.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
section .bss
char resb 1 ; allocate storage for char
section .data
lf db 0xa ; regular newline
phg db 240, 159, 171, 130 ; 200 ; People HugginG ; π«
sph db 240, 159, 146, 150 ; 50 ; SParkling Heart ; π
spk db 226, 156, 168 ; 10 ; SParKles ; β¨
pld db 240, 159, 165, 186 ; 5 ; PLeaDing ; π₯Ί
cma db 44 ; 1 ; CoMmA ; ,
hrt db 226, 157, 164, 239, 184, 143 ; 0 ; HeaRT ; β€οΈ
bsp db 240, 159, 145, 137, 240, 159, 145, 136 ; ; Byte SeParator ; ππ
section .text
global _start
_start:
; read stdin into buffer of size 1
mov edx, 1 ; max length
mov ecx, char ; buffer
mov ebx, 0 ; stdin
mov eax, 3 ; sys_read
int 0x80
; encode
cmp eax, 0 ; encode if length > 0
jg encode_entry
; add newline
mov edx, 1 ; length
mov ecx, lf ; buffer
mov ebx, 1 ; stdout
mov eax, 4 ; sys_write
int 0x80
; exit
mov eax, 1
mov ebx, 0
int 0x80
add_heart:
; write β€οΈ to stdout and continue to add_byte_separator
mov edx, 6 ; length
mov ecx, hrt ; buffer
mov ebx, 1 ; stdout
mov eax, 4 ; sys_write
int 0x80
add_byte_separator:
; write ππ to stdout and jmp back to main
mov edx, 8 ; length
mov ecx, bsp ; buffer
mov ebx, 1 ; stdout
mov eax, 4 ; sys_write
int 0x80
jmp _start
encode_entry:
; if (char == 0) { jmp add_heart } else { push buf; continue to loop }
mov eax, [char]
cmp eax, 0
je add_heart
loop:
mov eax, [char] ; copy char to eax
cmp eax, 200
jge over200
cmp eax, 50
jge over50
cmp eax, 10
jge over10
cmp eax, 5
jge over5
cmp eax, 1
jge over1
jmp add_byte_separator
over1:
; subtract char by 1
mov eax, [char] ; copy char to eax
dec eax
mov [char], eax ; copy char to eax
; write , to stdout
mov edx, 1 ; length
mov ecx, cma ; buffer
mov ebx, 1 ; stdout
mov eax, 4 ; sys_write
int 0x80
jmp loop
over5:
; subtract char by 5
mov eax, [char] ; copy char to eax
sub eax, 5
mov [char], eax ; copy char to eax
; write π₯Ί to stdout
mov edx, 4 ; length
mov ecx, pld ; buffer
mov ebx, 1 ; stdout
mov eax, 4 ; sys_write
int 0x80
jmp loop
over10:
; subtract char by 10
mov eax, [char] ; copy char to eax
sub eax, 10
mov [char], eax ; copy char to eax
; write β¨ to stdout
mov edx, 3 ; length
mov ecx, spk ; buffer
mov ebx, 1 ; stdout
mov eax, 4 ; sys_write
int 0x80
jmp loop
over50:
; subtract char by 50
mov eax, [char] ; copy char to eax
sub eax, 50
mov [char], eax ; copy char to eax
; write π to stdout
mov edx, 4 ; length
mov ecx, sph ; buffer
mov ebx, 1 ; stdout
mov eax, 4 ; sys_write
int 0x80
jmp loop
over200:
; subtract char by 200
mov eax, [char] ; copy char to eax
sub eax, 200
mov [char], eax ; copy char to eax
; write π« to stdout
mov edx, 4 ; length
mov ecx, phg ; buffer
mov ebx, 1 ; stdout
mov eax, 4 ; sys_write
int 0x80
jmp loop