Difference between revisions of "CSC231 nasmld script"
(Created page with "--~~~~ ---- <source lang="bash"> #! /bin/bash set -e # exit on error filename=$(basename "$1") extension="${filename##*.}" filename="${filename%.*}" nasm -f elf -F stabs $fi...") |
|||
Line 1: | Line 1: | ||
− | --[[User:Thiebaut|D. Thiebaut]] 09:18, 7 November 2012 (EST) | + | --[[User:Thiebaut|D. Thiebaut]] 09:18, 7 November 2012 (EST)<br /> |
+ | revised --[[User:Thiebaut|D. Thiebaut]] ([[User talk:Thiebaut|talk]]) 08:12, 16 September 2014 (EDT) | ||
---- | ---- | ||
+ | |||
+ | =Version 1= | ||
<source lang="bash"> | <source lang="bash"> | ||
#! /bin/bash | #! /bin/bash | ||
− | + | # nasmld | |
+ | # D. Thiebaut | ||
+ | # assembles and links an assembly program for | ||
+ | # a Pentium processor running Linux | ||
+ | |||
+ | |||
filename=$(basename "$1") | filename=$(basename "$1") | ||
− | |||
filename="${filename%.*}" | filename="${filename%.*}" | ||
+ | |||
nasm -f elf -F stabs $filename.asm | nasm -f elf -F stabs $filename.asm | ||
ld -o $filename -melf_i386 $filename.o | ld -o $filename -melf_i386 $filename.o | ||
</source> | </source> | ||
+ | =Version 2: more sophisticated= | ||
+ | <br /> | ||
+ | This version stops if nasm or ld return an error. | ||
+ | <br /> | ||
+ | <source lang="bash"> | ||
+ | #! /bin/bash | ||
+ | # nasmld | ||
+ | # D. Thiebaut | ||
+ | # assembles and links an assembly program for | ||
+ | # a Pentium processor running Linux | ||
+ | |||
+ | # display syntax if user forgets | ||
+ | if [ ! -n "$1" ] | ||
+ | then | ||
+ | echo "Usage: `basename $0` progName" | ||
+ | exit 1 | ||
+ | fi | ||
+ | |||
+ | # remove the ".asm" part of the filename | ||
+ | filename=$(basename "$1") | ||
+ | filename="${filename%.*}" | ||
+ | |||
+ | # assemble and generate a listing (optional) | ||
+ | nasm -f elf -F stabs $filename.asm -l $filename.lst | ||
+ | |||
+ | # if we get errors, stop | ||
+ | if [ "$?" -ne "0" ]; then | ||
+ | echo "*** Nasm ERROR! ***" | ||
+ | exit | ||
+ | fi | ||
+ | |||
+ | # link | ||
+ | ld -melf_i386 -o $filename $filename.o | ||
+ | |||
+ | # if we get errors, stop | ||
+ | if [ "$?" -ne "0" ]; then | ||
+ | echo "Link ERROR! ***" | ||
+ | exit | ||
+ | fi | ||
+ | |||
+ | # no errors, run the program! | ||
+ | ./$filename | ||
+ | |||
+ | </source> | ||
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /> | <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /> | ||
[[Category:CSC231]] | [[Category:CSC231]] |
Revision as of 08:12, 16 September 2014
--D. Thiebaut 09:18, 7 November 2012 (EST)
revised --D. Thiebaut (talk) 08:12, 16 September 2014 (EDT)
Version 1
#! /bin/bash
# nasmld
# D. Thiebaut
# assembles and links an assembly program for
# a Pentium processor running Linux
filename=$(basename "$1")
filename="${filename%.*}"
nasm -f elf -F stabs $filename.asm
ld -o $filename -melf_i386 $filename.o
Version 2: more sophisticated
This version stops if nasm or ld return an error.
#! /bin/bash
# nasmld
# D. Thiebaut
# assembles and links an assembly program for
# a Pentium processor running Linux
# display syntax if user forgets
if [ ! -n "$1" ]
then
echo "Usage: `basename $0` progName"
exit 1
fi
# remove the ".asm" part of the filename
filename=$(basename "$1")
filename="${filename%.*}"
# assemble and generate a listing (optional)
nasm -f elf -F stabs $filename.asm -l $filename.lst
# if we get errors, stop
if [ "$?" -ne "0" ]; then
echo "*** Nasm ERROR! ***"
exit
fi
# link
ld -melf_i386 -o $filename $filename.o
# if we get errors, stop
if [ "$?" -ne "0" ]; then
echo "Link ERROR! ***"
exit
fi
# no errors, run the program!
./$filename