Negative Immediate operands
Closed this issue · 1 comments
sueyllam commented
Well I made a modification that I hope you will find useful. Nothing in the SIC specifications says that immediate operands have to be +ve, so I decided to allow operands such as #-4 to be written in format 3 or format 4 immediate modes in 2's complement and be interpreted that way too.
Actually all SIC simulators/assemblers I came across made that assumption and I am not sure why?
The modification is fairly simple and involves only 4 functions in one file. Here it is:
File: "src\sic\common"
public int operandF3(int a, int b) {
// 12-bit address
if (isImmediate())
if (((a & 0x0F) & 0x8)==8)
return ((a & 0x0F) << 8 | b) | 0xFFFFF000;
return (a & 0x0F) << 8 | b;
}
public int operandF4(int a, int b, int c) {
// 20-bit address
if (isImmediate())
if (((a & 0x0F) & 0x8)==8)
return ((a & 0x0F) << 16 | b << 8 | c) | 0xFFF00000;
return (a & 0x0F) << 16 | b << 8 | c;
}
public int minOperand() {
if (isExtended() && ! isImmediate()) return SICXE.MIN_ADDR;
else if (isExtended() && isImmediate()) return -524288;
else return isImmediate() ? SICXE.MIN_SDISP : SICXE.MIN_DISP;
}
public int maxOperand() {
if (isExtended() && ! isImmediate()) return SICXE.MAX_ADDR;
else if (isExtended() && isImmediate()) return 524287;
else return isImmediate() ? SICXE.MAX_SDISP : SICXE.MAX_DISP;
}
sueyllam commented
OOps! I forgot the file name: Flags.java in the designated path