LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-26-2017, 05:55 PM   #1
Vido
Member
 
Registered: Mar 2014
Posts: 38

Rep: Reputation: Disabled
Simple HelloWorld.S does not print anything to console


Im trying to crosscompile simple helloworld.s written in assembly on MIPS platform, I found simple example here and here is mine simple program

Quote:
/*
* hello-1.2/Makefile
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file "COPYING" in the main directory of this archive
* for more details.
*
* Copyright (C) 1995, 1997 by Ralf Baechle
*/
#include <regdef.h>
#include <sys/asm.h>
#include <sys/syscall.h>

#define O_RDWR 02

EXPORT(__start)


.set noreorder
LEAF(main)

# fd = open("/dev/tty1", O_RDWR, 0);
la a0,tty
li a1,O_RDWR
li a2,0
li v0,SYS_open
syscall

bnez a3,quit
move s0,v0 # delay slot

# write(fd, "hello, world.\n", 14);
move a0,s0
la a1,hello
li a2,14
li v0,SYS_write
syscall

# close(fd);
move a0,s0
li v0,SYS_close
syscall

quit:
li a0,0
li v0,SYS_exit
syscall

j quit
nop

END(main)

.data
tty: .asciz "/dev/tty1"
hello: .ascii "Hello, world.\n"
and here is mine make file

Code:
#
# hello-1.2/Makefile
#
# This file is subject to the terms and conditions of the GNU General Public
# License. See the file COPYING in the main directory of this archive for more
# details.

tool-prefix	= mips-linux-gnu-

CC		= $(tool-prefix)gcc -I /home/slobodan/rtl819x-toolchain/toolchain/rsdk-1.5.5-5281-EB-2.6.30-0.9.30.3-110714/include/sys/
LD		= $(tool-prefix)ld
STRIP		= $(tool-prefix)strip

CFLAGS		= -G0 -mno-abicalls -fno-pic
LDFLAGS		= -N -s

all:		hello

hello:		hello.o
		$(LD) $(LDFLAGS) -o hello hello.o

hello.o:	hello.S
		$(CC) $(CFLAGS) -c hello.S

clean:
		rm -f core a.out *.o *.s

distclean:	clean
		rm -f hello
program does compile but when I run it I get nothing as output. I did tried mips-linux-gnu-gcc and
Code:
mips-linux-gcc
from Realtek SDK but its same deal does not print hello world to console.
I also tried changing
Code:
SYS_write
to
Code:
__NR_write
and
Code:
SYS_close
to
Code:
__NR_close
but again its same deal I dont get anything printed to console. As emulator I used qemu-mips-static and my mips box (its actually MIPS router)
 
Old 03-26-2017, 07:17 PM   #2
Soitgoes
Member
 
Registered: Oct 2016
Location: Beyond Thunderdome
Distribution: Gentoo
Posts: 67

Rep: Reputation: Disabled
Have you tried to track your registers? Perhaps the branch not equal to zero is being taken and the program quits prematurely before 'hello world' is loaded and called.

Regards
 
Old 03-30-2017, 12:05 PM   #3
Vido
Member
 
Registered: Mar 2014
Posts: 38

Original Poster
Rep: Reputation: Disabled
Yes I did track of whats going on and syscall is called but its nothing printed to stdout
 
  


Reply

Tags
assembly, compiling


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
How to print from console with LPR? Xeratul Linux - General 3 12-31-2010 12:36 AM
How to print a message from kernel module to terminal console or tty console yogesh_bansal Linux - Newbie 2 02-27-2009 09:10 AM
How to print in the console ? Volcano Programming 1 05-27-2008 03:15 AM
How to enable console_print() to print to console? pat_and_cami Programming 1 04-17-2006 11:17 PM
print a man page in console?? mipia Slackware 2 08-25-2003 12:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:22 AM.

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