Initial Commit

This commit is contained in:
root
2023-10-23 18:07:52 +00:00
commit 1923748144
11 changed files with 126 additions and 0 deletions

34
Makefile Normal file
View File

@@ -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

23
asm.txt Normal file
View File

@@ -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

BIN
calc Executable file

Binary file not shown.

BIN
calc-cpp Executable file

Binary file not shown.

BIN
calc-cpp.o Normal file

Binary file not shown.

19
calc.asm Normal file
View File

@@ -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

14
calc.cpp Normal file
View File

@@ -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;
}

BIN
calc.o Normal file

Binary file not shown.

23
cpp.txt Normal file
View File

@@ -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

13
main.cpp Normal file
View File

@@ -0,0 +1,13 @@
#include <iostream>
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;
}

BIN
main.o Normal file

Binary file not shown.