cc编译器生成的unix v6汇编代码是什么意思?
Meaning of unix v6 assembly code generated by cc compiler?
例如下面是一段C代码及其由cc编译器生成的汇编代码。
// C code (pre K&R C)
foo(a, b) {
int c, d;
c = a;
d = b;
return c+d;
}
// corresponding assembly code generated by cc
.global _foo
.text
_foo:
~~foo:
~a=4
~b=6
~c=177770
~d=177766
jsr r5, csv
sub , sp
mov 4(r5), -10(r5)
mov 6(r5), -12(r5)
mov -10(r5), r0
add -12(r5), r0
jbr L1
L1: jmp cret
我能看懂大部分代码。但是我不知道 ~~foo:
是做什么的。 ~c=177770
和 ~d=177766
中的幻数从何而来?硬件是 pdp-11/40.
波浪号看起来像是决定堆栈使用的数据。您可能会发现回想一下 pdp-11 使用 16 位整数以及 DEC 更喜欢 octal 数字而不是 hexadecimal.
那个
jsr r5, csv
是一种使寄存器 5 (r5) 指向某些数据(可能是偏移量列表)的方法。
这些数字对应于 octal 中堆栈上的偏移量。假设调用者做类似
的事情
- 将 a 和 b 压入堆栈(正偏移量)
- 将return地址压入堆栈(偏移量=0)
- 可能会在
csv
函数中推送其他内容
- c 和 d 是局部变量(负偏移量,因此是“17777x”)
那一行
~d=177776
看起来很奇怪 - 我希望
~d=177766
因为它应该在堆栈的 c
下面。寄存器操作数中的 -10
和 -12
偏移量看起来也是八进制数。您应该能够根据上下文将偏移量与变量相匹配。
这只是一个有根据的猜测:我不久前在 text-editor.
中改编了 jsr+r5 惯用语
带波浪号的行是符号定义。 DECUS C 编译器参考 中的一个线索,位于
ftp://ftp.update.uu.se/pub/pdp11/rsx/lang/decusc/2.19/005003/CC.DOC
这表示
3.3 Global Symbols Containing Radix-50 '$' and '.'
______ _______ __________ ________ ___
With this version of Decus C, it is possible to generate and
access global symbols which contain the Radix-50 '.' and '$'.
The compiler allows identifiers to contain the Ascii '$', which
becomes a Radix-50 '$' in the object code. The AS assembly code
shows this character as a tilde (~). The underscore character
(_) in a C program becomes a '.' in both the AS assembly
language and in the object code. This allows C programs to
access all global symbols:
extern int $dsw;
. . .
printf("Directive status = %06o\n", $dsw);
The above prints the current contents of the task's directive
status word.
所以你可以阅读
~a=4
作为
$a=4
并看到 $a
是(或多或少)常规符号。
例如下面是一段C代码及其由cc编译器生成的汇编代码。
// C code (pre K&R C)
foo(a, b) {
int c, d;
c = a;
d = b;
return c+d;
}
// corresponding assembly code generated by cc
.global _foo
.text
_foo:
~~foo:
~a=4
~b=6
~c=177770
~d=177766
jsr r5, csv
sub , sp
mov 4(r5), -10(r5)
mov 6(r5), -12(r5)
mov -10(r5), r0
add -12(r5), r0
jbr L1
L1: jmp cret
我能看懂大部分代码。但是我不知道 ~~foo:
是做什么的。 ~c=177770
和 ~d=177766
中的幻数从何而来?硬件是 pdp-11/40.
波浪号看起来像是决定堆栈使用的数据。您可能会发现回想一下 pdp-11 使用 16 位整数以及 DEC 更喜欢 octal 数字而不是 hexadecimal.
那个
jsr r5, csv
是一种使寄存器 5 (r5) 指向某些数据(可能是偏移量列表)的方法。
这些数字对应于 octal 中堆栈上的偏移量。假设调用者做类似
的事情- 将 a 和 b 压入堆栈(正偏移量)
- 将return地址压入堆栈(偏移量=0)
- 可能会在
csv
函数中推送其他内容 - c 和 d 是局部变量(负偏移量,因此是“17777x”)
那一行
~d=177776
看起来很奇怪 - 我希望
~d=177766
因为它应该在堆栈的 c
下面。寄存器操作数中的 -10
和 -12
偏移量看起来也是八进制数。您应该能够根据上下文将偏移量与变量相匹配。
这只是一个有根据的猜测:我不久前在 text-editor.
中改编了 jsr+r5 惯用语带波浪号的行是符号定义。 DECUS C 编译器参考 中的一个线索,位于
ftp://ftp.update.uu.se/pub/pdp11/rsx/lang/decusc/2.19/005003/CC.DOC
这表示
3.3 Global Symbols Containing Radix-50 '$' and '.'
______ _______ __________ ________ ___
With this version of Decus C, it is possible to generate and
access global symbols which contain the Radix-50 '.' and '$'.
The compiler allows identifiers to contain the Ascii '$', which
becomes a Radix-50 '$' in the object code. The AS assembly code
shows this character as a tilde (~). The underscore character
(_) in a C program becomes a '.' in both the AS assembly
language and in the object code. This allows C programs to
access all global symbols:
extern int $dsw;
. . .
printf("Directive status = %06o\n", $dsw);
The above prints the current contents of the task's directive
status word.
所以你可以阅读
~a=4
作为
$a=4
并看到 $a
是(或多或少)常规符号。