Tutorial: Moodle VPL -- Verifying Presence of Functions in Asm

From DftWiki

Jump to: navigation, search

--D. Thiebaut (talk) 20:46, 21 October 2014 (EDT)


Contents

MoodleVPLLogo.png



Moodle VPL Tutorials



This VPL activity tests an assembly program that is supposed to contain 3 key functions, defined by name, and samples the output to verify that key lines appear in the output.



Vpl_run.sh


#! /bin/bash
   
cat > vpl_execution <<EOF
#! /bin/bash
prog=Hw4_3

nasm -f elf 231Lib.asm
nasm -f elf  \$prog.asm
ld -melf_i386 -o \$prog \$prog.o 231Lib.o
./\$prog | cat -v
EOF
 
chmod +x vpl_execution


Vpl_evaluate.sh


#! /bin/bash
   
cat > vpl_execution <<EOF
#! /bin/bash
prog=Hw4_3

# remove the comments from the source file
cat \${prog}.asm | sed 's:;.*$::g'  > _\${prog}.asm

# check to see if there exist lines containing "call printLn", "call printMsg"
# or "call printFibMsg".  If not, then abort and give a grade of 20.
for pattern in printLn printMsg printFibMsg ; do
    grep \$pattern _\${prog}.asm | grep call &> grepLines.out
    if [ ! -s grepLines.out ] ; then
        echo "Comment :=>>You are not using function \$pattern in your code"
        echo "Grade :=>> 20"
        exit  
    fi
done

# assemble and link
nasm -f elf 231Lib.asm
nasm -f elf  \$prog.asm
ld -melf_i386 -o \$prog \$prog.o 231Lib.o


# see if "(0)" and "1" is in one output line
./\$prog | cat -v | grep "(0)" | grep "1" &>  grepLines.out
if [ ! -s grepLines.out ] ; then                                            
        echo "Comment :=>>Your program does not output the correct Fibonacci series"
        echo "Comment :=>>The 0th Fibonacci should be 1."                
        echo "Grade :=>> 40"  
        exit
fi

# see if "(35)" and "14930352" is in one output line
./\$prog | cat -v | grep "(35)" | grep "14930352" &>  grepLines.out
if [ ! -s grepLines.out ] ; then                                            
        echo "Comment :=>>Your program does not output the correct Fibonacci series"
        echo "Comment :=>>The 35th Fibonacci should be 14930352."                
        echo "Grade :=>> 40"  
        exit
fi

# see if "(39)" and "102334155" is in one output line
./\$prog | cat -v | grep "(39)" | grep "102334155" &>  grepLines.out
if [ ! -s grepLines.out ] ; then                                            
        echo "Comment :=>>Your program does not output the correct Fibonacci series"
        echo "Comment :=>>The 39th Fibonacci should be 102334155."    
        echo "Grade :=>> 40"  
        exit
fi

echo "Comment :=>> Congratulations, your program passes the test!"
echo "Grade :=>> 100"  
EOF
 
chmod +x vpl_execution


Solution Program: Hw4_3.asm



...