home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / coding / dsp / c30ug.exe / $MULAW.ASM < prev    next >
Encoding:
Assembly Source File  |  1988-06-25  |  3.2 KB  |  99 lines

  1. ;**************************************************************
  2. ;  
  3. ;                 $mulaw.asm
  4. ;  
  5. ;                 staff
  6. ;  
  7. ;                 06-25-88
  8. ;  
  9. ;           (C) Texas Instruments Inc., 1992 
  10. ;  
  11. ;           Refer to the file 'license.txt' included with this 
  12. ;           this package for usage and license information. 
  13. ;  
  14. ;**************************************************************
  15. Example 26.  u-law compression
  16. ;
  17. ;==============================================================================
  18. ;    SUBROUTINE   MUCMPR
  19. ;
  20. ;
  21. ; ARGUMENT ASSIGNMENTS:
  22. ;   argument | function
  23. ;   ---------+-----------------------
  24. ;   R0       | number to be converted
  25. ;
  26. ; REGISTERS USED AS INPUT: R0
  27. ; REGISTERS MODIFIED: R0, R1, R2, SP
  28. ; REGISTER CONTAINING RESULT: R0
  29. ;
  30. ; NOTE: Since the stack pointer SP is used in the compression routine
  31. ;       MUCMPR, make sure to inititalize it in the calling program.
  32. ;
  33. ;
  34. ;       CYCLES: 20      WORDS: 17
  35. ;=============================================================================
  36. ;
  37.         .global     MUCMPR
  38. ;
  39. MUCMPR    LDI       R0,R1          ; Save sign of number
  40.           ABSI      R0,R0
  41.           CMPI      1FDEH,R0       ; If R0>0x1FDE,
  42.           LDIGT     1FDEH,R0       ;    saturate the result       
  43.           ADDI      33,R0          ; Add bias
  44.  
  45.           FLOAT     R0             ; Normalize: (seg+5)0WXYZx...x
  46.           MPYF      0.03125,R0     ; Adjust segment number by 2^-5
  47.           LSH       1,R0           ; (seg)WXYZx...x
  48.           PUSHF     R0
  49.           POP       R0             ; Treat number as integer
  50.           LSH       -20,R0         ; Right-justify
  51.  
  52.           LDI       0,R2
  53.           LDI       R1,R1          ; If number is negative,
  54.           LDILT     80H,R2         ;    set sign bit
  55.           ADDI      R2,R0          ; R0 = compressed number
  56.           NOT       R0             ; Reverse all bits for transmission
  57.           RETS
  58.  
  59.  
  60.  
  61.  
  62. Example 27.  u-law expansion
  63. ;          
  64. ;==============================================================================
  65. ;    SUBROUTINE   MUXPND
  66. ;
  67. ;
  68. ; ARGUMENT ASSIGNMENTS:
  69. ;   argument | function
  70. ;   ---------+-----------------------
  71. ;   R0       | number to be converted
  72. ;
  73. ; REGISTERS USED AS INPUT: R0
  74. ; REGISTERS MODIFIED: R0, R1, R2, SP
  75. ; REGISTER CONTAINING RESULT: R0
  76. ;
  77. ;
  78. ;       CYCLES: 20 (worst case)         WORDS: 14
  79. ;=============================================================================
  80. ;
  81.           .global   MUXPND
  82. ;
  83. MUXPND    NOT       R0,R0          ; Complement bits
  84.           LDI       R0,R1
  85.           AND       0FH,R1         ; Isolate quantization bin
  86.           LSH       1,R1
  87.           ADDI      33,R1          ; Add implied 1 and rounding bit
  88. ;                                       to introduce 1xxxx1
  89.           LDI       R0,R2          ; Store for sign bit
  90.           LSH       -4,R0
  91.           AND       7,R0           ; Isolate segment code
  92.           LSH3      R0,R1,R0       ; Shift and put result in R0
  93.           SUBI      33,R0          ; Subtract bias
  94.           TSTB      80H,R2         ; Test sign bit
  95.           RETSZ
  96.           NEGI      R0             ; Negate if a negative number
  97.           RETS
  98.  
  99.