KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q52139: Accessing Strings from Local (Stack) Pointers with _asm

Article: Q52139
Product(s): See article
Version(s): 2.00 2.01
Operating System(s): MS-DOS
Keyword(s): ENDUSER | s_quickasm | mspl13_c
Last Modified: 17-JAN-1990

To access strings and other variables through auto pointers using the
_asm keyword, WORD PTR should be used in place of OFFSET. The WORD PTR
keyword will access the memory pointed to by the operand of the WORD
PTR. This results in the desired indirection. See the program example
below

Program Example
---------------

/* STRING.C -- compile with /AS (small memory model)
/* Notice the added \r and $ are added for int 21  */

char string_var1[] = "This is string 1\r\n$" ;

void main ( void )
{
  char *string_var2 = "This is string 2\r\n$" ;
  _asm {
    push dx

    mov dx, word ptr string_var2
    mov ah, 09h
    mov al, 00h
    int 21h

; Notice that offset is used properly below (with the array).
; In the case of *string_var1 (instead of string_var1[]),
; word ptr should again be used as above.
    mov dx, offset string_var1 ;
    mov ah, 09h
    mov al, 00h
    int 21h

    pop dx
  }
}

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1986-2002.