mirror of
				https://github.com/simon987/Much-Assembly-Required.git
				synced 2025-10-31 00:16:51 +00:00 
			
		
		
		
	
							parent
							
								
									8c5dcd0fba
								
							
						
					
					
						commit
						04d51e1f1f
					
				| @ -93,6 +93,7 @@ public class CPU implements JSONSerialisable{ | |||||||
|         instructionSet.add(new JsInstruction(this)); |         instructionSet.add(new JsInstruction(this)); | ||||||
|         instructionSet.add(new HwiInstruction(this)); |         instructionSet.add(new HwiInstruction(this)); | ||||||
|         instructionSet.add(new HwqInstruction(this)); |         instructionSet.add(new HwqInstruction(this)); | ||||||
|  |         instructionSet.add(new XchgInstruction(this)); | ||||||
| 
 | 
 | ||||||
|         status = new Status(); |         status = new Status(); | ||||||
|         memory = new Memory(config.getInt("memory_size")); |         memory = new Memory(config.getInt("memory_size")); | ||||||
|  | |||||||
| @ -0,0 +1,14 @@ | |||||||
|  | package net.simon987.server.assembly.instruction; | ||||||
|  | 
 | ||||||
|  | import net.simon987.server.assembly.Instruction; | ||||||
|  | 
 | ||||||
|  | public class LeaInstruction extends Instruction { | ||||||
|  | 
 | ||||||
|  |     public static final int OPCODE = 30; | ||||||
|  | 
 | ||||||
|  |     public LeaInstruction() { | ||||||
|  |         super("lea", OPCODE); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -0,0 +1,33 @@ | |||||||
|  | package net.simon987.server.assembly.instruction; | ||||||
|  | 
 | ||||||
|  | import net.simon987.server.assembly.CPU; | ||||||
|  | import net.simon987.server.assembly.Instruction; | ||||||
|  | import net.simon987.server.assembly.Status; | ||||||
|  | import net.simon987.server.assembly.Target; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Swap operands. Does not alter the flags | ||||||
|  |  */ | ||||||
|  | public class XchgInstruction extends Instruction { | ||||||
|  | 
 | ||||||
|  |     public static final int OPCODE = 31; | ||||||
|  | 
 | ||||||
|  |     private CPU cpu; | ||||||
|  | 
 | ||||||
|  |     public XchgInstruction(CPU cpu) { | ||||||
|  |         super("xchg", OPCODE); | ||||||
|  | 
 | ||||||
|  |         this.cpu = cpu; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status) { | ||||||
|  | 
 | ||||||
|  |         int tmp = dst.get(dstIndex); | ||||||
|  |         dst.set(dstIndex, src.get(srcIndex)); | ||||||
|  |         src.set(srcIndex, tmp); | ||||||
|  | 
 | ||||||
|  |         return status; | ||||||
|  |     } | ||||||
|  | } | ||||||
										
											Binary file not shown.
										
									
								
							
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user