How many HALT and .END should appear in an assembler program? (Assuming our program should not execute forever)

2.1k views Asked by At

How many HALT and .END should appear in an assembler program? (Assuming our program should not execute forever)

Is it at least one HALT and one .END?

2

There are 2 answers

0
Jester On

Technically that is true, but .END signals the end of the source file. It is strictly a compile-time construct, has no influence on whether your code runs forever or not. You need to make sure the program flow eventually reaches a HALT instruction, for which you obviously need at least one of that. However that does not by itself guarantee that all execution paths really end up there, so it is not a sufficient condition.

0
aqua On

You should have exactly one .END for the assembler to know that the source file is complete, regardless of whether it should run forever or not.

You may have as many HALTs as you care for (including zero, in the 'run forever' case), however the same warning applies as with multiple return statements in higher level languages: multiple exit points can obscure code flow. For readability's sake, I'd recommend as few HALT statements as is practical.