-
Notifications
You must be signed in to change notification settings - Fork 43
/
index.html
executable file
·145 lines (129 loc) · 3.26 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<title>y86 Simulator</title>
<style>
body {
font: 12px Helvetica, Arial, Sans;
}
h1, p {
padding: 0% 1%;
}
.buttons {
text-align: center;
}
.col3 {
font-weight: bold;
float: left;
padding: 1%;
}
.code {
font-size: 12px;
font-family: monospace;
width: 100%;
height: 320px;
overflow: auto;
}
.info { height: auto; }
.left { text-align: left; }
.center { text-align: center; }
.right { text-align: right; }
</style>
</head>
<body>
<h1>y86 Simulator</h1>
<p>Start coding and click assemble or copy/paste your object file to assembled and hit execute.</p>
<div class='buttons'>
<button id="assem" class="btn btn-primary">Assemble</button>
<button id="exec" class="btn">Execute</button>
<button id="assemexec" class="btn">Assemble + Execute</button>
</div>
<div class="col3" style="width: 36%">
<textarea id="y86" class="code"># Execution begins at address 0
.pos 0
init: irmovl Stack, %esp # Setup stack pointer
irmovl Stack, %ebp # Set up base pointer
call Main # Execute main program
halt # Terminate program
# Array of 4 elements
.align 4
array: .long 0xd
.long 0xc0
.long 0xb00
.long 0xa000
Main: pushl %ebp
rrmovl %esp,%ebp
irmovl $4,%eax
pushl %eax # Push 4
irmovl array,%edx
pushl %edx # Push array
call Sum # Sum(array, 4)
rrmovl %ebp,%esp
popl %ebp
ret
# int Sum(int *Start, int Count)
Sum: pushl %ebp
rrmovl %esp,%ebp
mrmovl 8(%ebp),%ecx # ecx = Start
mrmovl 12(%ebp),%edx # edx = Count
xorl %eax,%eax # sum = 0
andl %edx,%edx # Set condition codes
je End
Loop: mrmovl (%ecx),%esi # get *Start
addl %esi,%eax # add to sum
irmovl $4,%ebx #
addl %ebx,%ecx # Start++
irmovl $-1,%ebx #
addl %ebx,%edx # Count--
jne Loop # Stop when 0
End: rrmovl %ebp,%esp
popl %ebp
ret
# The stack starts here and grows to lower addresses
.pos 0x100
Stack:</textarea> Code
</div>
<div class="col3 center" style="width: 42%">
<textarea id='assembled' class='code'></textarea> Assembled
</div>
<div class="col3 right" style="width: 16%">
<textarea id='result' class='code'></textarea> Result
</div>
<p> </p>
<div class="center"> By Victor Aguilar |
<script>
var e = [118, 105, 99, 116, 111, 114, 97, 103, 117, 105, 108, 97, 114, 57, 48, 32, 123, 97, 116, 125, 32, 103, 109, 97, 105, 108, 32, 99, 111, 109], r = '';
for (c in e) {
r += String.fromCharCode(e[c]);
}
document.write(r);
</script>
<p> </p>
<a href="http://y86tutoring.wordpress.com/y86-ia/">Instruction Set</a> | <a href="http://github.com/vaguilar/js-y86/">View on Github</a>
</div>
<script src="y86.js"></script>
<script src="assem.js"></script>
<script src="instr.js"></script>
<script src="general.js"></script>
<script src="syntax.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
//Assemble when button is clicked
$('#assem').click(function(){
var assembled = ASSEMBLE($('#y86').val());
$('#assembled').val(assembled);
});
$('#exec').click(function(){
var result = toByteArray($('#assembled').val()),
registers = '';
result = EXECUTE(result);
registers = reg2str(REG);
$('#result').val(registers + '\n' + result);
});
$('#assemexec').click(function(){
$('#assem').click();
$('#exec').click();
});
</script>
</body>
</html>