TITLE numbin.a -- D. W. Jones ; Author: Douglas W. Jones ; Purpose: Implementation of the concrete class binary integer ; this is a subclass of number; read that file first! USE "hawk.macs" USE "number.h" USE "monitor.h" ; recapitulate some details of numbin.h representation SNUMBIN = 8 ; size of an object of type numbin ; private attributes of numbin objects: ; word zero points to the class descriptor INTREP = 4 ; word one is the 32-bit integer representation ; class description for all instances of this class INT NUMBIN NUMBIN: W NBIASBN ; address of ASSBIN routine for NUMBIN W NBIASNM ; address of ASSNUM routine for NUMBIN W NBITOBN ; address of NTOBIN routine for NUMBIN W NBITODS ; address of NTODSP routine for NUMBIN W NBIADD ; address of NADD routine for NUMBIN W NBISUB ; address of NSUB routine for NUMBIN W NBIMUL ; address of NMUL routine for NUMBIN W NBIDIV ; address of NDIV routine for NUMBIN ; ----- SUBTITLE NBIASBN ASSBIN routine for NUMBIN INT NBIASBN ; address of ASSBIN routine for NUMBIN NBIASBN: ; takes R3 = pointer to destination number object ; takes R4 = binary integer value to assign ; returns R3 = pointer to destination object LEA R5,NUMBIN STORES R5,R3 ; dest.class = NUMBIN STORE R4,R3,INTREP ; dest.intrep = R4 JUMPS R1 ; return ; ----- SUBTITLE NBIASNM ASSNUM routine for NUMBIN ; activation record format for NBIASNM RA = 0 ; return address DEST = 4 ; saved destination pointer ARSIZE = 8 ; size of activation record INT NBIASNM ; address of ASSNUM routine for NUMBIN NBIASNM: ; takes R3 = pointer to destination number object ; takes R4 = pointer to source number object ; returns R3 = pointer to destination object LEA R5,NUMBIN STORES R5,R3 ; dest.class = NUMBIN LOADS R6,R4 CMP R6,R5 ; if (source.class = NUMBIN) { BNE BIASDIF LOAD R5,R4,INTREP STORE R5,R3,INTREP ; dest.intrep = source.intrep JUMPS R1 ; return BIASDIF: ; } else { STORES R1,R2 ; -- save RA in AR STORE R3,R2,DEST ; -- save dest in AR MOVE R3,R4 LOADS R1,R3 ADDI R2,R2,ARSIZE LOAD R1,R1,NTOBIN JSRS R1,R1 ; R3 = source.ntobin() ADDI R2,R2,-ARSIZE LOAD R4,R2,DEST ; -- restore dest from AR STORE R3,R4,INTREP ; dest.intrep = R3 MOVE R3,R4 ; R3 = dest -- as caller expects LOADS R1,R2 ; -- restore RA from AR JUMPS R1 ; return ; ----- SUBTITLE NBITOBN NTOBIN routine for NUMBIN INT NBITOBN ; address of NTOBIN routine for NUMBIN NBITOBN: ; takes R3 = pointer to the source number object ; returns R3 = corresponding binary integer value LOAD R3,R3,INTREP ; R3 = source.intrep JUMPS R1 ; return ; ----- SUBTITLE NBITODS NTODSP routine for NUMBIN ; activation record format for NBITODS RA = 0 ; return address SOURCE = 4 ; saved source pointer ARSIZE = 8 ; size of activation record INT NBITODS ; address of NTODSP routine for NUMBIN NBITODS: ; takes R3 = pointer to the source number object ; returns R3 = pointer to source object STORES R1,R2 ; save RA in AR STORE R3,R2,SOURCE ; save source in AR LOAD R3,R3,INTREP LIS R4,0 ADDI R2,R2,ARSIZE LOAD R1,PDSPDEC JSRS R1,R1 ; dspdec( source.intrep, 0 ) ADDI R2,R2,-ARSIZE LOAD R3,R2,SOURCE ; restore source in AR for caller LOADS R1,R2 ; restore RA in AR JUMPS R1 ; return ; ----- SUBTITLE NBIADD NADD routine for NUMBIN ; activation record format for NBIADD RA = 0 ; return address DEST = 4 ; saved destination pointer ARSIZE = 8 ; size of activation record INT NBIADD ; address of NADD routine for NUMBIN NBIADD: ; takes R3 = pointer to destination number object ; takes R4 = pointer to source number object ; returns R3 = pointer to destination object LEA R5,NUMBIN LOADS R6,R4 CMP R6,R5 ; if (source.class = NUMBIN) { BNE NADDDIF LOAD R5,R4,INTREP ; srcrep = source.intrep; BR NADDX NADDDIF: ; } else { STORES R1,R2 ; -- save RA in AR STORE R3,R2,DEST ; -- save dest in AR MOVE R3,R4 LOADS R1,R3 ADDI R2,R2,ARSIZE LOAD R1,R1,NTOBIN JSRS R1,R1 ; R3 = source.ntobin() ADDI R2,R2,-ARSIZE MOVE R5,R3 ; srcrep = R3 LOAD R3,R2,DEST ; -- restore dest from AR LOADS R1,R2 ; -- restore RA from AR NADDX: ; } LOAD R4,R3,INTREP ADD R4,R4,R5 STORE R4,R3,INTREP ; dest.intrep += srcrep JUMPS R1 ; return ; ----- SUBTITLE NBISUB NSUB routine for NUMBIN ; activation record format for NBISUB RA = 0 ; return address DEST = 4 ; saved destination pointer ARSIZE = 8 ; size of activation record INT NBISUB ; address of NSUB routine for NUMBIN NBISUB: ; takes R3 = pointer to destination number object ; takes R4 = pointer to source number object ; returns R3 = pointer to destination object LEA R5,NUMBIN LOADS R6,R4 CMP R6,R5 ; if (source.class = NUMBIN) { BNE NSUBDIF LOAD R5,R4,INTREP ; srcrep = source.intrep; BR NSUBX NSUBDIF: ; } else { STORES R1,R2 ; -- save RA in AR STORE R3,R2,DEST ; -- save dest in AR MOVE R3,R4 LOADS R1,R3 ADDI R2,R2,ARSIZE LOAD R1,R1,NTOBIN JSRS R1,R1 ; R3 = source.ntobin() ADDI R2,R2,-ARSIZE MOVE R5,R3 ; srcrep = R3 LOAD R3,R2,DEST ; -- restore dest from AR LOADS R1,R2 ; -- restore RA from AR NSUBX: ; } LOAD R4,R3,INTREP SUB R4,R4,R5 STORE R4,R3,INTREP ; dest.intrep -= srcrep JUMPS R1 ; return ; ----- SUBTITLE NBIMUL NMUL routine for NUMBIN ; activation record format for NBIMUL RA = 0 ; return address DEST = 4 ; saved destination pointer ARSIZE = 8 ; size of activation record INT NBIMUL ; address of NMUL routine for NUMBIN NBIMUL: ; takes R3 = pointer to destination number object ; takes R4 = pointer to source number object ; returns R3 = pointer to destination object STORES R1,R2 ; -- save RA in AR STORE R3,R2,DEST ; -- save dest in AR LEA R5,NUMBIN LOADS R6,R4 CMP R6,R5 ; if (source.class = NUMBIN) { BNE NMULDIF LOAD R4,R4,INTREP ; srcrep = source.intrep; BR NMULX NMULDIF: ; } else { MOVE R3,R4 LOADS R1,R3 ADDI R2,R2,ARSIZE LOAD R1,R1,NTOBIN JSRS R1,R1 ; R3 = source.ntobin() ADDI R2,R2,-ARSIZE MOVE R4,R3 ; srcrep = R3 LOAD R3,R2,DEST ; -- restore dest from AR NMULX: ; } LOAD R3,R3,INTREP ADDI R2,R2,ARSIZE LOAD R1,PMUL JSRS R1,R1 ADDI R2,R2,-ARSIZE MOVE R4,R3 LOAD R3,R2,DEST ; -- restore dest from AR STORE R4,R3,INTREP ; dest.intrep = dest.intrep * srcrep LOADS R1,R2 ; -- restore RA from AR JUMPS R1 ; return ; ----- SUBTITLE NBIDIV NDIV routine for NUMBIN ; activation record format for NBIDIV RA = 0 ; return address DEST = 4 ; saved destination pointer ARSIZE = 8 ; size of activation record INT NBIDIV ; address of NDIV routine for NUMBIN NBIDIV: ; takes R3 = pointer to destination number object ; takes R4 = pointer to source number object ; returns R3 = pointer to destination object STORES R1,R2 ; -- save RA in AR STORE R3,R2,DEST ; -- save dest in AR LEA R5,NUMBIN LOADS R6,R4 CMP R6,R5 ; if (source.class = NUMBIN) { BNE NDIVDIF LOAD R4,R4,INTREP ; srcrep = source.intrep; BR NDIVX NDIVDIF: ; } else { MOVE R3,R4 LOADS R1,R3 ADDI R2,R2,ARSIZE LOAD R1,R1,NTOBIN JSRS R1,R1 ; R3 = source.ntobin() ADDI R2,R2,-ARSIZE MOVE R4,R3 ; srcrep = R3 LOAD R3,R2,DEST ; -- restore dest from AR NDIVX: ; } LOAD R3,R3,INTREP ADDI R2,R2,ARSIZE LOAD R1,PDIVU JSRS R1,R1 ADDI R2,R2,-ARSIZE MOVE R4,R3 LOAD R3,R2,DEST ; -- restore dest from AR STORE R4,R3,INTREP ; dest.intrep = dest.intrep / srcrep LOADS R1,R2 ; -- restore RA from AR JUMPS R1 ; return ; ----- END