简体   繁体   中英

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

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM