Articles Hierarchy

Articles Home » RPI » ASM on RPI


no, i not want to learn ASM, but i remember i used it a little bit
in my first company when i play with our Z80 (NSC800) board on CPM
using turbo pascal with inline asm.

but i read some strange newbie question and the answers from the specialists here

so i just try to see the RPI environment.

add, i needed some source code start what works in RPI so i looked for tutorials
( after i failed with some internet examples ( must have been for other compilers.. ))
thinkingeek and

nano test.s
/* -- test.s */
.global main /* 'main' is our entry point and must be global */

main: /* This is main */
mov r0, #2 /* Put a 2 inside the register r0 */
bx lr /* Return from main */

as -o test.o test.s
gcc -o test test.o
./test ; echo $?

i like command files to remember that kind of things:
nano asm
# this filename: asm
# make executable with
# chmod +x asm
# and start with
# ./asm

# play with color in terminal window
WHTE='echo -e \E[37;44m' # white on blue background
BLUE='echo -e \E[47;34m' # blue on white background
MAGE='echo -e \E[47;35m' # magenta on white background
GRNE='echo -e \E[0;32m' # green on NO background
REDE='echo -e \E[47;31m' # red on white background
BLKE='echo -e \E[47;30m' # black on white background
BOLD='\033[1m' # and BOLD
END2='\033[0m' # end

# use file test.s as asm source file
# like edit with
CMDL='nano '$MYPROG'.s'
# nano test.s

# and compile it
#as test.s -o -g test.o
CMDL='as -o '$MYPROG'.o '$MYPROG'.s'

# and link it making program test
#ld test.o -o test
CMDL='gcc -o '$MYPROG' '$MYPROG'.o'

# or run with ./test
# or with ./test ; echo $?
CMDL='./'$MYPROG' ; echo $?'
#$CMDL not work
./$MYPROG ; echo $?

# and call gdb
MYTEXT='in GDB use "la r" for run '$MYPROG' in debug mode and step with "si" or "ni" or "quit" to en$
# gdb test
CMDL='gdb -q '$MYPROG

# and show dir
CMDL='ls -la'


chmod +x asm

pi@RPI3:~/projects/asm $ ./asm
as -o test.o test.s
gcc -o test test.o
./test ; echo $?
in GDB use "la r" for run test in debug mode and step with "si" or "ni" or "quit" to end gdb
gdb -q test
Reading symbols from test...(no debugging symbols found)...done.
(gdb) quit
ls -la
total 28
drwxr-xr-x 2 pi pi 4096 Mar 3 20:55 .
drwxr-xr-x 9 pi pi 4096 Mar 3 17:37 ..
-rwxr-xr-x 1 pi pi 1250 Mar 3 20:48 asm
-rwxr-xr-x 1 pi pi 8076 Mar 3 20:55 test
-rw-r--r-- 1 pi pi 640 Mar 3 20:55 test.o
-rw-r--r-- 1 pi pi 208 Mar 3 20:44 test.s
pi@RPI3:~/projects/asm $

next i play with
hello world example