home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / os / msdos / programm / 8977 < prev    next >
Encoding:
Text File  |  1992-09-01  |  3.3 KB  |  113 lines

  1. Path: sparky!uunet!uunet.ca!canrem!dosgate![gord.armstrong@canrem.com]
  2. From: "gord armstrong" <gord.armstrong@canrem.com>
  3. Newsgroups: comp.os.msdos.programmer
  4. Subject: ass'y gurus
  5. Message-ID: <1992Sep2.1478.12907@dosgate>
  6. Date: 2 Sep 92 00:18:27 EST
  7. Reply-To: "gord armstrong" <gord.armstrong@canrem.com>
  8. Distribution: comp
  9. Organization: Canada Remote Systems
  10. Lines: 101
  11.  
  12.  
  13. Segments ARRRG!
  14.  
  15. 'C' Compiler: Microsoft C 6.0, Assembler: TASM 2.0
  16.  
  17. I'm linking a 'C' and assembler prog together in DOS, and I need
  18. to pass a pointer from a C prog to an assembler proc. For a SMALL
  19. model this is not much of a problem since code and data are in the
  20. same segment, as follows:
  21.  
  22.   char *ptr; // will use in other modules, make it global
  23.  
  24. main()
  25. {
  26.   ptr=malloc((unsigned int)1024); *ptr=0x55;
  27.   get_value();  // call ass'y routine
  28.   free(ptr);
  29. }
  30.  
  31.  
  32. DOSSEG
  33. .MODEL SMALL
  34.                 public  _get_value:proc
  35. .DATA
  36.                 extrn   _ptr:word
  37. other_var       db  ?
  38. .CODE
  39. ;--------------------------------------------------------
  40. ; _get_value
  41. ;--------------------------------------------------------
  42. _get_value      proc
  43.                 procin              ;save stuff for 'C'
  44.                 mov     bx,word ptr _ptr
  45.                 mov     al,[bx]
  46.                 xor     ah,ah
  47.                 call    to_integer  ;get '55' as set in main()
  48.                 procout             ;restore stuff for 'C'
  49.                 ret
  50. _get_value      endp
  51.  
  52. For a LARGE model, I can't seem to find a way or a keyword to
  53. do it neatly. A 'malloc' in the large model has 'ptr' pointing
  54. to another segment. I can make it work doing the following:
  55.  
  56.   char far *_ptr;
  57.   unsigned int ptr_seg,ptr_off;
  58.  
  59. main()
  60. {
  61.   ptr=malloc((unsigned int)1024); *ptr=0x55;
  62.  
  63.   ptr_seg=FP_SEG(ptr); ptr_off=FP_OFF(ptr);
  64.  
  65.   get_value();  // call ass'y routine
  66.   free(ptr);
  67. }
  68.  
  69. DOSSEG
  70. .MODEL LARGE
  71.                 public  _get_value:proc
  72. .FARDATA
  73.                 extrn   _ptr_seg:word
  74.                 extrn   _ptr_off:word
  75. .DATA
  76. other_var       db  ?
  77. .CODE
  78. ;--------------------------------------------------------
  79. ; _get_value
  80. ;--------------------------------------------------------
  81. _get_value      proc
  82.                 procin                ;save stuff for 'C'
  83.                 assume  ds:@FARDATA   ;FAR for large model
  84.                 mov     ax,@FARDATA
  85.                 mov     ds,ax         ;...is now our DS
  86.                 mov     es,_ptr_seg
  87.                 mov     bx,_ptr_off
  88.  
  89.                 assume  ds:@DATA      ;put back DS for 'other_var'
  90.                 mov     ax,@DATA
  91.                 mov     ds,ax
  92.  
  93.                 mov     al,es:[bx]    ;get '55' as set in main()
  94.                 xor     ah,ah
  95.                 call    to_integer
  96.                 procout             ;restore stuff for 'C'
  97.                 ret
  98. _get_value      endp
  99.  
  100. It works, but it looks messy, is there a neater way of doing this?
  101. If I use OS/2, I won't have this problem since it uses protected
  102. mode...right?
  103.  
  104. All help appreciated!
  105. ---------------------------------------------------------------------
  106. gord.armstrong@canremote.com   "If you blow chunks and she comes
  107.                                 back, she's yours. If you spew and
  108.                                 she bolts, it was never meant to be"
  109.                                 - Wayne's World
  110. --
  111. Canada Remote Systems  - Toronto, Ontario/Detroit, MI
  112. World's Largest PCBOARD System - 416-629-7000/629-7044
  113.