home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c081_11 / 9.ddi / CHAPXMPL.ZIP / SQRTBLE2.C < prev    next >
Encoding:
Text File  |  1991-02-13  |  890 b   |  24 lines

  1. // Turbo Assembler    Copyright (c) 1988, 1991 By Borland International, Inc.
  2.  
  3. // SQRTBLE2.C - Example of inline assembler code
  4.  
  5. // From the Turbo Assembler Users Guide - Interfacing Turbo Assembler
  6. //                                         with Borland C++
  7.  
  8. /* Function to look up the square of a value between 0 and 10 */
  9. int LookUpSquare(int Value)
  10. {
  11.    asm  jmp  SkipAroundData /* jump past the data table */
  12.  
  13.    /* Table of square values */
  14.    asm  SquareLookUpTable  label  word;
  15.    asm  dw  0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100;
  16.  
  17. SkipAroundData:
  18.    asm  mov  bx,Value;   /* get the value to square */
  19.    asm  shl  bx,1;       /* multiply it by 2 to look up in */
  20.                          /* a table of word-sized elements */
  21.    asm  mov  ax,[SquareLookUpTable+bx]; /* look up the square */
  22.    return(_AX);                         /* return the result */
  23. }
  24.