home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 6 / FreshFish_September1994.bin / new / dev / c / hce / examples / clib / tests / asmtest.c next >
C/C++ Source or Header  |  1992-09-02  |  2KB  |  69 lines

  1. /*
  2.  * HCC asm() demonstration program by TetiSoft
  3.  */
  4.  
  5. /*
  6.  * Changed slightly by Jason Petty for HCE. (15/6/94)
  7.  * Changes marked VANSOFT.
  8.  */
  9.  
  10. void main();
  11. int AddByte();
  12.  
  13. int AddByte()
  14. {
  15.  /* HCC and TOP will add the following here:
  16.   * link a5,#0
  17.   * That means, our parameters are found relative to A5.
  18.   * The first parameter is found at 8(A5),
  19.   * the second at 12(A5), etc.
  20.   * Since HCC expands all parameters to 32 bit when -L is specified,
  21.   * we must NOT care if we GOT a char, short, int, long, signed or
  22.   * unsigned parameter. We only must care if we WANTED a byte, word
  23.   * or long value.
  24.   * A long value could be addressed as move.l  8(a5),d0
  25.   * A word value could be addressed as move.w 10(a5),d0
  26.   * A byte value could be addressed as move.b 11(a5),d0
  27.   * We are allowed to destroy d0,d1,d2,a0,a1,a6 and a7.
  28.   * We are not allowed to destroy d3-d7 and a2-a5.
  29.   * If we return something, it is expected in d0.
  30.   * We should not return via rts without an unlk a5,
  31.   * which restores a7.
  32.   */
  33.  
  34.  asm(" move.b 11(a5),d0");
  35.  asm(" add.b 15(a5),d0");
  36.  
  37.  /* HCC and TOP will add the following here:
  38.   * unlk a5  ; restore a7
  39.   * rts   ; return value in d0
  40.   */
  41. }
  42.  
  43. void main()
  44. {
  45.  char var1=1, var2=2;
  46.  
  47.  /* Changed lines below slightly. VANSOFT. */
  48.  printf(
  49.      "\n\nThis demonstration shows the use of the 'asm()' operator used\n");
  50.  printf("by the internal compiler HCC. It adds two variables together\n");
  51.  printf(
  52.      "using a function who's body was made with the 'asm()' operator and\n");
  53.  printf("can only add byte sized numbers, hence the name 'AddByte()'.\n\n");
  54.  
  55.  printf("Var1 = 1 and Var2 = 2:\n\n");
  56.  
  57.  printf("AddByte( (char)Var1, (char)Var2 ) = %d\n\n",
  58.          AddByte((char)var1,(char)var2));
  59.  
  60.  printf("AddByte( (short)Var1, (short)Var2 ) = %d\n\n", 
  61.          AddByte((short)var1,(short)var2));
  62.  
  63.  printf("AddByte( (long)Var1, (long)Var2 ) = %d\n\n", 
  64.          AddByte((long)var1,(long)var2));
  65.  
  66.  printf("See source code for how it works...\n\n\n");
  67. }
  68.  
  69.