How to create the dead loop by one assembly instruction ?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to create the dead loop by one assembly instruction ?

4,098 Views
admin
Specialist II
I want to added a software trap in my application, I fill the unused ROM location with the SWI instruction. And I want to add the dead loop in the ISR of SWI, so that the watchdog can reset the CPU.
 
My 'deadloop' code is as below:
 
dead_loop:
                  NOP;
                  JMP dead_loop;
 
I remeber in the MCS-51 MCU, we could invoke a single insrutcion "SJMP &;" to create a deadloop, is there any similar instruction for the HC08?
 
Thanks,
Simon
Labels (1)
0 Kudos
9 Replies

856 Views
peg
Senior Contributor IV
Hi Simon
 
BRA *
 
0 Kudos

856 Views
admin
Specialist II
Hi Peg,
 
Thanks.
0 Kudos

856 Views
PeterHouse
Contributor I
peg,

Respectfully, this still takes two bytes.  Could you use the SWI instruction to cause and endless loop at the interrupt location?  I do not have hardware up and running to test this right now.

Peter House
0 Kudos

856 Views
ok2ucx
Contributor IV
SWI would be the cure - this is recommended technique: filling all unused memory with SWI instruction (use FILL 0x83 directive in .prm file for all Flash areas)
 
Regards, Pavel
0 Kudos

856 Views
peg
Senior Contributor IV
Hi all,
We seem to be getting off track here.
The OP already said he is filling unused memory with SWI.
What he wanted was a one instruction (should have said one byte) loop to put in the ISR for the SWI.
My answer is, I believe, as tight as it gets.
Someone with a few minutes to spare may want to work out what would happen if you were in fact to land on the operand of this instruction.
Maybe it still works???
 
0 Kudos

856 Views
Nabla69
Contributor V

Hello all,

I don't even think that a one instruction loop in the SWI ISR (Interrupt Sub Routine) is what Simon Zhu was looking for.

Going to the ISR is using time.

I believe Simon Zhu would like the equivalent of Peg's BRA * to be put anywhere in the code and in one byte, outside any interrupt.

Looking at the HC08 Instruction Table, there is one column dedicated to "Branches" and there is no "one-byte instruction.

Therefore, my answer would be. There is no branch instruction you can use in one-byte.
Using the SWI is one way to work around by inserting a one-byte instruction to jump somewhere else where you would have the space to do a longer code.

Simon, may you please precise ?
Do you want to hack into existing ASM code to add this infinite loop ? It looks like it to me.

David,
I don't understand the last part of your contribution on the few minutes to spare. Can you please explain to me what you mean ?


Alfred.

0 Kudos

856 Views
peg
Senior Contributor IV
Hi Al,
 
Run out of names?
 
My understanding of filling the memory with SWI is to do something predictable when (if?) the code goes bananas jumping off into unused (random) memory. Filling with a one byte jump like SWI means it gets caught immediately and does something you control rather than something random like push the red button. What I was thinking was what happened if it landed on the operand of this BRA (and tried to decode it as an instruction) but actually now I realise (with a little more thought and prodding) that that would be the same as landing on any other valid code anyway. So now the question is raised "Why do you need a one byte loop in the ISR?" or "What's wrong with SWI to achieve this? Why are you looking beyond this solution?"
 
Actually on a re-read of the original post:
 
"And I want to add the dead loop in the ISR of SWI"
 
seems pretty clear to me!


Message Edited by peg on 2007-09-24 08:26 PM
0 Kudos

856 Views
Nabla69
Contributor V
Hi Peg,
 
We kind of got out of the question then.
I imagine we have all the space we wish for this loop in SWI then.
 
Simon, it is important to note that an SWI in the MON08 mode (debug) is generating a break in the software and will stop the execution.
 
I know it is a bit out of subject now... Still, I prefer using an Illegal Opcode (ILOP) to fill the empty space.
I consider the code runaway as a very important problem and generate a reset as I am not confident the rest of the flow is valid anymore.
The ILOP comes from a single byte instruction and is handled after reset.
 
Alberto :smileywink:
0 Kudos

856 Views
peg
Senior Contributor IV
Hi,
 
If someone had of thought of this a long time ago, they would have made sure 00 and FF where invalid opcodes ( and generate an ILOP) and all these conversations on this subject never would have had to happen. Long live backwards compatability!
 
0 Kudos