block String { // char *fromChar( char c ) { // static char buffer[ 2 ]; // buffer[ 0 ] = c; // buffer[ 1 ] = NULL; // return buffer; // } public block fromChar uses proc { data { align; buffer: ubyte[ 2 ]; align; } data code { public enter: body: ldiq $t0, buffer; stb $a0, 0($t0); stb $zero, 1($t0); mov $t0, $v0; return: ret; } code } block fromChar // int compare( char *s, char *t ) { // while ( *s == *t && *s != 0 ) { // s++; // t++; // } // return *s - *t; // } public block compare uses proc { abs { s = a0; t = a1; } abs code { public enter: body: { while: ldbu $t0, ($s); ldbu $t1, ($t); cmpeq $t0, $t1, $t2; blbc $t2, end; beq $t0, end; do: addq $s, 1; addq $t, 1; br while; end: } subq $t0, $t1, $v0; return: ret; } code } block compare // int length( char *s ) { // int len = 0; // while ( *s != 0 ) { // len++; // s++; // } // return len; // } public block length uses proc { abs { s = a0; len = s0; } abs code { public enter: lda $sp, -sav1($sp); stq $ra, savRet($sp); stq $s0, sav0($sp); body: { for: clr $len; while: ldbu $t0, ($s); beq $t0, end; do: addq $len, 1; addq $s, 1; continue: br while; end: } mov $len, $v0; return: ldq $s0, sav0($sp); ldq $ra, savRet($sp); lda $sp, +sav1($sp); ret; } code } block length // char *copy( char *s, char *t ) { // while ( ( *s = *t ) != 0 ) { // s++; // t++; // } // return s; // } public block copy uses proc { abs { s = a0; t = a1; } abs code { public enter: body: { while: ldbu $t0, ($t); stb $t0, ($s); beq $t0, end; do: addq $s, 1; addq $t, 1; continue: br while; end: } return: mov $s, $v0; ret; } code } block copy // #define MAXBUFFER 0x100 // char *padLeft( char *s, char padChar, int fieldWidth ) { // static char buffer[ MAXBUFFER + 1 ]; // int i; // int len = length( s ); // if ( len > fieldWidth ) // fieldWidth = len; // for ( i = 0; i < fieldWidth; i++ ) { // if ( i >= fieldWidth - len ) // buffer[ i ] = s[ i - fieldWidth + len ]; // else // buffer[ i ] = padChar; // } // buffer[ i ] = 0; // return buffer; // } public block padLeft uses proc { abs { MAXBUFFER = 0x100; s = s0; padChar = s1; fieldWidth = s2; i = s3; len = s4; } abs data { align; buffer: ubyte[ MAXBUFFER + 1 ]; align; } data code { public enter: lda $sp, -sav5($sp); stq $ra, savRet($sp); stq $s0, sav0($sp); stq $s1, sav1($sp); stq $s2, sav2($sp); stq $s3, sav3($sp); stq $s4, sav4($sp); init: mov $a0, $s; mov $a1, $padChar; mov $a2, $fieldWidth; body: mov $s, $a0; bsr length.enter; mov $v0, $len; { if: cmplt $len, $fieldWidth, $t0; blbs $t0, end; then: mov $len, $fieldWidth; end: } { for: clr $i; while: cmplt $i, $fieldWidth, $t0; blbc $t0, end; do: { subq $fieldWidth, $len, $t2; if: cmplt $i, $t2, $t0; blbs $t0, else; then: subq $i, $t2, $t2; addq $s, $t2, $t0; ldbu $t0, ($t0); ldiq $t1, buffer; addq $t1, $i; stb $t0, ($t1); br end; else: ldiq $t1, buffer; addq $t1, $i; stb $padChar, ($t1); end: } continue: addq $i, 1; br while; end: } ldiq $t1, buffer; addq $t1, $i; stb $zero, ($t1); ldiq $v0, buffer; return: ldq $s4, sav4($sp); ldq $s3, sav3($sp); ldq $s2, sav2($sp); ldq $s1, sav1($sp); ldq $s0, sav0($sp); ldq $ra, savRet($sp); lda $sp, +sav5($sp); ret; } code } block padLeft // #define MAXBUFFER 0x100 // char *padRight( char *s, char padChar, int fieldWidth ) { // static char buffer[ MAXBUFFER + 1 ]; // int i; // int len = length( s ); // if ( len > fieldWidth ) // fieldWidth = len; // for ( i = 0; i < fieldWidth; i++ ) { // if ( i < len ) // buffer[ i ] = s[ i ]; // else // buffer[ i ] = padChar; // } // buffer[ i ] = 0; // return buffer; // } public block padRight uses proc { abs { MAXBUFFER = 0x100; s = s0; padChar = s1; fieldWidth = s2; i = s3; len = s4; } abs data { align; buffer: ubyte[ MAXBUFFER + 1 ]; align; } data code { public enter: lda $sp, -sav5($sp); stq $ra, savRet($sp); stq $s0, sav0($sp); stq $s1, sav1($sp); stq $s2, sav2($sp); stq $s3, sav3($sp); stq $s4, sav4($sp); init: mov $a0, $s; mov $a1, $padChar; mov $a2, $fieldWidth; body: mov $s, $a0; bsr length.enter; mov $v0, $len; { if: cmplt $len, $fieldWidth, $t0; blbs $t0, end; then: mov $len, $fieldWidth; end: } { for: clr $i; while: cmplt $i, $fieldWidth, $t0; blbc $t0, end; do: { if: cmplt $i, $len, $t0; blbc $t0, else; then: addq $s, $i, $t0; ldbu $t0, ($t0); ldiq $t1, buffer; addq $t1, $i; stb $t0, ($t1); br end; else: ldiq $t1, buffer; addq $t1, $i; stb $padChar, ($t1); end: } continue: addq $i, 1; br while; end: } ldiq $t1, buffer; addq $t1, $i; stb $zero, ($t1); ldiq $v0, buffer; return: ldq $s4, sav4($sp); ldq $s3, sav3($sp); ldq $s2, sav2($sp); ldq $s1, sav1($sp); ldq $s0, sav0($sp); ldq $ra, savRet($sp); lda $sp, +sav5($sp); ret; } code } block padRight } block String