/* An INST is composed of a pointer to the instance fields, together with a pointer to the (static) table of instance methods. */ block INST { local { public fields: quad; public methods: quad; public max: } // create( long fieldSize, long *methods ) { // long *fields = allocate( fieldSize ); // INST *instance = allocate( sizeof( INST ) ); // instance->fields = fields; // instance->methods = methods; // return instance; // } public block create uses proc { abs { public fieldSize = s0; public methods = s1; public fields = s2; public instance = s3; } const { string: asciiz "Unable to allocate memory\n"; } code { public enter: lda $sp, -sav4($sp); stq $ra, savRA($sp); stq $fp, savFP($sp); stq $ip, savIP($sp); stq $s0, sav0($sp); stq $s1, sav1($sp); stq $s2, sav2($sp); stq $s3, sav3($sp); decls: mov $a0, $fieldSize; mov $a1, $methods; body: // Allocate space for the fields mov $fieldSize, $a0; bsr Memory.allocate.enter; beq $v0, error; mov $v0, $fields; // Allocate space for the instance ldiq $a0, INST.max; bsr Memory.allocate.enter; beq $v0, error; // Fill in fields/methods pointers for instance mov $v0, $instance; stq $fields, INST.fields($instance); stq $methods, INST.methods($instance); return: ldq $s3, sav3($sp); ldq $s2, sav2($sp); ldq $s1, sav1($sp); ldq $s0, sav0($sp); ldq $ip, savIP($sp); ldq $fp, savFP($sp); ldq $ra, savRA($sp); lda $sp, +sav4($sp); ret; error: ldiq $a0, string; bsr IO.print.enter; mov 1, $a0; bsr Sys.exit.enter; } } }