使用过程范围来避免使用局部标签? [英] Use procedure scope to avoid local labels?

查看:108
本文介绍了使用过程范围来避免使用局部标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将一些MASM代码移植到了NASM.除了需要本地标签外,该港口相当轻松.需要本地标签,因为MASM代码具有多个过程,并且某些标签是该过程共有的.例如

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

在NASM下,我必须使用本地标签.例如:

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

;; NASM code
  global _FOO
  section .text

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

当代码与调试信息组合在一起时,它会产生令人讨厌的标签(对我来说).该代码将产生标签_FOO.Exit_Failure_FOO.Exit_Success等.除了使人眼花,乱之外,它们还使移植变得更加复杂,因为我必须在每个标签上添加一个点.

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.

我似乎找不到NASM的代码命名"部分的概念,因此可以对标签进行范围划分.

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?

推荐答案

NASM部分提供了点前缀本地标签功能,以便您可以制作过程本地标签.没有用于使标签始终位于过程本地的MASM等效设置,因为NASM本身并不真正识别过程的存在.它只是保留标签的记录,我们有时将它们用作过程入口点,而NASM却无法真正分辨出这些标签或任何其他非本地标签之间的区别.

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.

这篇关于使用过程范围来避免使用局部标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆