-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint.xt
More file actions
176 lines (153 loc) · 3.17 KB
/
print.xt
File metadata and controls
176 lines (153 loc) · 3.17 KB
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
var a = 0;
var MSIZE = 0;
var MMEM = 0;
var STR_LENGTH = 0;
var STR_POINTER = 0;
var k = 505 % 10;
var TYPE_INT = 1;
var TYPE_FLOAT = 2;
var TYPE_STRING = 3;
var TYPE_REF = 4;
function memalloc(size)
{
MSIZE = size;
asm(["mov eax , [MSIZE]",
"mov ecx , eax",
"call malloc",
"mov bl , [REF_TYPE]",
"movzx bx , bl",
"mov [MMEM] , bx",
"mov [MMEM + 1] , eax",
]);
return MMEM;
}
function print_int(x)
{
var temp = x;
var buffer_size = 12;
var buffer = memalloc(buffer_size);
var temp_buffer = buffer;
x;
if (x == 0)
{
@temp_buffer = 48;
temp_buffer++;
@temp_buffer = 0;
return buffer;
}
var ch = 0;
var length = 0;
while (temp > 0)
{
length++;
ch = 0;
ch = temp % 10;
ch = ch + 48;
@temp_buffer = ch;
temp_buffer++;
temp = temp / 10;
}
var string_number = memalloc(buffer_size);
buffer = string_number;
while (length >= 0)
{
ch = @temp_buffer;
ch = ch & 0xFF;
@string_number = ch;
string_number++;
temp_buffer--;
length--;
}
@string_number = 0;
return buffer;
}
function print(x)
{
var t = typeof(x);
if (typeof(x) == 1)
{
var buffer = print_int(x);
STR_LENGTH = 10;
STR_POINTER = buffer;
asm(["mov ecx , [STR_POINTER + 1 ] ;; file str pointer",
"mov edx , [STR_LENGTH + 1] ;; str length",
"mov eax, 4 ",
"mov ebx, 1 ; file descriptor 1 (stdout)",
"int 0x80 ; make syscall to write",
]);
return;
}
var length = 0;
var temp = x;
var maxBuffer = 1024;
var buffer = memalloc(maxBuffer);
var tempBuffer = buffer;
var ch = 0;
ch = @temp;
ch = ch & 0xFF;
var z = 10;
while (ch != 0)
{
ch = @temp;
ch = ch & 0xFF;
// asm(["pop eax" ,"pop bx" , "call print_eax"]);
if (ch == 92)
{
// 92 is ASCII for '/' character
temp++;
ch = @temp;
ch = ch & 0xFF;
if (ch == 110)
{
// 110 is ASCII for 'n'
ch = 10; // 10 is ASCII for new line
}
if (ch == 116)
{
// 116 is ASCII for 't'
ch = 9; // 9 is ASSCII for tab
}
}
// if(ch == )
@tempBuffer = ch;
temp++;
tempBuffer++;
length++;
}
STR_LENGTH = length;
STR_POINTER = buffer;
asm(["mov ecx , [STR_POINTER + 1 ] ;; file str pointer",
"mov edx , [STR_LENGTH + 1] ;; str length",
"mov eax, 4 ",
"mov ebx, 1 ; file descriptor 1 (stdout)",
"int 0x80 ; make syscall to write",
]);
}
function print_series(x)
{
var i = x;
var k = 0;
while (i > 0)
{
if (i % 2 == 0)
{
i--;
continue;
}
print(i);
print("\n");
i--;
if (i < 10)
{
return;
}
}
print("nice");
}
var msg = " hello\t world \n";
print(msg);
var i = 12345;
print(i);
print("\n");
i = 50;
print_series(i);