home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / tpfast.zip / FASTBIT.ASM < prev    next >
Assembly Source File  |  1990-09-26  |  7KB  |  153 lines

  1. ;   _______________________________________________________________
  2. ;  |                                                               |
  3. ;  |            Copyright (C) 1989,1990  Steven Lutrov             |
  4. ;  |_______________________________________________________________|____
  5. ;  |                                                               |    |
  6. ;  |  Program Title : FastBit.Asm                                  |    | ___
  7. ;  |  Author        : Steven Lutrov                                |    |    |
  8. ;  |  Revision      : 2.01                                         |    |    |
  9. ;  |  Date          : 1990-03-16                                   |    |    |
  10. ;  |  Language      : Turbo  Assembler                             |    |    |
  11. ;  |                                                               |    |    |
  12. ;  |  Description   : Assembly Functions For Bit Mannipulation.    |    |    |
  13. ;  |                : Tested with Turbo Pascal Ver 5.0 5.5         |    |    |
  14. ;  |                                                               |    |    |
  15. ;  |_______________________________________________________________|    |    |
  16. ;      |                                                                |    |
  17. ;      |________________________________________________________________|    |
  18. ;          |                                                                 |
  19. ;          |_________________________________________________________________|
  20. ;
  21.  
  22.  
  23. Code    Segment Word  Public
  24.  
  25. Assume  Cs:Code
  26.  
  27.  
  28. Public  Bytetohex,Rotatebyteleft,Rotatewordleft,Rotatebyteright
  29. Public  Rotatewordright,Wordtohex
  30.  
  31.  
  32. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  33. ;Function Bytetohex(Work_: Byte): Stype;
  34. ;
  35. ;
  36. Bytetohex Proc Far
  37.                 Push Bp                         ;Save Bp
  38.                 Mov  Bp,Sp                      ;Set Stack Frame
  39.                 Les  Di,Dword Ptr[Bp+8]         ;Es:Di Pts To Return String
  40.                 Sub  Si,Si                      ;Si Counts Chars
  41.                 Mov  Bl,[Bp+6]                  ;Get The Value To Convert
  42.                 Mov  Cl,2                       ;String Length
  43.                 Mov  Es:[Di],Cl                 ;Set String Descriptor
  44.                 Shl  Cl,1                       ;Cl=4 Bits=One-Half Byte
  45. Bytetohex1:     Sub  Bh,Bh                      ;Clear Bh
  46.                 Shl  Bx,Cl                      ;Shift In One-Half Byte
  47.                 Cmp  Bh,10                      ;Is It '0' - '9'?
  48.                 Jl   Bytetohex2                 ;If Not, Jump Ahead
  49.                 Add  Bh,55                      ;10+55 = 'A', Etc...
  50.                 Jmp  Short Bytetohex3           ;Jmp Ahead
  51. Bytetohex2:     Add  Bh,48                      ;0+48 = '0', Etc...
  52. Bytetohex3:     Inc  Di                         ;Pt To Next Byte Of Strx
  53.                 Mov  Es:[Di],Bh                 ;Place Char In The Strx
  54.                 Inc  Si                         ;Test Char Counter
  55.                 Cmp  Si,2                       ;End Of String?
  56.                 Jne  Bytetohex1                 ;Jump If Not
  57.                 Pop  Bp                         ;Restore Bp
  58.                 Ret  2
  59. Bytetohex Endp
  60.  
  61.  
  62.  
  63. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  64. ;Function Rotatewordleft(Work_: Word; Bits_: Byte): Word;
  65. ;
  66. ;
  67. Rotatewordleft Proc Far
  68.                 Mov  Bx,Sp                      ;Set Stack Frame
  69.                 Mov  Cl,Ss:[Bx+4]               ;Number Of Bits To Rotate
  70.                 Mov  Ax,Ss:[Bx+6]               ;Get The Integer
  71.                 Rol  Ax,Cl                      ;Make The Rotation
  72.                 Ret  4
  73. Rotatewordleft Endp
  74.  
  75.  
  76. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  77. ;Function Rotatebyteright(Work_,Bits_: Byte): Byte;
  78. ;
  79. ;
  80. Rotatebyteright Proc Far
  81.                 Mov  Bx,Sp                      ;Set Stack Frame
  82.                 Mov  Cl,Ss:[Bx+4]               ;Number Of Bits To Rotate
  83.                 Mov  Al,Ss:[Bx+6]               ;Get The Byte
  84.                 Ror  Al,Cl                      ;Make The Rotation
  85.                 Ret  4
  86. Rotatebyteright Endp
  87.  
  88. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  89. ;Function Rotatebyteleft(Work_,Bits_:Byte): Byte;
  90. ;
  91. ;
  92. Rotatebyteleft Proc Far
  93.                 Mov  Bx,Sp                      ;Set Stack Frame
  94.                 Mov  Cx,Ss:[Bx+4]               ;Number Of Bits To Rotate
  95.                 Mov  Al,Ss:[Bx+6]               ;Get The Byte
  96.                 Rol  Al,Cl                      ;Make The Rotation
  97.                 Ret  4
  98. Rotatebyteleft Endp
  99.  
  100.  
  101. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  102. ;Function Rotatewordright(Work_: Word; Bits_: Byte): Word;
  103. ;
  104. ;
  105. Rotatewordright Proc Far
  106.                 Mov  Bx,Sp                      ;Set Stack Frame
  107.                 Mov  Cl,Ss:[Bx+4]               ;Number Of Bits To Rotate
  108.                 Mov  Ax,Ss:[Bx+6]               ;Get The Integer
  109.                 Ror  Ax,Cl                      ;Make The Rotation
  110.                 Ret  4
  111. Rotatewordright Endp
  112.  
  113.  
  114.  
  115. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  116. ;Function Wordtohex(Work_: Word): Stype;
  117. ;
  118. ;
  119. Wordtohex Proc Far
  120.                 Push Bp                         ;Save Bp
  121.                 Mov  Bp,Sp                      ;Set Stack Frame
  122.                 Les  Di,Dword Ptr[Bp+8]         ;Es:Di Pts To Return String
  123.                 Sub  Si,Si                      ;Si Counts Chars
  124.                 Mov  Ax,[Bp+6]                  ;Get The Value To Convert
  125.                 Mov  Cl,4                       ;Shifts One-Half Byte
  126.                 Mov  Es:[Di],Cl                 ;Set String Descriptor
  127.                 Mov  Bl,Ah                      ;Start With High Byte
  128. Wordtohex1:     Sub  Bh,Bh                      ;Clear Bh
  129.                 Shl  Bx,Cl                      ;Shift In One-Half Byte
  130.                 Cmp  Bh,10                      ;Is It '0' - '9'?
  131.                 Jl   Wordtohex2                 ;If Not, Jump Ahead
  132.                 Add  Bh,55                      ;10+55 = 'A', Etc...
  133.                 Jmp  Short Wordtohex3           ;Jmp Ahead
  134. Wordtohex2:     Add  Bh,48                      ;0+48 = '0', Etc...
  135. Wordtohex3:     Inc  Di                         ;Pt To Next Byte Of Strx
  136.                 Mov  Es:[Di],Bh                 ;Place Char In The Strx
  137.  
  138.                 Inc  Si                         ;Test Char Counter
  139.                 Test Si,1                       ;Is Strx Ctr Odd Or Even?
  140.                 Jnz  Wordtohex1                 ;Do 2Nd Half Char If Odd
  141.                 Cmp  Si,2                       ;Another Byte To Do?
  142.                 Jne  Wordtohex4                 ;Jump If Not
  143.                 Mov  Bl,Al                      ;Fetch Low Byte
  144.                 Jmp  Short Wordtohex1           ;Start Over On 2Nd Byte
  145. Wordtohex4:     Pop  Bp                         ;Restore Bp
  146.                 Ret  2
  147. Wordtohex Endp
  148.  
  149.  
  150. Code    Ends
  151.         End
  152.  
  153.