function str = instr2string_ass(b1, b2)
%INSTR2STRING_ASS returns string representation of instruction
% STR = INSTR2STRING_ASS(B1, B2) returns a string giving the assembly
% language representation of the instruction made of bytes B1, B2.
% Copyright 2008 University of Sussex and David Young
% instrs = {@NOP @LOADA, @LOADI, @STORE, @MOVE, @ADDI, @ADDF, @ORBITS, @ANDBITS, ...
% @XORBITS, @ROTBITS, @JUMP, @HALT, @LOADR, @STORER, @JUMPR};
[op, r, s, t] = decodeInstr(b1, b2);
switch op
case 0
if b1 == hex2dec('F') && b2 == hex2dec('FF')
str = 'NOP';
else
str = '';
end
case 1
str = ['MOV [' dec2hex(b2, 2) '] -> R' dec2hex(r)];
case 2
str = ['MOV ' dec2hex(b2, 2) ' -> R' dec2hex(r)];
case 3
str = ['MOV R' dec2hex(r) ' -> [' dec2hex(b2, 2) ']'];
case 4
str = ['MOV R' dec2hex(s) ' -> R' dec2hex(t)];
case 5
str = ['ADDI R' dec2hex(s) ', R' dec2hex(t) ' -> R' dec2hex(r)];
case 6
str = ['ADDF R' dec2hex(s) ', R' dec2hex(t) ' -> R' dec2hex(r)];
case 7
str = ['OR R' dec2hex(s) ', R' dec2hex(t) ' -> R' dec2hex(r)];
case 8
str = ['AND R' dec2hex(s) ', R' dec2hex(t) ' -> R' dec2hex(r)];
case 9
str = ['XOR R' dec2hex(s) ', R' dec2hex(t) ' -> R' dec2hex(r)];
case 10
str = ['ROT R' dec2hex(r) ', ' num2str(t)];
case 11
if r == 0
str = ['JMP ' dec2hex(b2, 2)];
else
str = ['JMPEQ ' dec2hex(b2, 2) ', R' dec2hex(r)];
end
case 12
str = 'HALT';
case 13
str = ['MOV [R' dec2hex(t) '] -> R' dec2hex(s)];
case 14
str = ['MOV R' dec2hex(s) ' -> [R' dec2hex(t) ']'];
case 15
if r == 0 && (s == 0 || s == 2 || s == 3)
str = ['JMP R' dec2hex(t)];
else
switch s
case 0
test = 'EQ';
case 1
test = 'NE';
case 2
test = 'GE';
case 3
test = 'LE';
case 4
test = 'GT';
case 5
test = 'LT';
otherwise
test = '??';
end
str = ['JMP' test ' R' dec2hex(t) ', R' dec2hex(r)];
end
end
end