Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hand compile the complete accompanying C code fragment into ARM assembly languag

ID: 3862543 • Letter: H

Question

Hand compile the complete accompanying C code fragment into ARM assembly language. This means the full code fragment, not its individual C instructions, one at a time. The only ARM operation available: NOP, ADD, SUB, AND, OR, EOR, LSL, LDURSW, STURW, B, BR, B.GT, with I type operation as well(ADDI, SUBI, ANDI, ORI, XORI ). Provide explanation for each line of the code. Don't assume that there's something in the SRAM, you'll need to ADD Immediate to get the value of int into the RF.

int A = 7;
int B = 5;
int C = 3;
int D = 5;
int* dPtr = &D;
unsigned int E = 0x5A5A;
unsigned int F = 0x6767;
unsigned int G = 0x3C;
unsigned int H = 0xFF;

if((A-B) > 3)
{
   C = C +4;
   D = C -3;
   G = E | F;
}
else
{
   C = C << 3;
   *dPtr = 7;
   G = E & F;
}
A = A + B;
G = (E^F) & H;

Explanation / Answer

The given c code itself does not compile. So, i am assuming the statements to be in a main fiunction and compiled it to a ARM code:

Here is the attached code

A:
B:
C:
D:
dPtr:
.quad D
E:
.long 23130
F:
.long 26471
G:
.long 60
H:
.long 255
main:
push rbp
mov rbp, rsp
mov edx, DWORD PTR A[rip]
mov eax, DWORD PTR B[rip]
sub edx, eax
mov eax, edx
cmp eax, 3
jle .L2
mov eax, DWORD PTR C[rip]
add eax, 4
mov DWORD PTR C[rip], eax
mov eax, DWORD PTR C[rip]
sub eax, 3
mov DWORD PTR D[rip], eax
mov edx, DWORD PTR E[rip]
mov eax, DWORD PTR F[rip]
or eax, edx
mov DWORD PTR G[rip], eax
jmp .L3
.L2:
mov eax, DWORD PTR C[rip]
sal eax, 3
mov DWORD PTR C[rip], eax
mov rax, QWORD PTR dPtr[rip]
mov DWORD PTR [rax], 7
mov edx, DWORD PTR E[rip]
mov eax, DWORD PTR F[rip]
and eax, edx
mov DWORD PTR G[rip], eax
.L3:
mov edx, DWORD PTR A[rip]
mov eax, DWORD PTR B[rip]
add eax, edx
mov DWORD PTR A[rip], eax
mov edx, DWORD PTR E[rip]
mov eax, DWORD PTR F[rip]
xor edx, eax
mov eax, DWORD PTR H[rip]
and eax, edx
mov DWORD PTR G[rip], eax
mov eax, 0
pop rbp
ret

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote