@@ -195,26 +195,36 @@ describe("Virtual machine", () => {
195195 expect ( vm . registers [ 0xa ] ) . to . equal ( 0xff ) ;
196196 expect ( vm . registers [ 0xf ] ) . to . equal ( 0x0 ) ;
197197 } ) ;
198- it ( "should shift register right by one bit and assign it to another register" , ( ) => {
199- const vm = initializeVm ( [ 0x6bee , 0x8ab6 , 0x6bff , 0x8ab6 ] ) ;
200- //Shift value register VB to the right by 1 bit and and store it in register
201- //VA - set register VF to the least significant bit before the shift
198+ it ( "should shift register right by one bit" , ( ) => {
199+ const vm = initializeVm ( [
200+ 0x6bee , //Store 0xEE in register VB (least significant bit is 0)
201+ 0x8bb6 , //Shift register VB right by one bit
202+ 0x6bff , //Store 0xFF in register VB (least significant bit is 1)
203+ 0x8bb6 //Shift register VB right by one bit
204+ ] ) ;
205+ //Register VB should be shifted right and register VF should be 0
202206 times ( 2 , ( ) => vm . next ( ) ) ;
203- expect ( vm . registers [ 0xa ] ) . to . equal ( 0x77 ) ;
207+ expect ( vm . registers [ 0xb ] ) . to . equal ( 0x77 ) ;
204208 expect ( vm . registers [ 0xf ] ) . to . equal ( 0x0 ) ;
209+ //Register VB should be shifted right and register VF should be 1
205210 times ( 2 , ( ) => vm . next ( ) ) ;
206- expect ( vm . registers [ 0xa ] ) . to . equal ( 0x7f ) ;
211+ expect ( vm . registers [ 0xb ] ) . to . equal ( 0x7f ) ;
207212 expect ( vm . registers [ 0xf ] ) . to . equal ( 0x1 ) ;
208213 } ) ;
209- it ( "should shift register left by one bit and assign it to another register" , ( ) => {
210- const vm = initializeVm ( [ 0x6bee , 0x8abe , 0x6b7f , 0x8abe ] ) ;
211- //Shift value register VB to the left by 1 bit and and store it in register
212- //VA - set register VF to the most significant bit before the shift
214+ it ( "should shift register left by one bit" , ( ) => {
215+ const vm = initializeVm ( [
216+ 0x6bee , //Store 0xEE in register VB (most significant bit is 1)
217+ 0x8bbe , //Shift register VB left by one bit
218+ 0x6b7f , //Store 0x7F in register VB (most significant bit is 0)
219+ 0x8bbe //Shift register VB left by one bit
220+ ] ) ;
221+ //Register VB should be shifted left and register VF should be 1
213222 times ( 2 , ( ) => vm . next ( ) ) ;
214- expect ( vm . registers [ 0xa ] ) . to . equal ( 0xdc ) ;
223+ expect ( vm . registers [ 0xb ] ) . to . equal ( 0xdc ) ;
215224 expect ( vm . registers [ 0xf ] ) . to . equal ( 0x1 ) ;
225+ //Register VB should be shifted left and register VF should be 0
216226 times ( 2 , ( ) => vm . next ( ) ) ;
217- expect ( vm . registers [ 0xa ] ) . to . equal ( 0xfe ) ;
227+ expect ( vm . registers [ 0xb ] ) . to . equal ( 0xfe ) ;
218228 expect ( vm . registers [ 0xf ] ) . to . equal ( 0x0 ) ;
219229 } ) ;
220230 } ) ;
0 commit comments