Hey I'm trying to convert this C code into ARMv8 however I'm having severe difficulty while doing it. This is just for personal practice to develop my skills. Thank you!
// Code starts here
// This is a C language code below
#define FALSE 0
#define TRUE 1
struct coord {
int x, y;
};
struct size {
int width, length;
};
struct pyramid {
struct coord center;
struct size base;
int height;
int volume;
};
struct pyramid newPyramid(int width, int length, int height)
{
struct pyramid p;
p.center.x = 0;
p.center.y = 0;
p.base.width = width;
p.base.length = length;
p.height = height;
p.volume = (p.base.width * p.base.length * p.height) / 3;
return p;
}
void relocate(struct pyramid *p, int deltaX, int deltaY)
{
p->center.x += deltaX;
p->center.y += deltaY;
}
void expand(struct pyramid *p, int factor)
{
p->base.width *= factor;
p->base.length *= factor;
p->height *= factor;
p->volume = (p->base.width * p->base.length *
p->height) / 3;
}
void printPyramid(char *name, struct pyramid *p)
{
printf("Pyramid %s\n", name);
printf("\tCenter = (%d, %d)\n", p->center.x,
p->center.y);
printf("\tBase width = %d Base length = %d\n", p->base.width,
p->base.length);
printf("\tHeight = %d\n", p->height);
printf("\tVolume = %d\n\n", p->volume);
}
int equalSize(struct pyramid *p1, struct pyramid *p2)
{
int result = FALSE;
if (p1->base.width == p2->base.width) {
if (p1->base.length == p2->base.length) {
if (p1->height == p2->height) {
result = TRUE;
}
}
}
return result;
}
int main()
{
struct pyramid khafre, cheops;
khafre = newPyramid(10, 10, 9);
cheops = newPyramid(15, 15, 18);
printf("Initial pyramid values:\n");
printPyramid("khafre", &khafre);
printPyramid("cheops", &cheops);
if (!equalSize(&khafre, &cheops)) {
expand(&cheops, 9);
relocate(&cheops, 27, -10);
relocate(&khafre, -23, 17);
}
printf("\nNew pyramid values:\n");
printPyramid("khafre", &khafre);
printPyramid("cheops", &cheops);
}
newPyramid:
push rbp
mov rbp, rsp
mov QWORD PTR [rbp-40], rdi
mov DWORD PTR [rbp-44], esi
mov DWORD PTR [rbp-48], edx
mov DWORD PTR [rbp-52], ecx
mov DWORD PTR [rbp-32], 0
mov DWORD PTR [rbp-28], 0
mov eax, DWORD PTR [rbp-44]
mov DWORD PTR [rbp-24], eax
mov eax, DWORD PTR [rbp-48]
mov DWORD PTR [rbp-20], eax
mov eax, DWORD PTR [rbp-52]
mov DWORD PTR [rbp-16], eax
mov edx, DWORD PTR [rbp-24]
mov eax, DWORD PTR [rbp-20]
imul edx, eax
mov eax, DWORD PTR [rbp-16]
imul eax, edx
movsx rdx, eax
imul rdx, rdx, 1431655766
shr rdx, 32
sar eax, 31
mov esi, edx
sub esi, eax
mov eax, esi
mov DWORD PTR [rbp-12], eax
mov rcx, QWORD PTR [rbp-40]
mov rax, QWORD PTR [rbp-32]
mov rdx, QWORD PTR [rbp-24]
mov QWORD PTR [rcx], rax
mov QWORD PTR [rcx+8], rdx
mov rax, QWORD PTR [rbp-16]
mov QWORD PTR [rcx+16], rax
mov rax, QWORD PTR [rbp-40]
pop rbp
ret
relocate:
push rbp
mov rbp, rsp
mov QWORD PTR [rbp-8], rdi
mov DWORD PTR [rbp-12], esi
mov DWORD PTR [rbp-16], edx
mov rax, QWORD PTR [rbp-8]
mov edx, DWORD PTR [rax]
mov eax, DWORD PTR [rbp-12]
add edx, eax
mov rax, QWORD PTR [rbp-8]
mov DWORD PTR [rax], edx
mov rax, QWORD PTR [rbp-8]
mov edx, DWORD PTR [rax+4]
mov eax, DWORD PTR [rbp-16]
add edx, eax
mov rax, QWORD PTR [rbp-8]
mov DWORD PTR [rax+4], edx
nop
pop rbp
ret
expand:
push rbp
mov rbp, rsp
mov QWORD PTR [rbp-8], rdi
mov DWORD PTR [rbp-12], esi
mov rax, QWORD PTR [rbp-8]
mov eax, DWORD PTR [rax+8]
imul eax, DWORD PTR [rbp-12]
mov edx, eax
mov rax, QWORD PTR [rbp-8]
mov DWORD PTR [rax+8], edx
mov rax, QWORD PTR [rbp-8]
mov eax, DWORD PTR [rax+12]
imul eax, DWORD PTR [rbp-12]
mov edx, eax
mov rax, QWORD PTR [rbp-8]
mov DWORD PTR [rax+12], edx
mov rax, QWORD PTR [rbp-8]
mov eax, DWORD PTR [rax+16]
imul eax, DWORD PTR [rbp-12]
mov edx, eax
mov rax, QWORD PTR [rbp-8]
mov DWORD PTR [rax+16], edx
mov rax, QWORD PTR [rbp-8]
mov edx, DWORD PTR [rax+8]
mov rax, QWORD PTR [rbp-8]
mov eax, DWORD PTR [rax+12]
imul edx, eax
mov rax, QWORD PTR [rbp-8]
mov eax, DWORD PTR [rax+16]
imul eax, edx
movsx rdx, eax
imul rdx, rdx, 1431655766
shr rdx, 32
sar eax, 31
sub edx, eax
mov rax, QWORD PTR [rbp-8]
mov DWORD PTR [rax+20], edx
nop
pop rbp
ret
.LC0:
.string "Pyramid %s\n"
.LC1:
.string "\tCenter = (%d, %d)\n"
.LC2:
.string "\tBase width = %d Base length = %d\n"
.LC3:
.string "\tHeight = %d\n"
.LC4:
.string "\tVolume = %d\n\n"
printPyramid:
push rbp
mov rbp, rsp
sub rsp, 16
mov QWORD PTR [rbp-8], rdi
mov QWORD PTR [rbp-16], rsi
mov rax, QWORD PTR [rbp-8]
mov rsi, rax
mov edi, OFFSET FLAT:.LC0
mov eax, 0
call printf
mov rax, QWORD PTR [rbp-16]
mov edx, DWORD PTR [rax+4]
mov rax, QWORD PTR [rbp-16]
mov eax, DWORD PTR [rax]
mov esi, eax
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call printf
mov rax, QWORD PTR [rbp-16]
mov edx, DWORD PTR [rax+12]
mov rax, QWORD PTR [rbp-16]
mov eax, DWORD PTR [rax+8]
mov esi, eax
mov edi, OFFSET FLAT:.LC2
mov eax, 0
call printf
mov rax, QWORD PTR [rbp-16]
mov eax, DWORD PTR [rax+16]
mov esi, eax
mov edi, OFFSET FLAT:.LC3
mov eax, 0
call printf
mov rax, QWORD PTR [rbp-16]
mov eax, DWORD PTR [rax+20]
mov esi, eax
mov edi, OFFSET FLAT:.LC4
mov eax, 0
call printf
nop
leave
ret
equalSize:
push rbp
mov rbp, rsp
mov QWORD PTR [rbp-24], rdi
mov QWORD PTR [rbp-32], rsi
mov DWORD PTR [rbp-4], 0
mov rax, QWORD PTR [rbp-24]
mov edx, DWORD PTR [rax+8]
mov rax, QWORD PTR [rbp-32]
mov eax, DWORD PTR [rax+8]
cmp edx, eax
jne .L7
mov rax, QWORD PTR [rbp-24]
mov edx, DWORD PTR [rax+12]
mov rax, QWORD PTR [rbp-32]
mov eax, DWORD PTR [rax+12]
cmp edx, eax
jne .L7
mov rax, QWORD PTR [rbp-24]
mov edx, DWORD PTR [rax+16]
mov rax, QWORD PTR [rbp-32]
mov eax, DWORD PTR [rax+16]
cmp edx, eax
jne .L7
mov DWORD PTR [rbp-4], 1
.L7:
mov eax, DWORD PTR [rbp-4]
pop rbp
ret
.LC5:
.string "Initial pyramid values:"
.LC6:
.string "khafre"
.LC7:
.string "cheops"
.LC8:
.string "\nNew pyramid values:"
main:
push rbp
mov rbp, rsp
sub rsp, 96
lea rax, [rbp-96]
mov ecx, 9
mov edx, 10
mov esi, 10
mov rdi, rax
call newPyramid
mov rax, QWORD PTR [rbp-96]
mov rdx, QWORD PTR [rbp-88]
mov QWORD PTR [rbp-32], rax
mov QWORD PTR [rbp-24], rdx
mov rax, QWORD PTR [rbp-80]
mov QWORD PTR [rbp-16], rax
lea rax, [rbp-96]
mov ecx, 18
mov edx, 15
mov esi, 15
mov rdi, rax
call newPyramid
mov rax, QWORD PTR [rbp-96]
mov rdx, QWORD PTR [rbp-88]
mov QWORD PTR [rbp-64], rax
mov QWORD PTR [rbp-56], rdx
mov rax, QWORD PTR [rbp-80]
mov QWORD PTR [rbp-48], rax
mov edi, OFFSET FLAT:.LC5
call puts
lea rax, [rbp-32]
mov rsi, rax
mov edi, OFFSET FLAT:.LC6
call printPyramid
lea rax, [rbp-64]
mov rsi, rax
mov edi, OFFSET FLAT:.LC7
call printPyramid
lea rdx, [rbp-64]
lea rax, [rbp-32]
mov rsi, rdx
mov rdi, rax
call equalSize
test eax, eax
jne .L10
lea rax, [rbp-64]
mov esi, 9
mov rdi, rax
call expand
lea rax, [rbp-64]
mov edx, -10
mov esi, 27
mov rdi, rax
call relocate
lea rax, [rbp-32]
mov edx, 17
mov esi, -23
mov rdi, rax
call relocate
.L10:
mov edi, OFFSET FLAT:.LC8
call puts
lea rax, [rbp-32]
mov rsi, rax
mov edi, OFFSET FLAT:.LC6
call printPyramid
lea rax, [rbp-64]
mov rsi, rax
mov edi, OFFSET FLAT:.LC7
call printPyramid
mov eax, 0
leave
ret
Hey I'm trying to convert this C code into ARMv8 however I'm having severe difficulty while...
Using C, I need help debugging this program. I have a few error messages that I'm not sure how to fix. Here is the code I have: /* * C Program to Print a Linked List in Reverse Order */ #include <stdio.h> #include <stdlib.h> struct node { int num; struct node *next; }; int main() { struct node *p = NULL; struct node_occur *head = NULL; int n; printf("Enter data into the list\n"); create(&p); printf("Displaying the nodes in the list:\n");...
I am trying to write C programming code and output will be as below but I donno how to get the result analysis part. help me to add the 2nd part with my code: here is my code below: #include <stdio.h> #define MAX 100 struct studentMarkVariable{ int id; float marks; }; void getData(struct studentMarkVariable arrs[]); void show(struct studentMarkVariable arrs[]); int main() { printf ("####### Marks Analyzer V3.0 ####### \n"); struct studentMarkVariable arrs[MAX]; getData(arrs); show(arrs); return 0; }...
C++. Difficulty with quickSort function. Code will not run quickSort function. The code I'm having trouble with is in bold. -------------------------------------------------------------------------------------------------driverProgram.cpp #include #include #include #include #include "quickSort.cpp" using namespace std; int main() { const int MIN_SIZE = 4; //Array size const int SIZE = 25; int theArray[SIZE] = {11, 22, 33, 44, 55, 66, 77, 88, 99, 12, 13, 14, 15, 16, 17, 18, 19, 18, 19, 20, 21, 22, 23, 24, 25}; cout << "List of 25 items: ";...
I'm trying to code a C program so it sorts an array of integer numbers of size n in ascending order. My code is written below but its not working properly, its giving me errors, I think my sort and swap functions aren't done right maybe, please help and fix. It says "undefined reference to "SelectionSort" as an error. But the question asks to not change the PrintArray and Main function. #include <stdio.h> void PrintArray(int size, int array[]) { for...
C Programming Question Hi, I have the following code and in my submission I'm supposed to only include function definitions (i.e. implementations) in the file. However, I'm not NOT required to write the main, struct definitions and function prototypes. Could someone help me fix this code? Text Version: #include<stdio.h> #include<stdlib.h> #include <string.h> struct ip_address { int octet_1; int octet_2; int octet_3; int octet_4; }; typedef struct ip_address ip_address_t; void print_ip_address(ip_address_t ip1){ printf("%d.%d.%d.%d", ip1.octet_1,ip1.octet_2,ip1.octet_3,ip1.octet_4); } int is_valid(ip_address_t ip1){ if(ip1.octet_1 < 0...
program in C - Starter code below //In this assignment, we practice call by reference. //Below description of call by reference is from the following link //https://www.tutorialspoint.com/cprogramming/c_function_call_by_reference.htm //The call by reference method of passing arguments to a function copies //the address of an argument into the formal parameter. Inside the function, //the address is used to access the actual argument used in the call. //It means the changes made to the parameter affect the passed argument. //We use an example...
Can you help with this C programming question. I have provided the skeleton code below along with the Stack/Data/Process Class for you to see/reference. Along with the Stack/Data type definition. **SKELTON CODE** #include #include #include Stack* concat_stack(Stack *s1, Stack *s2) { //your code here return NULL; } **STACK CLASS FOR YOU TO REFERENCE** #include #include #include #include Stack* create_stack(int stack_capacity) { Stack *s = (Stack*) malloc(sizeof(Stack)); if (stack_capacity < 1) { fprintf(stderr, "Error(create_stack): invalid capacity, set to 10\n"); s->capacity =...
Following changes need to be made, and the code for each is provided: (1) Modify newMovieReviewNode(), this time the newly allocated review should get an empty linked list of scores ReviewNode *newMovieReviewNode() { /* * This function allocates a new, empty ReviewNode, and initializes the * contents of the MovieReview for this node to empty values. * The fields in the MovieReview should be set to: * movie_title="" * movie_studio="" * year = -1 * BO_total = -1 * score...
C Programming - Please Help us! Implementing Load Balancing, the 3 Base Code files are at the bottom: Implementing Load Balancing Summary: In this homework, you will be implementing the main muti-threaded logic for doing batch based server load balancing using mutexes Background In this assignment you will write a batch-based load balancer. Consider a server which handles data proces- sing based on user requests. In general, a server has only a fixed set of hardware resources that it can...
C++ Error. I'm having trouble with a pointer. I keep getting the error "Thread 1: EXC_BAD_ACCESS (code=1, address=0x18)" The objective of the assignment is to revise the public method add in class template LinkedBag so that the new node is inserted at the end of the linked chain instead of at the beginning. This is the code I have: linkedBag-driver.cpp BagInterface.hpp LinkedBag.hpp Node.hpp int main) LinkedBag<string> bag; cout << "Testing array-based Set:" << endl; cout << "The initial bag is...