Research V6 development
authorDennis Ritchie <dmr@research.uucp>
Thu, 17 Jul 1975 16:04:57 +0000 (11:04 -0500)
committerDennis Ritchie <dmr@research.uucp>
Thu, 17 Jul 1975 16:04:57 +0000 (11:04 -0500)
Work on file usr/source/fort/sum.s

Co-Authored-By: Ken Thompson <ken@research.uucp>
Synthesized-from: v6

usr/source/fort/sum.s [new file with mode: 0644]

diff --git a/usr/source/fort/sum.s b/usr/source/fort/sum.s
new file mode 100644 (file)
index 0000000..bdb8bf1
--- /dev/null
@@ -0,0 +1,44 @@
+/      example of UNIX fortran
+/      calling interface to machine code
+/      this example is a function that
+/      returns the single precision 
+/      sum of all of its single precision arguments.
+/      for example:
+/              f = sum(1.,2.,3.)
+/      sets f to 6.
+
+.globl sum.                            / defination of entry
+.globl retrn                           / reference of return
+
+sum.:                                  / entry point
+       value                           / location of return value
+       .+2                             / pointer to execution code
+       setf                            / no d/f i/l modes guaranteed
+       mov     *2(sp),r0               / arg count
+       mov     r3,r1                   / r3 points to arg list
+       tst     (r1)+                   / zeroth arg is old r3
+
+       clrf    fr0                     / start of actual function
+1:
+       addf    *(r1)+,fr0              / add in each argument
+       sob     r0,1b                   / for each argument
+
+       movf    fr0,value               / make returned value available
+       jmp     retrn                   / actual return
+
+.bss
+value: .=.+4                           / space for return value
+
+/ synopsis:
+/      1. save registers r3, sp
+/      2. arg list (pointers to values)
+/         begins at 2(r3)
+/      3. entry name is name of function
+/         followed by "."
+/      4. first word after entry point is
+/         location of return value. this is
+/         true for both functions and subroutines
+/      5. second word after entry point is
+/         pointer to pdp-11 code body
+/      6. return is expedited by a jump to
+/         the globl routine "retrn"