inline assembly question

This is a discussion on inline assembly question within the C++ Programming forums, part of the General Programming Boards category; How would you go about using a C style string in inline assembly? I have been working on this for ...

  1. #1
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738

    inline assembly question

    How would you go about using a C style string in inline assembly?

    I have been working on this for quite awhile now...but cant get it to work...here is my code, its not long:

    Code:
    #include <iostream.h>
    #include <conio.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    char string[20];
    
    int main (void)
    {
    	memset(string, 0, 20);      
       asm {
       	mov dx, seg string
          mov ds, dx
          lea dx, string
          mov ah, 0Ah
          int 21h
       }
    
       printf("%s", string);
    
       getch();
       return 0;
    }
    It is supposed to input a string, then print it, wait for a keypress, and exit..

    however, it is not inputting, just going straight to the getch()...anybody good with inline assembly around here that could help out?
    My Website

    "Circular logic is good because it is."

  2. #2
    Budding Synth Programmer samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Trefforest
    Posts
    368
    Well, looks fine to me, but then again my assembler is a bit rusty.
    MSVC++ 6.0

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    string should be unsigned char

    also you are not pushing DS - therefore your program will probably crash.

    if you alter DS inside of C or assembly you must push it's current value so you can restore it later

    Your code will cause system instability next time you try to access something in your data segment.

  4. #4
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    You could ditch the DOS interupts and call the c functions (so it would have a tiny bit more portability) -

    Code:
    char n[20];
    char format[] ="%s";
    
    int main()
    {
        
        __asm{
            lea eax,n
            lea ebx,format
            push eax
            push ebx
            call scanf
            add esp,8     
        }
    
        printf(format,n);
        
    
        return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I need help to compile this code...
    By wise_ron in forum C Programming
    Replies: 17
    Last Post: 05-07-2006, 12:22 PM
  2. inline assembly
    By seizmic in forum C++ Programming
    Replies: 8
    Last Post: 09-30-2005, 09:21 AM
  3. Inline assembly
    By ^xor in forum C Programming
    Replies: 13
    Last Post: 07-05-2005, 06:32 AM
  4. inline assembly in dev-cpp
    By variable in forum C Programming
    Replies: 4
    Last Post: 02-16-2005, 09:27 PM
  5. Inline Assembly?
    By AlenM in forum C++ Programming
    Replies: 5
    Last Post: 12-07-2001, 11:08 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21