Tuesday, March 2, 2010

Hello World - Assembly Language (ARM 920T)

This is a "Hello World" program written in pure assembly language on Linux/ARM 920T platform.

1 #
2 # Makefile for Hello World on Linux/ARM 920T platform
3 #
4 all:
5 arm-linux-as hello.s -o hello.o
6 arm-linux-ld hello.o -o hello
7
8 clean:
9 rm -rf hello hello.o

1
2 .text
3 .global _start
4 _start:
5
6 mov r0, #1
7 adr r1, msg
8 mov r2, #14
9 swi 0x00900004
10
11 mov r0, #0
12 swi 0x00900001
13
14 msg: .asciz "Hello World\n"

Result...

$ uname -a
Linux ARM 2.6.11.1armzone_linux2.6 #6 Fri Dec 12 12:12:23 CST 2008 armv4tl unknown
$ ./hello
$
Hello World
$

Of Linux on ARM 920T CPU...
  • The Linux kernel entry, from user mode application into kernel mode, is triggled by swi (0x00900001 or index) instrusion.
  • The system call number is got from the low byte of swi parameter (swi 0x009000XX).
  • The system call parameter is placed in the sequence of r0, r1, r2...

    In the example of the WRITE() system call

    ssize_t write (int __fd, __const void *__buf, size_t __n);
  • The system call index (g1) is 0x04 (swi 0x00900004)
  • __fd is r0
  • __buf is r1
  • __n is r2
  • No comments:

    Post a Comment