Question
Q1:Convert the following C codes to equivalent IA-64 assembly codes as per the GCC conventions.: a) If else if else : int compare(int a, int
Q1:Convert the following C codes to equivalent IA-64 assembly codes as per the GCC conventions.:
a) If else if else :
int compare(int a, int *b, int c) { if (a > *b) return 1; else if (a < *b) if (c != a) return 0; else if (c > *b) return -1; else return 0; else return -1;}
=== b) Assume the functions get(), test(), and set() are already defined.
char ch1, ch2; // assume their values are taken from user input switch (ch1) { case s: set(ch1); case t: ch2 = get(ch1); switch(ch2) { case 0: test(0); break; default: test(1); } break;}
====
c) Assume given a matrix A with number of rows N = 5 and number of columns M = 4.
int i, j, product = 1; for (i=0; i === d) Factorial numbers int factorial(int n) { if (n == 1) return 1; else return n * factorial (n-1);} ____________________________ ( convert these code from c to assembly ) in simply assembly like this example: pushl %rbp movl %rsp, %rbp subl $4, %rsp movl $0, -4(%rbp) .L2: movl -4(%rbp), %rax cmpl 8(%rbp), %rax jl .L5 jmp .L3 .L5: decl 8(%rbp) movl 12(%rbp), %rdx leal -4(%rbp), %rax addl %rdx, (%rax) jmp .L2 .L3: movl 8(%rbp), %rax leave ret and stuff pls help But not like Qword things Q1:Convert the following C codes to equivalent IA-64 assembly codes as per the GCC conventions.: a) If else if else : int compare(int a, int *b, int c) { if (a > *b) return 1; else if (a < *b) if (c != a) return 0; else if (c > *b) return -1; else return 0; else return -1;} === b) Assume the functions get(), test(), and set() are already defined. char ch1, ch2; // assume their values are taken from user input switch (ch1) { case s: set(ch1); case t: ch2 = get(ch1); switch(ch2) { case 0: test(0); break; default: test(1); } break;} ==== c) Assume given a matrix A with number of rows N = 5 and number of columns M = 4. int i, j, product = 1; for (i=0; i === d) Factorial numbers int factorial(int n) { if (n == 1) return 1; else return n * factorial (n-1);} ____________________________ ( convert this c code to assembly ) in simple assembly like this example: pushl %rbp movl %rsp, %rbp subl $4, %rsp movl $0, -4(%rbp) .L2: movl -4(%rbp), %rax cmpl 8(%rbp), %rax jl .L5 jmp .L3 .L5: decl 8(%rbp) movl 12(%rbp), %rdx leal -4(%rbp), %rax addl %rdx, (%rax) jmp .L2 .L3: movl 8(%rbp), %rax leave ret __ But not like what below in QWORD and DWORD ptr __ //a. compare: push rbp mov rbp, rsp mov DWORD PTR [rbp-4], edi mov QWORD PTR [rbp-16], rsi mov DWORD PTR [rbp-8], edx mov rax, QWORD PTR [rbp-16] mov eax, DWORD PTR [rax] cmp DWORD PTR [rbp-4], eax jle .L2 mov eax, 1 jmp .L3 .L2: mov rax, QWORD PTR [rbp-16] mov eax, DWORD PTR [rax] cmp DWORD PTR [rbp-4], eax jge .L4 mov eax, DWORD PTR [rbp-8] cmp eax, DWORD PTR [rbp-4] je .L5 mov eax, 0 jmp .L3 .L5: mov rax, QWORD PTR [rbp-16] mov eax, DWORD PTR [rax] cmp DWORD PTR [rbp-8], eax jle .L6 mov eax, -1 jmp .L3 .L6: mov eax, 0 jmp .L3 .L4: mov eax, -1 .L3: pop rbp ret //b. function: push rbp mov rbp, rsp sub rsp, 16 movsx eax, BYTE PTR [rbp-1] cmp eax, 115 je .L2 cmp eax, 116 je .L3 jmp .L7 .L2: movsx eax, BYTE PTR [rbp-1] mov edi, eax mov eax, 0 call set .L3: movsx eax, BYTE PTR [rbp-1] mov edi, eax mov eax, 0 call get mov BYTE PTR [rbp-2], al movsx eax, BYTE PTR [rbp-2] test eax, eax jne .L5 mov edi, 0 mov eax, 0 call test jmp .L6 .L5: mov edi, 1 mov eax, 0 call test .L6: nop .L7: nop leave ret //c. func: push rbp mov rbp, rsp push r15 push r14 push r13 push r12 push rbx sub rsp, 56 mov rcx, rsp mov r15, rcx mov DWORD PTR [rbp-52], 1 mov DWORD PTR [rbp-64], 5 mov DWORD PTR [rbp-68], 4 mov ecx, DWORD PTR [rbp-68] mov ebx, DWORD PTR [rbp-64] movsx r12, ecx sub r12, 1 mov QWORD PTR [rbp-80], r12 movsx r12, ecx mov r13, r12 mov r14d, 0 movsx r12, ecx lea r14, [0+r12*4] movsx r12, ebx sub r12, 1 mov QWORD PTR [rbp-88], r12 movsx r12, ecx mov r10, r12 mov r11d, 0 movsx r12, ebx mov rax, r12 mov edx, 0 mov r13, r11 imul r13, rax mov r12, rdx imul r12, r10 add r12, r13 mul r10 lea r10, [r12+rdx] mov rdx, r10 movsx rax, ecx mov r8, rax mov r9d, 0 movsx rax, ebx mov rsi, rax mov edi, 0 mov rdx, r9 imul rdx, rsi mov rax, rdi imul rax, r8 lea r10, [rdx+rax] mov rax, r8 mul rsi lea rsi, [r10+rdx] mov rdx, rsi movsx rdx, ecx movsx rax, ebx imul rax, rdx lea rdx, [0+rax*4] mov eax, 16 sub rax, 1 add rax, rdx mov edi, 16 mov edx, 0 div rdi imul rax, rax, 16 sub rsp, rax mov rax, rsp add rax, 3 shr rax, 2 sal rax, 2 mov QWORD PTR [rbp-96], rax mov DWORD PTR [rbp-60], 0 jmp .L2 .L5: mov DWORD PTR [rbp-56], 1 jmp .L3 .L4: mov rsi, r14 shr rsi, 2 mov rax, QWORD PTR [rbp-96] mov edx, DWORD PTR [rbp-56] movsx rcx, edx mov edx, DWORD PTR [rbp-60] movsx rdx, edx imul rdx, rsi add rdx, rcx mov eax, DWORD PTR [rax+rdx*4] mov edx, DWORD PTR [rbp-52] imul eax, edx mov DWORD PTR [rbp-52], eax add DWORD PTR [rbp-56], 1 .L3: mov eax, DWORD PTR [rbp-56] cmp eax, DWORD PTR [rbp-68] jl .L4 add DWORD PTR [rbp-60], 1 .L2: mov eax, DWORD PTR [rbp-60] cmp eax, DWORD PTR [rbp-64] jl .L5 mov rsp, r15 nop lea rsp, [rbp-40] pop rbx pop r12 pop r13 pop r14 pop r15 pop rbp ret //d. factorial: push rbp mov rbp, rsp sub rsp, 16 mov DWORD PTR [rbp-4], edi cmp DWORD PTR [rbp-4], 1 jne .L2 mov eax, 1 jmp .L3 .L2: mov eax, DWORD PTR [rbp-4] sub eax, 1 mov edi, eax call factorial imul eax, DWORD PTR [rbp-4] .L3: leave ret Q3. No assembly code generating for structures struct r1{ int array[4]; int sum; char ch1; }; (in computer system language) ASSEMBLY =====================
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started