@@ -30,9 +30,7 @@ void setup() {
30
30
void testStoreOperation () {
31
31
32
32
// Setup source and destination registers
33
- int op1 = Registry .nameToIdx (Registry .REG_R1 );
34
- int op2 = Registry .nameToIdx (Registry .REG_RES );
35
- int operand = (op1 << 4 ) | op2 ;
33
+ int operand = Registry .nameToIdx (Registry .REG_RES );
36
34
int registerValue = 35 ; // The value stored in the source register
37
35
int memoryAddress = 8 ; // The destination address in memory where the value should be stored
38
36
int nextMemoryLocation = 1 ; // The next memory location according to the program counter
@@ -41,14 +39,13 @@ void testStoreOperation() {
41
39
// destination address
42
40
when (mockPC .next ()).thenReturn (nextMemoryLocation );
43
41
44
- // Simulate fetching the operand from memory
45
- when (mockMemory .getValueAt (nextMemoryLocation )).thenReturn (operand );
42
+ // Simulate fetching the destination address from the memory
43
+ when (mockMemory .getValueAt (nextMemoryLocation )).thenReturn (memoryAddress );
46
44
47
45
// Simulate fetching the value from the register specified by the operand
48
- when (mockRegistry .getValueAt (op1 )).thenReturn (registerValue );
49
- when (mockRegistry .getValueAt (op2 )).thenReturn (memoryAddress );
46
+ when (mockRegistry .getValueAt (operand )).thenReturn (registerValue );
50
47
51
- St stInstruction = new St (0 );
48
+ St stInstruction = new St (operand );
52
49
stInstruction .execute (mockMemory , mockRegistry , mockPC , null );
53
50
54
51
// Verify memory's setValueAt method is called with the correct destination address and value
@@ -58,13 +55,15 @@ void testStoreOperation() {
58
55
59
56
@ Test
60
57
void testPrettyPrint () {
61
- St store = new St (0 );
62
- int leftOp = Registry .nameToIdx (Registry .REG_R2 );
63
- int rightOp = Registry .nameToIdx (Registry .REG_OP1 );
64
- int operand = (leftOp << 4 ) | rightOp ;
65
- when (mockMemory .getValueAt (1 )).thenReturn (operand );
58
+ // Setup source and destination registers
59
+ int operand = Registry .nameToIdx (Registry .REG_RES );
60
+ int memoryAddress = 8 ; // The destination address in memory where the value should be stored
61
+
62
+ when (mockMemory .getValueAt (1 )).thenReturn (memoryAddress );
63
+
64
+ St store = new St (operand );
66
65
assertEquals (
67
- InstructionFactory .INST_NAME_STO + " (R2 " + Instruction .RIGHT_ARROW_CHAR + " *OP1 )" ,
66
+ InstructionFactory .INST_NAME_STO + " (RES " + Instruction .RIGHT_ARROW_CHAR + " m[8] )" ,
68
67
store .prettyPrint (mockMemory , mockRegistry , 0 ));
69
68
}
70
69
}
0 commit comments