Compare commits

..

2 Commits

Author SHA1 Message Date
Darkress
022dd499ce Renamed setPcForGotoCall function to setPcFrom11BitLiteral 2023-05-30 01:18:51 +02:00
Darkress
3eaf697306 implemented Call instruction 2023-05-30 01:06:12 +02:00
5 changed files with 13 additions and 50 deletions

View File

@@ -12,14 +12,13 @@ class Main
public static void main(String[] args) { public static void main(String[] args) {
ArrayList<Command> program = new ArrayList<>(); ArrayList<Command> program = new ArrayList<>();
Memory.workingRegister = 0xAA;
int input1 = 0x27FF; int input1 = 0x27FF;
program.add(CommandDecoder.decode(0x3011)); program.add(CommandDecoder.decode(input1));
program.add(CommandDecoder.decode(0x2003));
program.add(CommandDecoder.decode(0x3022)); Memory.setPCLATH(0xFF);
program.add(CommandDecoder.decode(0x0008)); program.get(0).execute();
while(true)
{ //ProgramCounter.incPC();
program.get(ProgramCounter.getPc()).execute();
}
} }
} }

View File

@@ -1,24 +0,0 @@
package de.darkress.pic16f84sim.commands;
import de.darkress.pic16f84sim.microcontroller.Memory;
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
import de.darkress.pic16f84sim.microcontroller.Stack;
public class Retlw extends CommandUtils implements Command
{
private final int literal;
public Retlw(int input)
{
literal = input & 0x00FF;
}
@Override
public void execute()
{
Memory.workingRegister = literal;
ProgramCounter.setPcFrom11BitLiteral(Stack.pop());
//TODO: This may need some rework since it does not really load all 13 Bit into the PC. Only 8 Bit are
// effectively set
}
}

View File

@@ -1,15 +0,0 @@
package de.darkress.pic16f84sim.commands;
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
import de.darkress.pic16f84sim.microcontroller.Stack;
public class Return extends CommandUtils implements Command
{
@Override
public void execute()
{
ProgramCounter.setPcFrom11BitLiteral(Stack.pop());
//TODO: This may need some rework since it does not really load all 13 Bit into the PC. Only 8 Bit are
// effectively set
}
}

View File

@@ -110,7 +110,8 @@ public class CommandDecoder
case 0x3000: case 0x3000:
return new Movlw(input); return new Movlw(input);
case 0x3400: case 0x3400:
return new Retlw(input); //retlw();
break;
} }
if ((input | 0x0060) == 0x0060) if ((input | 0x0060) == 0x0060)
@@ -130,7 +131,8 @@ public class CommandDecoder
if (input == 0x0008) if (input == 0x0008)
{ {
return new Return(); //return();
//This is the function name. Do not mistake this for a normal return!
} }
if (input == 0x0063) if (input == 0x0063)

View File

@@ -14,8 +14,9 @@ public class Stack
public static int pop() public static int pop()
{ {
int tmp = stack[stackPointer];
pointPrevious(); pointPrevious();
return stack[stackPointer]; return tmp;
} }
public static int peek() public static int peek()