TRIPOS PDP-11 Assembler version 1.4


                                      ; Constants about machine.

              020000                  COREND	= 8.*1024.	; First unusable word


              002000                  WIDTH	= 1024.		; Height of display
              001400                  HEIGHT	= 768.		; Width of display

                                      ; Address of registers.

              172000                  DPC     = 172000        ; VT40 Program counter
              172002                  DSR     = 172002        ; VT40 Status register
              172004                  XSR     = 172004        ; X status register
              172006                  YSR     = 172006        ; Y status register

                                      ; Recommended mnemomics

              100000                  CHAR    = 100000        ; Character mode
              104000                  SHORTV  = 104000        ; Short vector mode
              110000                  LONGV   = 110000        ; Long vector mode
              114000                  POINT   = 114000        ; Point mode
              120000                  GRAPHX  = 120000        ; Graphplot X mode
              124000                  GRAPHY  = 124000        ; Graphplot Y mode
              130000                  RELATV  = 130000        ; Relative point mode

              002000                  INT0    = 2000          ; Intensity modes
              002200                  INT1    = 2200
              002400                  INT2    = 2400
              002600                  INT3    = 2600
              003000                  INT4    = 3000
              003200                  INT5    = 3200
              003400                  INT6    = 3400
              003600                  INT7    = 3600

              000100                  LPOFF   = 100           ; Light pen off
              000140                  LPON    = 140           ; and on

              000020                  BLKOFF  = 20            ; Blink off
              000030                  BLKON   = 30            ; and on

              000004                  LINE0   = 4             ; Solid line
              000005                  LINE1   = 5             ; Long dash
              000006                  LINE2   = 6             ; Short dash
              000007                  LINE3   = 7             ; Dot dash

              160000                  DJMP    = 160000        ; Display jump
              164000                  DNOP    = 164000        ; Display NOP

              170000                  STATSA  = 170000        ; Load status A
              173400                  DSTOP   = 173400        ; Display stop and interrupt

              001400                  SINON   = 1400          ; Stop interrupt on
              001000                  SINOFF  = 1000          ; Stop interrupt off
              000200                  LPLITE  = 200           ; Light pen hit on
              000300                  LPDARK  = 300           ; and off

              000040                  ITAL0   = 40            ; Italics off
              000060                  ITAL1   = 60            ; and on

              000004                  SYNC    = 4             ; Halt and resume in Sync

              174000                  STATSB  = 174000        ; Load status B
              000100                  INCR    = 100           ; Graphplot increment

              040000                  INTX    = 40000         ; Intensify vector or point
              001777                  MAXX    = 1777          ; Max delta-x
              001377                  MAXY    = 1377          ; Max delta-y

              020000                  MINUSX  = 20000         ; -ve delta-x
              020000                  MINUSY  = 20000         ; -ve delta-y

              017600                  MAXSX   = 17600         ; Max delta-x in short mode
              000077                  MAXSY   = 77            ; Max delta-y

              020000                  MISVX   = 20000         ; -ve delta-x
              000100                  MISVY   = 100           ; -ve delta-y

              000000'                         .PSECT

                                      ;       Simple PDP-11 program

      000000' 012706  017776          	MOV	#COREND-2,SP	; Set up stack

                                      ; R2 - x
                                      ; R3 - DPC when writing display file
      000004' 012703  000176'         MAIN:	MOV	#END,R3		; where to start writing point data
      000010' 005002                  	CLR	R2		; start x at 0

      000012'                         LOOP:

                                      	; compute next point on graph
      000012' 010200                  	MOV	R2,R0
      000014' 004767  000052          	JSR	PC,SQRT
                                      	; validate return value
      000020' 032701  176000          	BIT	#176000,R1	; Y range check - max 10 bits
      000024' 001016                  	BNE	BOOB
      000026' 010123                  	MOV	R1,(R3)+
      000030' 005202                  	INC	R2
      000032' 022702  001777          	CMP	#WIDTH-1,R2
      000036' 100365                  	BPL	LOOP		; loop until x>WIDTH-1

      000040'                         DISPLAY:
      000040' 012723  160000          	MOV	#DJMP,(R3)+	; fix up end of display program
      000044' 012723  000166'         	MOV	#DLOOP,(R3)+

      000050' 012737  000164' 172000  	MOV	#DPROG,@#DPC	; start displayprocessor runnig

      000056' 000001                  	WAIT			; for ever
      000060' 000000                  	HALT

      000062'                         BOOB:	; Got a duff value from sqrt!
      000062' 012737  000001  172002  	MOV	#1,@#DSR	; Beep!
      000070' 000763                  	BR	DISPLAY

                                      ; Integer square root, Martin Guy, June 1988.
                                      ; Negative arguments are simply negated to make things easy.
                                      ; Status: works for arguments -32767 to +32767
                                      ; Argument in R0 -> result in R1, remainder in R0

                                      ; R0	op
                                      ; R1	res
                                      ; R2	one
                                      ; R3	tmp (op-res-one)
      000072'                         SQRT:
                                      	; validate argument
      000072' 005700                  	TST	R0
      000074' 001431                  	BEQ	SQRT1		; if (op == 0) return(0);
      000076' 100001                  	BPL	SQRT2		; op = abs(op)
      000100' 005400                  	NEG	R0

                                      	; preserve temporary registers
      000102' 010246                  SQRT2:	MOV	R2,-(SP)	; preserve temporaries
      000104' 010346                  	MOV	R3,-(SP)

                                      	; initialise: res = 0; op = highest power of 4 <= op
      000106' 005001                  	CLR	R1

      000110' 012702  040000          	MOV	#40000,R2
      000114' 000402                  	BR	SQRT4
      000116' 006202                  SQRT3:	ASR	R2
      000120' 006202                  	ASR	R2
      000122' 020002                  SQRT4:	CMP	R0,R2
      000124' 100774                  	BMI	SQRT3		; loop until one <= op (R2 <= R0)
                                      				; ie until (R0 - R2) is positive or 0

                                      	; main sqrt loop
      000126' 010003                  SQRT5:	MOV	R0,R3		; op2 = op -res - one
      000130' 160103                  	SUB	R1,R3
      000132' 006201                  	ASR	R1		; loop reinit moved here from end for speed
      000134' 160203                  	SUB	R2,R3
      000136' 100402                  	BMI	SQRT6		; can't do it if it underflowed
                                      	; it can happen - do it.
      000140' 010300                  	MOV	R3,R0		; op = op2
      000142' 060201                  	ADD	R2,R1		; res += 2 * one (+=1*one cos R1 already >>)
      000144'                         SQRT6:
      000144' 006202                  	ASR	R2		; one >>= 2
      000146' 006202                  	ASR	R2
      000150' 001366                  	BNE	SQRT5		; while (one > 0);

                                      	; all done
      000152' 012603                  	MOV	(SP)+,R3
      000154' 012602                  	MOV	(SP)+,R2
      000156' 000207                  	RTS	PC

                                      ; Code fragment: 
      000160'                         SQRT1:
      000160' 005001                  	CLR	R1
      000162' 000207                  	RTS	PC

                                      ; end of SQRT

      000164'                         DPROG:	
      000164' 174101                  	STATSB+INCR+1

      000166' 114000                  DLOOP:	POINT
      000170' 000000                  	0
      000172' 000000                  	0
      000174' 124000                  	GRAPHY
      000176'                         END:	.END

No errors detected

Assembly statistics (words):

           Absolute   Relocatable
Code            0          63
Reloc. info     0           3

Space used for symbol table: 1070 words
Total workspace used: 1273 words
Assembly complete
