Permalink
Browse files

fix label replacement when assembling JR instructions

  • Loading branch information...
1 parent 2cb4d41 commit d10a8dac581aa84025ab8df764dbd58af60693a5 @izuzak committed Jun 13, 2012
Showing with 17 additions and 6 deletions.
  1. +9 −3 friscasm.js
  2. +8 −3 friscasm.pegjs
View
Oops, something went wrong.
View
@@ -286,13 +286,14 @@ instructions_main
}
}
- function replaceLabel(element) {
+ function replaceLabel(element, baseValueForDiff) {
if (element.type === "label") {
var labelValue = labels[element.value];
if (typeof labelValue !== "undefined") {
element.type = "num";
- element.value = labelValue;
+ element.value = (typeof baseValueForDiff === 'undefined') ?
+ labelValue : (labelValue - baseValueForDiff);
} else {
unknownlabels.push(element.value);
element.value = null;
@@ -305,7 +306,11 @@ instructions_main
if (instrs[i].op in aluops || instrs[i].op in cmpops || instrs[i].op in moveops) {
replaceLabel(instrs[i].alusrc2);
} else if (instrs[i].op in jmpops) {
- replaceLabel(instrs[i].addr);
+ if (instrs[i].op === "JR") {
+ replaceLabel(instrs[i].addr, instrs[i].curloc);
+ } else {
+ replaceLabel(instrs[i].addr);
+ }
} else if (instrs[i].op in memops) {
replaceLabel(instrs[i].mem);
} else if (instrs[i].op in dwhbops) {

0 comments on commit d10a8da

Please sign in to comment.