commit 19237481446f4fd7c501ad5be6d02e811f628538 Author: root Date: Mon Oct 23 18:07:52 2023 +0000 Initial Commit diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c56d700 --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ +all: link + +build: build-asm build-cpp build-main + +asm: build-main link-asm +cpp: build-main link-cpp + + +build-main: + g++ -o main.o -c main.cpp + +build-asm: + nasm -felf64 calc.asm + +build-cpp: + g++ -o calc-cpp.o -c calc.cpp + +link: build-main link-asm link-cpp + +link-asm: build-asm + g++ -o calc calc.o main.o + +link-cpp: build-cpp + g++ -o calc-cpp calc-cpp.o main.o + +clean: + rm *.o *.txt calc calc-cpp + +run: build link + ./calc + +test: build link + echo "24 12" | /bin/time -v -o asm.txt ./calc + echo "24 12" | /bin/time -v -o cpp.txt ./calc-cpp \ No newline at end of file diff --git a/asm.txt b/asm.txt new file mode 100644 index 0000000..da708bc --- /dev/null +++ b/asm.txt @@ -0,0 +1,23 @@ + Command being timed: "./calc" + User time (seconds): 0.00 + System time (seconds): 0.00 + Percent of CPU this job got: 100% + Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.00 + Average shared text size (kbytes): 0 + Average unshared data size (kbytes): 0 + Average stack size (kbytes): 0 + Average total size (kbytes): 0 + Maximum resident set size (kbytes): 3824 + Average resident set size (kbytes): 0 + Major (requiring I/O) page faults: 0 + Minor (reclaiming a frame) page faults: 142 + Voluntary context switches: 0 + Involuntary context switches: 0 + Swaps: 0 + File system inputs: 0 + File system outputs: 0 + Socket messages sent: 0 + Socket messages received: 0 + Signals delivered: 0 + Page size (bytes): 4096 + Exit status: 0 diff --git a/calc b/calc new file mode 100755 index 0000000..a9deb99 Binary files /dev/null and b/calc differ diff --git a/calc-cpp b/calc-cpp new file mode 100755 index 0000000..8aa93b9 Binary files /dev/null and b/calc-cpp differ diff --git a/calc-cpp.o b/calc-cpp.o new file mode 100644 index 0000000..c920e0a Binary files /dev/null and b/calc-cpp.o differ diff --git a/calc.asm b/calc.asm new file mode 100644 index 0000000..880c836 --- /dev/null +++ b/calc.asm @@ -0,0 +1,19 @@ +section .data + feet_in3: dq 1728.00 + pi: dq 3.141592 + half_it: dq 0.5 + +section .text +global hole_calc + +hole_calc: + ; xmm0 Diameter xmm1 Volume + ; This program converts the volume of a cylinder to a depth to dig a hole. + ; + mulsd xmm1, [rel half_it] ; Convert Diameter // radius = diameter / 2.0; + mulsd xmm0, [rel feet_in3] ; Multiply diameter by 1728.00, result in xmm1 // volumeInCubicInches = volume * 1728.00; + mulsd xmm1, xmm1 ; Square Diameter, load into xmm0 + mulsd xmm1, [rel pi] ; Diameter Squared Times Pi, loaded into xmm0 + divsd xmm0, xmm1 ; Product the final result. + ret + diff --git a/calc.cpp b/calc.cpp new file mode 100644 index 0000000..9c64d92 --- /dev/null +++ b/calc.cpp @@ -0,0 +1,14 @@ +using namespace std; +extern "C" double hole_calc(double volume, double diameter) +{ + // Convert diameter to radius + double radius = diameter / 2.0; + + //Calculate the volume in cubic inches + double volumeInCubicInches = volume * 1728.00; + + // Calculate the depth using the volume, radius, and pi + double depth = volumeInCubicInches / ((radius * radius) * 3.141592); + + return depth; +} \ No newline at end of file diff --git a/calc.o b/calc.o new file mode 100644 index 0000000..0dd92fa Binary files /dev/null and b/calc.o differ diff --git a/cpp.txt b/cpp.txt new file mode 100644 index 0000000..9b52167 --- /dev/null +++ b/cpp.txt @@ -0,0 +1,23 @@ + Command being timed: "./calc-cpp" + User time (seconds): 0.00 + System time (seconds): 0.00 + Percent of CPU this job got: 100% + Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.00 + Average shared text size (kbytes): 0 + Average unshared data size (kbytes): 0 + Average stack size (kbytes): 0 + Average total size (kbytes): 0 + Maximum resident set size (kbytes): 3820 + Average resident set size (kbytes): 0 + Major (requiring I/O) page faults: 0 + Minor (reclaiming a frame) page faults: 141 + Voluntary context switches: 0 + Involuntary context switches: 4 + Swaps: 0 + File system inputs: 0 + File system outputs: 0 + Socket messages sent: 0 + Socket messages received: 0 + Signals delivered: 0 + Page size (bytes): 4096 + Exit status: 0 diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..46d7171 --- /dev/null +++ b/main.cpp @@ -0,0 +1,13 @@ +#include +using namespace std; +// hole_calc(volume, diameter) +extern "C" double hole_calc(double, double); + +int main() +{ + double diameter, volume; + cout << "Please enter the diameter in in, press enter and then the volume in cubic feet, and press enter again." << endl; + cin >> diameter >> volume; + cout << "Dig hole to " << hole_calc(volume, diameter) << " in deep." << endl; + return 0; +} \ No newline at end of file diff --git a/main.o b/main.o new file mode 100644 index 0000000..f3ee7a3 Binary files /dev/null and b/main.o differ