From: Wu Zhangjin <wuzhangjin@gmail.com>
To: adnan iqbal <adnan.iqbal@seecs.edu.pk>
Cc: linux-mips@linux-mips.org
Subject: Re: MIPS/Linux assembly issue
Date: Fri, 21 May 2010 20:30:01 +0800 [thread overview]
Message-ID: <1274445001.9403.5.camel@localhost> (raw)
In-Reply-To: <AANLkTikrUGzUykZJwoK3Jq9mEJa6l35jo5DXHae3vbIG@mail.gmail.com>
Hi,
Just found Arnaud have explained the problems, so here give you an
example I have written one year ago:
# File: hello.s -- Say Hello to MIPS Assembly Language Programmer
# Author: falcon <wuzhangjin@gmail.com>, 2009/01/17
# Ref:
# [*] http://www.tldp.org/HOWTO/Assembly-HOWTO/mips.html
# [*] MIPS Assembly Language Programmer's Guide
# [*] See MIPS Run Linux(second version)
# Compile:
# $ gcc -o hello hello.s
# or
# $ as -o hello.o hello.s
# $ ld -e main -o hello hello.o
.text
.globl main
main:
.set noreorder
.cpload $gp # setup the pointer to global data
.set reorder
# print sth. via sys_write
li $a0, 1 # print to standard ouput
la $a1, stradr # set the string address
lw $a2, strlen # set the string length
li $v0, 4004 # index of sys_write:
# __NR_write in /usr/include/asm/unistd.h
syscall # causes a system call trap.
# exit via sys_exit
move $a0, $0 # exit status as 0
li $v0, 4001 # index of sys_exit
# __NR_exit in /usr/include/asm/unistd.h
syscall
.rdata
stradr: .asciiz "hello, world!\n"
strlen: .word . - stradr # current address - the string address
# end
Regards,
Wu Zhangjin
On Fri, 2010-05-21 at 16:46 +0500, adnan iqbal wrote:
> Hi all,
>
> I am trying to compile/link/execute following very simple program in
> debian/MIPS (Tried on Qemu and Octeon). I am getting errors while
> executing the program. gdb also shows a strange behavior showing
> program entrypoint somehere in data segement. Any help getting this
> sorted out shall be appreciated.
>
> Regards
> Adnan
>
> Commands used to compile/link
> ----------------------------------------------------
> $ as hello.s -o hello.o
> $ld hello.o -o hello
> $ ./hello
>
>
> The code
> ---------------
> .data
> str:
> .asciiz "hello world\n"
> .text
> .globl __start
>
> __start:
> jal f2
> la $4,str
> li $2,4
> syscall
>
> ## terminate program via _exit () system call
> li $2, 10
> syscall
> f2:
> add $8,$8,$0
> jr $31
>
next prev parent reply other threads:[~2010-05-21 12:30 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-21 11:46 MIPS/Linux assembly issue adnan iqbal
2010-05-21 12:21 ` Arnaud Patard
2010-05-21 12:30 ` Wu Zhangjin [this message]
2010-05-25 5:33 ` adnan iqbal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1274445001.9403.5.camel@localhost \
--to=wuzhangjin@gmail.com \
--cc=adnan.iqbal@seecs.edu.pk \
--cc=linux-mips@linux-mips.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox