block Array { // []char fromString( String s ) { // int length = s.length(); // []char result = new [ length ]char; // for ( int i = 0; i < length; i++ ) // result[ i ] = s[ i ]; // return result; // } public block fromString uses proc { abs { s = s0; length = s1; result = s2; i = s3; base = s4; } code { public enter: lda $sp, -sav6($sp); stq $ra, savRA($sp); stq $s0, sav0($sp); stq $s1, sav1($sp); stq $s2, sav2($sp); stq $s3, sav3($sp); stq $s4, sav4($sp); stq $s5, sav5($sp); decls: mov $a0, $s; body: mov $s, $a0; bsr String.length.enter; mov $v0, $length; mov 16, $a0; bsr Memory.allocate.enter; mov $v0, $result; s8addq $length, 0, $a0; bsr Memory.allocate.enter; mov $v0, $base; stq $length, 0($result); stq $base, 8($result); { for: clr $i; while: cmplt $i, $length, $t0; blbc $t0, end; do: s8addq $i, $base, $t0; addq $i, $s, $t1; ldbu $t1, ($t1); stq $t1, ($t0); continue: addq $i, 1; br while; end: } mov $result, $v0; return: ldq $s5, sav5($sp); ldq $s4, sav4($sp); ldq $s3, sav3($sp); ldq $s2, sav2($sp); ldq $s1, sav1($sp); ldq $s0, sav0($sp); ldq $ra, savRA($sp); lda $sp, +sav6($sp); ret; } } // String toString( []char a ) { // int length = size a; // String s = new [ length + 1 ]String; // for ( int i = 0; i < length; i++ ) // s[ i ] = a[ i ]; // return s; // } public block toString uses proc { abs { a = s0; s = s1; length = s2; result = s3; i = s4; base = s5; } code { public enter: lda $sp, -sav6($sp); stq $ra, savRA($sp); stq $s0, sav0($sp); stq $s1, sav1($sp); stq $s2, sav2($sp); stq $s3, sav3($sp); stq $s4, sav4($sp); stq $s5, sav5($sp); decls: mov $a0, $a; body: ldq $length, 0($a); ldq $base, 8($a); addq $length, 1, $a0; bsr Memory.allocate.enter; mov $v0, $s; { for: clr $i; while: cmplt $i, $length, $t0; blbc $t0, end; do: s8addq $i, $base, $t0; addq $i, $s, $t1; ldq $t0, ($t0); stb $t0, ($t1); continue: addq $i, 1; br while; end: } mov $s, $v0; return: ldq $s5, sav5($sp); ldq $s4, sav4($sp); ldq $s3, sav3($sp); ldq $s2, sav2($sp); ldq $s1, sav1($sp); ldq $s0, sav0($sp); ldq $ra, savRA($sp); lda $sp, +sav6($sp); ret; } } // []char concat( []char a, b ) { // int lengthA = size a; // int lengthB = size b; // []char result = new [ lengthA + lengthB ]char; // for ( int i = 0; i < lengthA; i++ ) // result[ i ] = a[ i ]; // for ( int i = 0; i < lengthB; i++ ) // result[ i + lengthA ] = b[ i ]; // return result; // } public block concat uses proc { abs { lengthA = s0; lengthB = s1; base = s2; i = s3; baseA = s4; baseB = s5; } code { public enter: lda $sp, -sav6($sp); stq $ra, savRA($sp); stq $s0, sav0($sp); stq $s1, sav1($sp); stq $s2, sav2($sp); stq $s3, sav3($sp); stq $s4, sav4($sp); stq $s5, sav5($sp); decls: body: ldq $lengthA, 0($a0); ldq $baseA, 8($a0); ldq $lengthB, 0($a1); ldq $baseB, 8($a1); addq $lengthA, $lengthB, $t0; s8addq $t0, 0, $a0; bsr Memory.allocate.enter; mov $v0, $base; { for: clr $i; while: cmplt $i, $lengthA, $t0; blbc $t0, end; do: s8addq $i, $baseA, $t0; s8addq $i, $base, $t1; ldq $t0, ($t0); stq $t0, ($t1); continue: addq $i, 1; br while; end: } { for: clr $i; while: cmplt $i, $lengthB, $t0; blbc $t0, end; do: s8addq $i, $baseB, $t0; addq $i, $lengthA, $t1; s8addq $t1, $base, $t1; ldq $t0, ($t0); stq $t0, ($t1); continue: addq $i, 1; br while; end: } mov 16, $a0; bsr Memory.allocate.enter; addq $lengthA, $lengthB, $t0; stq $t0, 0($v0); stq $base, 8($v0); return: ldq $s5, sav5($sp); ldq $s4, sav4($sp); ldq $s3, sav3($sp); ldq $s2, sav2($sp); ldq $s1, sav1($sp); ldq $s0, sav0($sp); ldq $ra, savRA($sp); lda $sp, +sav6($sp); ret; } } }