/* This C language subroutine performs A-Law compression on the integer input data. The Run Time Library for the C Language. Gordon A. Sterling (617) 461 - 3076 DSP Development Tools Engineering Created on 5/19/90 Updated on 5/94 by AS #include
int a_compress(int x); int a_expand(int x); */ #include "lib_glob.h" #include "com_glob.h" .SEGMENT/CODE Code_Space_Name; .FILE RTL_FILENAME; .GLOBAL _a_expand, _a_compress; _a_compress: R0=ABS R4; /*Take absolute value */ R1=4095; /*Maximum PCM value */ R0=MIN(R0,R1); /*Cap input */ R2=LSHIFT R0 BY -1; /*Prepare for possible zero seg */ R1=31; /*Check for zero segment */ COMP(R0,R1); IF LE JUMP (PC, sign_invert); /*Append sign and invert bits */ R1=EXP R0; /*Find exponent adjustment */ R1=-R1; R0=ASHIFT R0 BY R1; /*Normalize input */ R0=BCLR R0 BY 30; /*Remove first significant bit */ R0=LSHIFT R0 BY -26; /*Shift position bits */ R2=26; R1=R2-R1, R2=R0; /*Compute segment */ R2=R2 OR LSHIFT R1 BY 4; /*Position segment bits */ sign_invert: R4=PASS R4; /*Append the sign bit and invert*/ IF GE R2=BSET R2 BY 7; JUMP (PC, restore_state) (DB); R1=0x55; R0=R2 XOR R1, FETCH_RETURN /*Invert bits */ _a_expand: R12=0xFF; /*Mask unwanted bits */ R1=R4 AND R12, R0=R4; R12=0x55; /*Invert odd bits */ R1=R12 XOR R1; /*Invert bits */ R8=LSHIFT R1 BY -4; /*Isolate segment */ R8=BSET R8 BY 3; /*Always set sign bit */ R12=32; R2=9; R8=R8-R2, FETCH_RETURN /*Determine sight value */ IF LT R12=R12-R12; /*Don't OR MSB bit */ IF EQ R8=R8-R8; /*No less then zero bits */ R2=LSHIFT R1 BY 28; /*Isolate interval */ R2=BSET R2 BY 27; /*Set LSB of interval */ R2=LSHIFT R2 BY -27; /*Shift interval into bottom */ R2=R2 OR LSHIFT R12 BY 0;/*Add MSB if necessary */ R0=LSHIFT R2 BY R8, R2=R4;/*Position interval */ BTST R2 BY 7; /*Check sign of input */ IF SZ R0=-R0; /*Invert output */ restore_state: RETURN (DB); RESTORE_STACK RESTORE_FRAME .ENDSEG;