【问题标题】:how to expand TASM macros如何扩展 TASM 宏
【发布时间】:2016-11-20 19:06:31
【问题描述】:

有没有办法用 Borland 的 TASM 扩展宏? 我想转换一个与 TASM 兼容的 .ASM 文件,以查看他所有的宏扩展。 找不到执行此操作的任何选项。

【问题讨论】:

  • 如果 TASM 没有提供方法(我不知道),如果值得的话,您可能需要编译源代码并将二进制文件 objdump 回文本。

标签: assembly macros tasm


【解决方案1】:

使用 TASM 的命令行选项 /la 生成扩展列表。从这个清单中,您可以看到高级和低级扩展。此功能适用于所有版本的 TASM,直至 1988 年的初始版本。

例如,假设您有以下 TASM 宏:

OUTPUTMESSAGE MACRO hConsole,stringval
LOCAL msg
    .data
msg  db  '&stringval',0
    .code
    call outputString ,hConsole,OFFSET msg
ENDM ;OUTPUTMESSAGE

你想看看下面的源码是如何扩展的:

OUTPUTMESSAGE hConsole,<This app was assembled with TASM version >
OUTPUTMESSAGE hConsole,%??version

使用 /la 生成的列表文件(我碰巧使用的是 5.4 版)生成以下内容:

    516                      OUTPUTMESSAGE hConsole,<This app was assembled with TASM version >
1   517 0000018F                 .data
1   518 00000000  54 68 69 73 20 61 70+  ??0000  db  'This app was assembled with TASM version ',0
    519       70 20 77 61 73 20 61+
    520       73 73 65 6D 62 6C 65+
    521       64 20 77 69 74 68 20+
    522       54 41 53 4D 20 76 65+
    523       72 73 69 6F 6E 20 00
1   524 0000002A                 .code
2   525 0000018F  C8 0000 00             ENTERD  00000h,0
2   526                      call outputString ,hConsole,OFFSET ??0000
3   527 00000193  68 00000000r           PUSH    OFFSET ??0000
3   528 00000198  FF 75 08           PUSH    hConsole
3   529 0000019B  E8 FFFFFE9B            CALL    outputString
    530                      OUTPUTMESSAGE hConsole,%??version
1   531 000001A0                 .data
1   532 0000002A  31 32 38 34 00     ??0001  db  '1284',0
1   533 0000002F                 .code
1   534                      call outputString ,hConsole,OFFSET ??0001
2   535 000001A0  68 0000002Ar           PUSH    OFFSET ??0001
2   536 000001A5  FF 75 08           PUSH    hConsole
2   537 000001A8  E8 FFFFFE8E            CALL    outputString

这些列对应于 [depth] [line#] [offset] [machine_code] [source]。不幸的是,您会发现,[line#] 列并不是特别有用。以下是 TASM5 用户指南中描述这些列的片段:

[depth] - indicates the level of nesting of Include files and macros within your
          listing file.

[line#] - is the number of the line in the listing file (not including header
          and title lines). Line numbers are particularly useful when the
          cross-reference feature of Turbo Assembler, which refers to lines by
          line number, is used. Be aware that the line numbers in [line#] are
          not the source module line numbers. For example, if a macro is
          expanded or a file is included, the line-number field will continue to
          advance, even though the current line in the source module stays the
          same. To translate a line number (for example, one that the
          cross-referencer produced) back to the source file, you must look up
          the line number in the listing file, and then find that same line (by
          eye, not by number) in the source file.

[offset] - is the offset in the current segment of the start of the machine code
           generated by the associated assembler source line.

[machine_code] - is the actual sequence of hexadecimal byte and word values that
                 is assembled from the associated assembler source line.

[source] - is simply the original assembler line, comments and all. Some
           assembler lines, such as those that contain only comments, don't
           generate any machine code; these lines have no [offset] or [machine_
           code] fields, but do have a line number.

【讨论】:

  • @byteprt 谢谢,知道如何过滤除源之外的所有内容吗?
  • 在您的情况下打开或关闭列可能会很有用,但 TASM(甚至 MASM)的列表文件不是超级灵活。您也不能依赖深度列等于特定值来获得最低级别的源,因为这个数字会根据指令/宏的类型而波动,如上所示。正如@Ped7g 所建议的那样,我认为最好的办法是反汇编生成的模块以获取源代码。如果您需要了解特定的宏,列表文件至少对此很有用。
  • 话虽如此,如果您编写了一个解析器脚本以仅提取其行还包含 [machine-code] 列中的值的源代码行,那么在所有扩展之后,您将只获得最低级别的汇编源代码这就是你所追求的。请注意,此技术不能用于可靠地再现原始内容,因为您会错过介于两者之间的指令,例如在指令之间切换数据和 .code(如上所示)。同样,您似乎又回到了需要使用反汇编程序的阶段。
猜你喜欢
  • 1970-01-01
  • 2016-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多