Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
cc编译器生成的unix v6汇编代码的含义?_Unix_Cc_Pdp 11 - Fatal编程技术网

cc编译器生成的unix v6汇编代码的含义?

cc编译器生成的unix v6汇编代码的含义?,unix,cc,pdp-11,Unix,Cc,Pdp 11,例如,下面是一段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 $4

例如,下面是一段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 $4, 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更喜欢八进制数而不是十六进制数,您可能会发现这很有帮助

是一种使寄存器5(r5)指向某些数据(可能是偏移列表)的方法

这些数字对应于堆栈上以八进制表示的偏移量。假定调用方执行以下操作

  • 将a和b推到堆栈上(正偏移)
  • 将返回地址推送到堆栈上(偏移量=0)
  • 可能在
    csv
    功能中推送其他内容
  • c和d是局部变量(负偏移,因此为“17777x”)
那条线

~d=177776
看起来很奇怪-我想是的

~d=177766
因为它应该在堆栈的
c
下面。寄存器操作数中的
-10
-12
偏移量看起来也是八进制数。您应该能够根据上下文将偏移量与变量匹配起来

这只是一个有根据的猜测:不久前,我在一本书中修改了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
是一个(或多或少)常规符号。

未初始化变量?以
~
开头的行可能是注释。查看“Lions’Commentation on UNIX 6th Edition”,显示的汇编程序似乎使用了
/
标记注释行,但没有以
~
开头的行来说明该用法。但是我猜,我不打算在网上寻找Unix V6 assembler for PDP 11/40,但有可能一个或多个搜索引擎知道这些信息的位置。我认为链接器使用以
~
开头的行。但是找不到具体的材料。如果在机器上工作,所有这些都是八进制而不是十六进制。如果在gcc上使用带有pdp11后端的现代计算机,情况就不同了。看看机器代码,它被分为3位部分,以便更容易地以八进制读取它…必须考虑八进制,以便使pdp11更容易理解…是的,
~d=177766
。这是一个负的偏移量,我应该考虑一下。谢谢你的精彩猜测。如果我能很好地回答你的问题,你可能会把它标为“接受”。对不起,我忘了。但是你能分享更多关于瓷砖的信息吗?
~a=4
$a=4