7

i use devcpp and borland c compiler....

asm {
    mov ax,4       // (I/O Func.)
    mov bx,1       // (Output func)  
    mov cx,&name   // (address of the string)
    mov dx,6       // (length of the string)
    int 0x21       // system call
}

in the above code snippets i want to print a string with the help of assembly language... but how can i put the address of the string in register cx....

is there something wrong in code???

4
  • 0x21 - wow kudos for getting to basics :-) Commented Feb 1, 2010 at 18:58
  • How is the string being stored? i.e: What's the declaration of name?
    – GManNickG
    Commented Feb 1, 2010 at 19:20
  • 4
    I suggest to ignore the 16 bit real-mode assembler and directly start with 32 bit assembler. It's much easier and much more practical these days. Commented Feb 1, 2010 at 19:24
  • well thanx.... but is there any way to get the address of string and put back in the cx register... or have u ever tried inline assembly... i need just a little help...so i can start with asm... any example???
    – vs4vijay
    Commented Feb 2, 2010 at 12:57

2 Answers 2

4

I don't have the Borland compiler on hand, so I might be misremembering its syntax, but have you tried this:

asm {
    mov ax,4       // (I/O Func.)
    mov bx,1       // (Output func)  
    lds cx,"Hello, world" // (address of the string)
    mov dx,6       //  (length of the string)
    int 0x21       // system call
}

or this:

char msg[] = "Hello, world";

asm {
    mov ax,4       // (I/O Func.)
    mov bx,1       // (Output func)  
    lds cx, msg   // (address of the string)
    mov dx,6       //  (length of the string)
    int 0x21       // system call
}

edit: although this will compile (now that I've changed MOV to LDS), it will still throw an error at runtime. I'll try again...

3
  • 1
    no it doesnt work... it gives error........ is there any other way by which i can get the address of string..and put then back to the cx register....
    – vs4vijay
    Commented Feb 2, 2010 at 12:55
  • As far I know, mov cx,msg put msg's address into cx register. What are you getting?
    – Jack
    Commented Mar 23, 2013 at 17:51
  • 1
    @vs4vijay You shouldn't accept not working solution as an answer because it is missleading.
    – ST3
    Commented Jul 30, 2014 at 12:48
2

Just put the variable name in there:

mov ax,4       // (I/O Func.)
mov bx,1       // (Output func)  
mov cx,name   // (address of the string)
mov dx,6       //  (lenght of the string)
int 0x21       // system call

Disclaimer: I'm not too good at assembly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.