-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun-asm.sh
53 lines (42 loc) · 1.33 KB
/
run-asm.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
#THIS SCRIPT USED FOR 1) ASSEMBLE CODE
# 2) LINK
# 3) RUN THE BINARY
# 4) PRINT THE OUTPUT
#SCRIPT WORKS WITH X86_ASSEMBLY AT&T SYNTAX
options=("asm" "link" "asm-link" "all")
option=$2
if [[ ! ${options[*]} =~ "$option" ]]; then
echo "Please enter valid option: asm | link | asm-link | all"
exit
fi
file_arg=$1
path_file=""
file_name=""
if [ -n "$file_arg" ]; then
path_file=${file_arg::-2} # remove extension .s if exits
file_name=$(basename ${path_file}) # get file name without path
else
echo "Please enter the assembly file as an argument"
exit 1
fi
if [ ! -d out ]
then
mkdir out
fi
if [[ $option == "asm" ]]; then
echo "assembling..."
as --32 -g -I $(pwd) $path_file.s -o out/$file_name.o
echo "done"
elif [[ $option == "link" ]]; then
echo "linking..."
ld -melf_i386 out/$file_name.o -o out/$file_name
echo "done"
elif [[ $option == "asm-link" ]]; then
echo "assembling-linking..."
as --32 -g -I $(pwd) $path_file.s -o out/$file_name.o && ld -melf_i386 out/$file_name.o -o out/$file_name
echo "done"
elif [[ $option == "all" ]]; then
as --32 -g -I $(pwd) $path_file.s -o out/$file_name.o && ld -melf_i386 out/$file_name.o -o out/$file_name && ./out/$file_name "${*:2}"; echo $?
fi
# END