LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   A problem. When using assembly language to call the C language function (https://www.linuxquestions.org/questions/programming-9/a-problem-when-using-assembly-language-to-call-the-c-language-function-4175520939/)

mirage1993 10-03-2014 05:49 AM

A problem. When using assembly language to call the C language function
 
I use assembly language to call the C language function.And I have a problem.

main.s
Code:

.section .data
a:
        .int 10
b:
        .int 20
.section .text
.globl main
.type main,@function
main:
        movl $a,%eax
        movl $b,%ebx
        pushl %ebx
        pushl %eax
        call _swapint
        movl $1,%eax
        movl $0,%ebx
        int $0x80

pro.c
Code:

#include<stdio.h>
int _swapint(int *a,int *b)
{
int c;
printf("!!!");
c=*a;
*a=*b;
*b=c;
printf("success!");
return 0;
}

I am sure that the value of a and b have been swapped,but I can't see any output! I can't understand.

thx.

mirage1993 10-03-2014 07:24 AM

when I use
Code:

puts("success");
It's OK!
but,why??

Guttorm 10-03-2014 07:42 AM

It's because puts adds a newline, and stdout is line buffered, so you don't see anything until you output a newline.

mirage1993 10-03-2014 08:15 AM

Quote:

Originally Posted by Guttorm (Post 5248436)
It's because puts adds a newline, and stdout is line buffered, so you don't see anything until you output a newline.

thank you very much!!


All times are GMT -5. The time now is 09:47 PM.