View Single Post
Old 17 April 2021, 15:17   #1
KONEY
OctaMED Music Composer
 
KONEY's Avatar
 
Join Date: Jan 2009
Location: Venice - Italy
Age: 49
Posts: 670
Self-modifying code not removing itself

Hello,
I'm writing this piece of code:

Code:
	.notFirstBlock:
	MOVE.W	P61_LAST_POS,D0
	CMPI	#0,D0
	BEQ.S	.dontStartSequencer
	LEA	        .notFirstBlock,A0
	MOVE.L	#$4E714E71,(A0)+	; NOP opcodes
	MOVE.L	#$4E714E71,(A0)+	; NOP opcodes
	MOVE.L	#$4E714E71,(A0)+	; NOP opcodes
	BSR.W	__SET_SEQUENCER_LEDS
	.dontStartSequencer:
which basically checks for a value and when this value changes the code removes itself, leaving just a BSR

This works fine but the three MOVEs won't remove themself for some reason.

debugging this is how code looks like after the three MOVE.L:

Code:
0001C75C 4e71                     NOP 
0001C75E 4e71                     NOP 
0001C760 4e71                     NOP 
0001C762 4e71                     NOP 
0001C764 4e71                     NOP 
0001C766 4e71                     NOP 
0001C768 20fc 4e71 4e71           MOVE.L #$4e714e71,(A0)+ [4e714e71]
0001C76E 20fc 4e71 4e71           MOVE.L #$4e714e71,(A0)+ [4e714e71]
0001C774 20fc 4e71 4e71           MOVE.L #$4e714e71,(A0)+ [4e714e71]
so the three MOVEs have generated six NOPs which replaced the instructions up to LEA but leaving the rest in place.

Maybe this is a limitation of the CPU? or what?

Also, inserting NOPs doesn't look lie the best idea to me and I'm wondering if there is something else better for this purpose.

Thanks for any help
KONEY is offline  
 
Page generated in 0.04324 seconds with 11 queries