BSD 4 release
[unix-history] / usr / src / cmd / px / 05index.s
index c7e77ca..40f7217 100644 (file)
@@ -1,12 +1,14 @@
 #\f
 #\f
-# 05index.s
+# Copyright (c) 1979 Regents of the University of California
+#
+# char sccsid[] = "@(#)05index.s 4.1 10/10/80";
 #
 # OFF, INDEX and NIL
 #
 _OFF:
        cvtbl   (r10)+,r0
        bneq    l0501
 #
 # OFF, INDEX and NIL
 #
 _OFF:
        cvtbl   (r10)+,r0
        bneq    l0501
-       cvtwl   (r10)+,r0
+       movzwl  (r10)+,r0
 l0501:
        addl2   r0,(sp)
        jmp     (r8)
 l0501:
        addl2   r0,(sp)
        jmp     (r8)
@@ -15,12 +17,13 @@ _INX2:
        bneq    l0502
        cvtwl   (r10)+,r0       #r0 has size
 l0502:
        bneq    l0502
        cvtwl   (r10)+,r0       #r0 has size
 l0502:
-       cvtwl   (r10)+,r1       #r1 has lower bound
-       cvtwl   (r10)+,r2       #r2 has upper bound
-       cvtwl   (sp)+,r3        #r3 contains subscript
-       subl2   r1,r3           #r3 has base subscript
-       index   r3,$0,r2,r0,$0,r1  #r1 has calculated offset
-       addl2   r1,(sp)         #calculate actual address
+       clrl    r3              #r3 has base subscript
+       subw3   (r10)+,(sp)+,r3
+       blss    esubscr         #check lower bound
+       cmpw    r3,(r10)+       #check upper bound
+       bgtru   esubscr
+       mull2   r0,r3           #calc byte offset
+       addl2   r3,(sp)         #calculate actual address
        jmp     (r8)
 _INX4:
        cvtbl   (r10)+,r0
        jmp     (r8)
 _INX4:
        cvtbl   (r10)+,r0
@@ -28,12 +31,16 @@ _INX4:
        cvtwl   (r10)+,r0       #r0 has size
 l0503:
        cvtwl   (r10)+,r1       #r1 has lower bound
        cvtwl   (r10)+,r0       #r0 has size
 l0503:
        cvtwl   (r10)+,r1       #r1 has lower bound
-       cvtwl   (r10)+,r2       #r2 has upper bound
-       movl    (sp)+,r3        #r3 contains subscript
-       subl2   r1,r3           #r3 has base subscript
-       index   r3,$0,r2,r0,$0,r1  #r1 has calculated offset
-       addl2   r1,(sp)         #calculate actual address
+       movzwl  (r10)+,r2       #r2 has upper-lower bound
+       subl3   r1,(sp)+,r3     #r3 has base subscript
+       cmpl    r3,r2           #check for out of bounds
+       bgtru   esubscr
+       mull2   r0,r3           #calc byte offset
+       addl2   r3,(sp)         #calculate actual address
        jmp     (r8)
        jmp     (r8)
+esubscr:
+       movl    $ESUBSCR,_perrno
+       jbr     error
 _NIL:
        incl    r10
        tstl    (sp)
 _NIL:
        incl    r10
        tstl    (sp)
@@ -51,8 +58,9 @@ _INX4P2:
        jmp     (r8)
 _INX2P2:
        cvtbl   (r10)+,r0       #r0 has shift amount
        jmp     (r8)
 _INX2P2:
        cvtbl   (r10)+,r0       #r0 has shift amount
-       clrl    r1              #clear upper half of r1
-       subw3   (r10)+,(sp)+,r1 #r1 has base subscript
-       ashl    r0,r1,r1
-       addl2   r1,(sp)
+       cvtwl   (r10)+,r1       #r1 has base array value
+       cvtwl   (sp)+,r2        #r2 has subscript value
+       subl2   r1,r2           #r2 has element offset
+       ashl    r0,r2,r2        #r2 has byte offset
+       addl2   r2,(sp)
        jmp     (r8)
        jmp     (r8)