Use procedure scope to avoid local labels?

房东的猫 提交于 2019-12-12 02:28:56

问题


I ported some MASM code to NASM. The port was fairly painless, except for the need for local labels. The local labels were needed because the MASM code had multiple procedures, and some labels were common to the procedure. For example

;; MASM code
_FOO PROC
  ...
Exit_Failure:
  ...
Exit_Success:
  ...
  ret
_FOO ENDP

_BAR PROC
  ...
Exit_Failure:
  ...
Exit_Success:
  ...
  ret
_BAR ENDP

Under NASM, I have to use local labels. For example:

;; NASM code
  global _FOO
  section .text

_FOO:
  ...
.Exit_Failure:
  ...
.Exit_Success:
  ...
  ret

When the code is assembled with debugging information, it produces labels that are eyesores (to me). The code will produce labels _FOO.Exit_Failure, _FOO.Exit_Success and so on. In addition to being an eyesore, they complicate porting because I have to add a dot to every label.

I can't seem to find NASM's notion of a "named" section of code so the label can be scoped.

How do I scope procedures to avoid the need for local labels?


回答1:


NASM provides the dot-prefixed local label functionality in part so that you can make procedure-local labels. There is no MASM-equivalent setting for making labels always be local to procedures because NASM itself doesn't really recognize the existence of procedures. It just keeps records of labels, which we sometimes use as procedure entry points without NASM really being able to tell the difference between those or any other non-local labels.

You can make macro-local labels prefixed with %% instead of a period, allowing you to use the same macro multiple times inside the same function, but that's it.



来源:https://stackoverflow.com/questions/33657397/use-procedure-scope-to-avoid-local-labels

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!