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

Write a program in the ISA described above that utilizes the following pseudocod

ID: 3573643 • Letter: W

Question

Write a program in the ISA described above that utilizes the following pseudocode. Suppose that the data you need are in the local memory starting from the address that is stored in register r1. (To refer to a register use the notation r and the number of the register). There are 64 32-bit general purpose registers numbered from 0 to 63. For a 64 bit data use a pair of two consecutive registers with the even register as the reference. For example, if A is a 64 bit number and it is stored in registers r0 and r1, then, in order to reference this number, you just need to use r0.

void main() {

int a, b, c, d;

int e[10];

for (int i=0; i<10; 1++) {

if (a<=b) {

a = a + c;

e[i] = a;

}

else {

a = a – d;

e[i] = a;

}

}

}

Explanation / Answer

;assuming x86 assembly as the ISA not provided

        .file   "test.c"
        .text
        .globl main
        .type   main, @function
main:
.LFB0:
        .cfi_startproc
        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
        movq    %rsp, %rbp
        .cfi_def_cfa_register 6
        movl    $0, -68(%rbp)
        movl    $0, -60(%rbp)
        movl    $0, -56(%rbp)
        movl    $0, -52(%rbp)
        movl    $0, -64(%rbp)
        movl    $0, -64(%rbp)
        jmp     .L2
.L5:
        movl    -68(%rbp), %eax
        cmpl    -60(%rbp), %eax
        jg      .L3
        movl    -56(%rbp), %eax
        addl    %eax, -68(%rbp)
        movl    -64(%rbp), %eax
        cltq
        movl    -68(%rbp), %edx
        movl    %edx, -48(%rbp,%rax,4)
        jmp     .L4
.L3:
        movl    -52(%rbp), %eax
        subl    %eax, -68(%rbp)
        movl    -64(%rbp), %eax
        cltq
        movl    -68(%rbp), %edx
        movl    %edx, -48(%rbp,%rax,4)
.L4:
        addl    $1, -64(%rbp)
.L2:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote