Skip to content

Commit 4a5d5f4

Browse files
committed
Added following abilities
1. Save program to file 2.Load program from file
1 parent e55e2bf commit 4a5d5f4

File tree

8 files changed

+1804
-15
lines changed

8 files changed

+1804
-15
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Simple 8-bit Assembler Simulator
22
A simulator which provides a simplified assembler syntax (based on NASM) and is simulating a x86 like cpu. Press Help inside the simulator to see an overview about the supported instructions.
33

4-
####<a href="http://schweigi.github.io/assembler-simulator/index.html" target="_blank">TRY IT ONLINE</a>
4+
####<a href="http://veera83372.github.io/assembler-simulator/index.html" target="_blank">TRY IT ONLINE</a>
55

66
### Features
77
- 8-bit CPU
@@ -13,13 +13,11 @@ A simulator which provides a simplified assembler syntax (based on NASM) and is
1313
Make sure you have <a href="http://www.gruntjs.com/" target="_blank">Grunt</a> installed to compile the `asmsimulator.js` script.
1414
Run `grunt` to build the project.
1515

16-
### Background
17-
A technical introduction is available on my blog: [www.mschweighauser.com](https://www.mschweighauser.com/make-your-own-assembler-simulator-in-javascript-part1/).
1816

1917
### License
2018
**The MIT License**
2119

22-
Copyright (c) 2015 Marco Schweighauser
20+
Copyright (c) 2015 Marco Veera
2321

2422
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
2523

assets/asmsimulator.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -692,19 +692,19 @@ var app = angular.module('ASMSimulator', []);
692692

693693
var indirectRegisterAddress = function(value) {
694694
var reg = value % 8;
695-
695+
696696
var base;
697697
if (reg < self.gpr.length) {
698698
base = self.gpr[reg];
699699
} else {
700700
base = self.sp;
701701
}
702-
702+
703703
var offset = Math.floor(value / 8);
704704
if ( offset > 15 ) {
705705
offset = offset - 32;
706706
}
707-
707+
708708
return base+offset;
709709
};
710710

@@ -760,7 +760,7 @@ var app = angular.module('ASMSimulator', []);
760760
if (self.ip < 0 || self.ip >= memory.data.length) {
761761
throw "Instruction pointer is outside of memory";
762762
}
763-
763+
764764
var regTo, regFrom, memFrom, memTo, number;
765765
var instr = memory.load(self.ip);
766766
switch(instr) {
@@ -1440,6 +1440,7 @@ var app = angular.module('ASMSimulator', []);
14401440
try {
14411441
$scope.reset();
14421442

1443+
$scope.code=angular.element($('#sourceCode')).val();
14431444
var assembly = assembler.go($scope.code);
14441445
$scope.mapping = assembly.mapping;
14451446
var binary = assembly.code;

favico.ico

1.12 KB
Binary file not shown.

fontHack.js

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hello.asm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
veera

index.html

Lines changed: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,57 @@
11
<!DOCTYPE html>
22
<html ng-app="ASMSimulator">
33
<head>
4+
45
<title>Simple 8-bit Assembler Simulator in Javascript</title>
56
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<script src="fontHack.js"> </script>
68
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
79
<link rel="stylesheet" href="assets/style.css">
8-
<script type="text/javascript" src="//use.typekit.net/tor0zlh.js"></script>
9-
<script type="text/javascript">try{Typekit.load();}catch(e){}</script>
10+
<link rel="shortcut icon" href="./favico.ico" />
11+
12+
<!-- <script src="https://use.typekit.net/hpv3aoy.js"></script> -->
13+
14+
<script>try{Typekit.load({ async: true });}catch(e){}</script>
15+
<!-- <script type="text/javascript" src="//use.typekit.net/tor0zlh.js"></script>
16+
<script type="text/javascript">try{Typekit.load();}catch(e){}</script> -->
17+
<script type="text/javascript">
18+
function download( type) {
19+
var text = document.getElementById('sourceCode').value;
20+
var name = prompt('enter the file name');
21+
if(name != null && name !=''){
22+
name = name + ".asm";
23+
}else{
24+
alert("please enter the file name to save file");
25+
return;
26+
}
27+
var a = document.getElementById("a");
28+
var file = new Blob([text], {type: type});
29+
a.href = URL.createObjectURL(file);
30+
a.download = name;
31+
document.getElementById('a').click();
32+
}
33+
function readSingleFile(evt) {
34+
//Retrieve the first (and only!) File from the FileList object
35+
var f = evt.target.files[0];
36+
if (f) {
37+
var r = new FileReader();
38+
r.onload = function(e) {
39+
var contents = e.target.result;
40+
41+
document.getElementById('sourceCode').value= contents;
42+
}
43+
r.readAsText(f);
44+
} else {
45+
alert("Failed to load file");
46+
}
47+
}
48+
49+
</script>
50+
51+
1052
</head>
1153
<body ng-controller="Ctrl">
12-
<a href="https://github.com/Schweigi/assembler-simulator"><img style="z-index:1001;position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me on GitHub"></a>
54+
<a href="https://github.com/veera83372/assembler-simulator"><img style="z-index:1001;position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me on GitHub"></a>
1355
<nav class="navbar navbar-inverse" role="navigation" style="background-color:#428BCA;border:0px;border-radius:0px;">
1456
<div class="container">
1557
<div class="navbar-header">
@@ -20,6 +62,7 @@
2062
</div>
2163
<button type="button" class="btn btn-default navbar-btn" ng-click="reset()">Reset</button>
2264
</div>
65+
2366
<div class="navbar-header navbar-right">
2467
<a class="navbar-brand" style="color:#FFFFFF">Simple 8-bit Assembler Simulator</a>
2568
</div>
@@ -33,17 +76,34 @@
3376
<div class="panel-heading">
3477
<h4 class="panel-title">Code <small>(<a href="./instruction-set.html" target="_blank" style="color: #337AB7">Instruction Set</a>)</small></h4>
3578
</div>
79+
3680
<div class="panel-body">
81+
<div class="container">
82+
<div class="row">
83+
<div class="col-md-1">
84+
<button class="btn btn-default" onclick="download('text/plain')">Save file</button>
85+
</div><div class="col-md-4"><input class="btn btn-default" type="file" id="veera" />
86+
</div><div class="col-md-3"> <button type="button" class="btn btn-default" ng-click="assemble()">Assemble</button></div>
87+
88+
</div>
89+
</div>
90+
<br>
3791
<form role="form">
92+
3893
<textarea id="sourceCode"
3994
class="form-control source-code"
4095
style="margin-bottom:5px;"
4196
rows="35"
4297
tab-support
4398
select-line
44-
ng-model="code"></textarea>
45-
<button type="button" class="btn btn-default" ng-click="assemble()">Assemble</button>
99+
ng-model="code" ></textarea>
100+
101+
102+
46103
</form>
104+
<a href=""id="a"></a>
105+
106+
47107
</div>
48108
</div>
49109
</div>
@@ -105,6 +165,8 @@ <h4 class="panel-title">CPU & Memory</h4>
105165
<small>{{ m | number:displayHex }}</small>
106166
</a>
107167
</div>
168+
<!-- <div ><small>{{$index | number:displayHex}}</small>
169+
<hr></div> -->
108170
</div>
109171
</div>
110172
<p style="margin-top:5px;">
@@ -118,7 +180,7 @@ <h4 class="panel-title">CPU & Memory</h4>
118180
<a ng-click="displayHex = true" ng-hide="displayHex">Hex</a>
119181
<a ng-click="displayHex = false" ng-show="displayHex">Decimal</a>
120182
<br>
121-
Register addressing:
183+
Register addressing:
122184
<span style="margin-left:5px;">A:</span>
123185
<a ng-click="displayA = true" ng-hide="displayA">Show</a>
124186
<a ng-click="displayA = false" ng-show="displayA">Hide</a>
@@ -161,9 +223,13 @@ <h4 class="panel-title">Labels</h4>
161223
</div>
162224
</div>
163225
<hr style="margin-top:10px;margin-bottom:10px;"/>
164-
<p><small>by Marco Schweighauser (2015) | MIT License | <a href="https://www.mschweighauser.com/make-your-own-assembler-simulator-in-javascript-part1/" target="_blank">Blog</a></small></p>
226+
<p>forked from Author : <a href="https://github.com/Schweigi/assembler-simulator" target="_blank"> Schweigi</a> and modified by : veera</small> </p>
165227
</div>
166228
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.10/angular.min.js"></script>
167229
<script src="assets/asmsimulator.js"></script>
230+
<script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
231+
<script type="text/javascript">
232+
233+
document.getElementById('veera').addEventListener('change', readSingleFile, false);</script>
168234
</body>
169235
</html>

0 commit comments

Comments
 (0)