Mar 03 2018
ASM on RPI
no, i not want to learn ASM, but i remember i used it a little bitin 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 science.smith.edu
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 */
.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
#!/bin/bash
# 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
MYTEXT=''
CMDL=''
MYPROG='test'
# use file test.s as asm source file
# like edit with
CMDL='nano '$MYPROG'.s'
# nano test.s
$CMDL
# and compile it
#as test.s -o -g test.o
CMDL='as -o '$MYPROG'.o '$MYPROG'.s'
$BLUE$CMDL$END2
$CMDL
# and link it making program test
#ld test.o -o test
CMDL='gcc -o '$MYPROG' '$MYPROG'.o'
$BLUE$CMDL$END2
$CMDL
# or run with ./test
# or with ./test ; echo $?
CMDL='./'$MYPROG' ; echo $?'
$BLUE$CMDL$END2
#$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$
$WHTE$BOLD$MYTEXT$END2
# gdb test
CMDL='gdb -q '$MYPROG
$BLUE$CMDL$END2
$CMDL
# and show dir
CMDL='ls -la'
$BLUE$CMDL$END2
$CMDL
#end
# 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
MYTEXT=''
CMDL=''
MYPROG='test'
# use file test.s as asm source file
# like edit with
CMDL='nano '$MYPROG'.s'
# nano test.s
$CMDL
# and compile it
#as test.s -o -g test.o
CMDL='as -o '$MYPROG'.o '$MYPROG'.s'
$BLUE$CMDL$END2
$CMDL
# and link it making program test
#ld test.o -o test
CMDL='gcc -o '$MYPROG' '$MYPROG'.o'
$BLUE$CMDL$END2
$CMDL
# or run with ./test
# or with ./test ; echo $?
CMDL='./'$MYPROG' ; echo $?'
$BLUE$CMDL$END2
#$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$
$WHTE$BOLD$MYTEXT$END2
# gdb test
CMDL='gdb -q '$MYPROG
$BLUE$CMDL$END2
$CMDL
# and show dir
CMDL='ls -la'
$BLUE$CMDL$END2
$CMDL
#end
chmod +x asm
./asm
pi@RPI3:~/projects/asm $ ./asm
as -o test.o test.s
gcc -o test test.o
./test ; echo $?
2
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