Difference between revisions of "CSC231 nasmld script"
(→Version 2: more sophisticated) |
|||
Line 75: | Line 75: | ||
</source> | </source> | ||
− | <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /> | + | <br /> |
+ | =Usage= | ||
+ | <br /> | ||
+ | If you have a program, say HelloWorld.asm, and want to assemble, link and run it, simply type: | ||
+ | |||
+ | nasmld HelloWorld.asm | ||
+ | |||
+ | at the command line, or, if that doesn't work: | ||
+ | |||
+ | ./nasmld HelloWorld.asm | ||
+ | |||
+ | |||
+ | |||
+ | <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /> | ||
[[Category:CSC231]] | [[Category:CSC231]] |
Revision as of 07:15, 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
# To create the script, edit with your favorite text editor,
# save to current directory or to ~/bin, and make executable:
#
# chmod +x nasmld
#
set -e # stop on error
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.
# To create the script, edit with your favorite text editor,
# save to current directory or to ~/bin, and make executable:
#
# chmod +x nasmld
#
# 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
Usage
If you have a program, say HelloWorld.asm, and want to assemble, link and run it, simply type:
nasmld HelloWorld.asm
at the command line, or, if that doesn't work:
./nasmld HelloWorld.asm