Skip to content

Commit

Permalink
Merge pull request #150 from shattered/_734bbeb8
Browse files Browse the repository at this point in the history
cowasm: fix SOB insn on pdp11
  • Loading branch information
davidgiven authored Jun 2, 2024
2 parents 2f7fd7f + 0d1fdd5 commit 5f51a2c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/cowasm/archpdp11.cow
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ sub ReadOperand(): (token: Token) is
end if;
end case;

# FIXME @(reg) is @0(reg), not (reg)
if deferred != 0 then
addressingMode := addressingMode | AM__DEREF;
end if;
Expand Down Expand Up @@ -253,24 +254,24 @@ sub SobCb implements SymbolCallback is
if (addressingMode & 0o370) != AM_REG then
SimpleError("first parameter must be a register");
end if;
var param1addressingMode := addressingMode;
var param1addressingMode := (addressingMode & 0o07) as uint16 << 6;
ExpectExpression();

if pass == 1 then
[currentProgramCounter] := [currentProgramCounter] + 8;
else
var delta := (tokenNumber - [currentProgramCounter] - 2) as int16;
if (delta >= -256) and (delta <= 0) then
EmitWord(currentInsn.value | (((-delta as uint16) >> 1) & 0o77));
EmitWord(currentInsn.value | param1addressingMode | (((-delta as uint16) >> 1) & 0o77));
elseif (delta >= -128) and (delta <= 126) then
EmitWord(0o000401);
EmitWord(0o000400 | (((delta as uint16) >> 1) & 0o77));
EmitWord((currentInsn.value ^ 0o400) | 2);
EmitWord((currentInsn.value ^ 0o400) | param1addressingMode | 2);
else
EmitWord(0o000402);
EmitWord(0o000167);
EmitWord(tokenNumber - [currentProgramCounter] - 2);
EmitWord((currentInsn.value ^ 0o400) | 3);
EmitWord((currentInsn.value ^ 0o400) | param1addressingMode | 3);
end if;
end if;
end sub;
Expand Down Expand Up @@ -402,6 +403,8 @@ end sub;
{ "CLZ", 0o000244, SimpleCb, &s },
{ "CLN", 0o000250, SimpleCb, &s },

{ "NOP", 0o000240, SimpleCb, &s },

{ "BR", 0o000400, BrCb, &s },
{ "BNE", 0o001000, CondCb, &s },
{ "BEQ", 0o001400, CondCb, &s },
Expand Down

0 comments on commit 5f51a2c

Please sign in to comment.