LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-03-2014, 05:49 AM   #1
mirage1993
Member
 
Registered: Feb 2014
Location: China
Distribution: CentOS6.4
Posts: 51

Rep: Reputation: Disabled
Question 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.

Last edited by mirage1993; 10-03-2014 at 05:51 AM.
 
Old 10-03-2014, 07:24 AM   #2
mirage1993
Member
 
Registered: Feb 2014
Location: China
Distribution: CentOS6.4
Posts: 51

Original Poster
Rep: Reputation: Disabled
when I use
Code:
puts("success");
It's OK!
but,why??
 
Old 10-03-2014, 07:42 AM   #3
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,348

Rep: Reputation: 363Reputation: 363Reputation: 363Reputation: 363
It's because puts adds a newline, and stdout is line buffered, so you don't see anything until you output a newline.
 
1 members found this post helpful.
Old 10-03-2014, 08:15 AM   #4
mirage1993
Member
 
Registered: Feb 2014
Location: China
Distribution: CentOS6.4
Posts: 51

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Guttorm View Post
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!!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Assembly Language ashish anand Programming 9 10-18-2011 10:53 PM
assembly language ramorous24 Programming 4 08-21-2011 11:31 PM
Is Assembly Language considered a Structured Language? theKbStockpiler Programming 4 01-30-2011 09:09 AM
How to learn assembly language? darkangel29 Programming 8 01-12-2009 12:30 PM
assembly language in linux herbertgnanaraja Programming 12 09-21-2006 03:52 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration