使用 tc 存储映射类通过 toc 条目访问数据
通过首先从 TOC 中获取该项的地址,然后使用该地址获取数据,可访问外部数据项。
通过首先从 TOC 中获取该项的地址,然后使用该地址获取数据,可访问外部数据项。 要执行此操作,必须提供正确的重定位信息以访问正确的 TOC 条目。 .toc 和 .tc 伪操作生成正确的信息以访问 TOC 条目。 以下代码显示了如何访问项a使用其 TOC 条目:
.set RTOC,2
.csect prog1[pr] #prog1 is a csect
#containing instrs.
...
l 5,TCA(RTOC) #Now GPR5 contains the
#address of a[rw].
...
.toc
TCA: .tc a[tc],a[rw] #1st parameter is TOC entry
#name, 2nd is contents of
#TOC entry.
.extern a[rw] #a[rw] is an external symbol.
此方法用于访问程序的静态内部数据,即通过调用保留其值的数据,但只能通过声明数据项的文件中的过程进行访问。 以下是具有 静态 属性的 C 语言数据:
static int xyz;
此数据的名称由约定确定。 在 XCOFF 中,名称以下划线开头:
.csect prog1[pr]
...
l 1,STprog1(RTOC) #Load r1 with the address
#prog1's static data.
...
.csect _prog1[rw] #prog1's static data.
.long 0
...
.toc
STprog1: .tc.prog1[tc],_prog1[rw] #TOC entry with address of
#prog1's static data.