@@ -634,19 +634,20 @@ impl Cpu {
634634 // Unimplemented instruction, since all bits are 0.
635635 return Err ( Exception :: IllegalInstruction ) ;
636636 }
637- inst = self . execute_compressed ( ) ?
637+ inst = inst16;
638+ self . execute_compressed ( inst16) ?
639+ }
640+ _ => {
641+ inst = self . fetch ( WORD ) ?;
642+ self . execute_general ( inst) ?
638643 }
639- _ => inst = self . execute_general ( ) ?,
640644 }
641645 Ok ( inst)
642646 }
643647
644648 /// Execute a compressed instruction. Raised an exception if something is wrong, otherwise,
645649 /// returns a fetched instruction. It also increments the program counter by 2 bytes.
646- pub fn execute_compressed ( & mut self ) -> Result < u64 , Exception > {
647- // 1. Fetch.
648- let inst = self . fetch ( HALFWORD ) ?;
649-
650+ pub fn execute_compressed ( & mut self , inst : u64 ) -> Result < ( ) , Exception > {
650651 // Add 2 bytes to the program counter.
651652 self . pc += 2 ;
652653
@@ -1226,15 +1227,12 @@ impl Cpu {
12261227 return Err ( Exception :: IllegalInstruction ) ;
12271228 }
12281229 }
1229- Ok ( inst )
1230+ Ok ( ( ) )
12301231 }
12311232
12321233 /// Execute a general-purpose instruction. Raises an exception if something is wrong,
12331234 /// otherwise, returns a fetched instruction. It also increments the program counter by 4 bytes.
1234- fn execute_general ( & mut self ) -> Result < u64 , Exception > {
1235- // 1. Fetch.
1236- let inst = self . fetch ( WORD ) ?;
1237-
1235+ fn execute_general ( & mut self , inst : u64 ) -> Result < ( ) , Exception > {
12381236 // Add 4 bytes to the program counter.
12391237 self . pc += 4 ;
12401238
@@ -3323,6 +3321,6 @@ impl Cpu {
33233321 return Err ( Exception :: IllegalInstruction ) ;
33243322 }
33253323 }
3326- Ok ( inst )
3324+ Ok ( ( ) )
33273325 }
33283326}
0 commit comments