Skip to content

Commit 086325a

Browse files
committed
First instruction has now also 0 as adress
+ Minor code style improvements
1 parent 9edb7c9 commit 086325a

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

js/flowchart.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function generateFlowChartCode() {
5757
code = `start=>start: Start\n`;
5858

5959
source.forEach((cmd, index) => {
60-
const line = index + 1;
60+
const line = index;
6161
let nodetype = 'operation';
6262

6363
if (cmd.startsWith('dec')) {
@@ -75,7 +75,7 @@ function generateFlowChartCode() {
7575

7676
code += `\nstart->node1\n`;
7777
source.forEach((cmd, index) => {
78-
const line = index + 1;
78+
const line = index;
7979

8080
if (cmd.startsWith('tst')) {
8181
code += `node${line}(yes)->node${line + 1}\n`;

js/simulator.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ function executeLine() {
6363
// setup pointer
6464
const pointer = document.getElementById('pointer');
6565

66+
<<<<<<< ours
6667
const content = code[line - 1];
68+
=======
69+
const content = code[line];
70+
>>>>>>> theirs
6771
const cmd = content.substring(0, 3);
6872
const param = parseInt(content.substring(3, content.length));
6973

@@ -74,7 +78,7 @@ function executeLine() {
7478
for (let i = 0; i < lines.length; i++) {
7579
const lineContent = lines[i];
7680
if (lineContent != '' && !lineContent.startsWith(';')) linesOfCode++; // check if this line is code
77-
if (linesOfCode == line) {
81+
if (linesOfCode-1 == line) {
7882
pointer.style.top = i * 20 - 4 + 'pt';
7983
break;
8084
}
@@ -84,11 +88,20 @@ function executeLine() {
8488
switch (cmd) {
8589
case 'jmp':
8690
line = param;
91+
<<<<<<< ours
8792
break;
93+
=======
94+
return
95+
>>>>>>> theirs
8896

8997
case 'tst':
90-
// If register doesnt exist or is null, skip next line
91-
if (registers[param] == null || registers[param] == 0) line++;
98+
checkRegisterCount(param);
99+
if (registers[param]==0)
100+
line++;
101+
if (registers[param] == null){
102+
line++;
103+
registers[param] = 0;
104+
}
92105
break;
93106

94107
case 'hlt':

0 commit comments

Comments
 (0)