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

Convert the following C code to Pep/9 http://pastebin.com/5xKqfnTK #include #inc

ID: 3862916 • Letter: C

Question

Convert the following C code to Pep/9

http://pastebin.com/5xKqfnTK

#include

#include

#define PASS1 500

#define PASS2 495

#define PASS3 480

int score;

int low = 100;

int secLow = 100;

int total = 0;

int i = 0;

int main()

{

while ( i < 10) { //Loop user input 10 times

printf("Score: "); //We are entering a test score here

scanf("%d", &score); //Storing the test score in 'score'

if (score < low) { //Checking if the input test 'score' is less than 'low'

secLow = low; //If it is, set the current 'low' to 'secLow'

low = score; //Then replace the current 'low' with 'score'

}

else if ( score < secLow ) { //If 'score' is not less than 'low', check if it is less than 'secLow'

secLow = score; //If it is, replace 'secLow' with 'low'

}

total = total + score; //Every loop add 'score' to 'total'

i++; //Every loop increment 'i' by 1

}

/*

**Below is pretty self explanatory. We are checking if the total is greater than 3 different scenarios that

**Lead to the student passing. If none of those conditions are met, the student fails.

*/

if (total > PASS1)

printf("Pass");

else if ( (total - low) > PASS2)

printf("Pass");

else if ( (total - low - secLow) > PASS3)

printf("Pass");

else

printf("Fail");

}

Explanation / Answer

Answer:

score:
        .zero   4
low:
        .long   100
secLow:
        .long   100
total:
        .zero   4
i:
        .zero   4
.LC0:
        .string "Score: "
.LC1:
        .string "%d"
.LC2:
        .string "Pass"
.LC3:
        .string "Fail"
main:
        push    rbp
        mov     rbp, rsp
.L5:
        mov     eax, DWORD PTR i[rip]
        cmp     eax, 9
        jg      .L2
        mov     edi, OFFSET FLAT:.LC0
        mov     eax, 0
        call    printf
        mov     esi, OFFSET FLAT:score
        mov     edi, OFFSET FLAT:.LC1
        mov     eax, 0
        call    scanf
        mov     edx, DWORD PTR score[rip]
        mov     eax, DWORD PTR low[rip]
        cmp     edx, eax
        jge     .L3
        mov     eax, DWORD PTR low[rip]
        mov     DWORD PTR secLow[rip], eax
        mov     eax, DWORD PTR score[rip]
        mov     DWORD PTR low[rip], eax
        jmp     .L4
.L3:
        mov     edx, DWORD PTR score[rip]
        mov     eax, DWORD PTR secLow[rip]
        cmp     edx, eax
        jge     .L4
        mov     eax, DWORD PTR score[rip]
        mov     DWORD PTR secLow[rip], eax
.L4:
        mov     edx, DWORD PTR total[rip]
        mov     eax, DWORD PTR score[rip]
        add     eax, edx
        mov     DWORD PTR total[rip], eax
        mov     eax, DWORD PTR i[rip]
        add     eax, 1
        mov     DWORD PTR i[rip], eax
        jmp     .L5
.L2:
        mov     eax, DWORD PTR total[rip]
        cmp     eax, 500
        jle     .L6
        mov     edi, OFFSET FLAT:.LC2
        mov     eax, 0
        call    printf
        jmp     .L7
.L6:
        mov     edx, DWORD PTR total[rip]
        mov     eax, DWORD PTR low[rip]
        sub     edx, eax
        mov     eax, edx
        cmp     eax, 495
        jle     .L8
        mov     edi, OFFSET FLAT:.LC2
        mov     eax, 0
        call    printf
        jmp     .L7
.L8:
        mov     edx, DWORD PTR total[rip]
        mov     eax, DWORD PTR low[rip]
        sub     edx, eax
        mov     eax, DWORD PTR secLow[rip]
        sub     edx, eax
        mov     eax, edx
        cmp     eax, 480
        jle     .L9
        mov     edi, OFFSET FLAT:.LC2
        mov     eax, 0
        call    printf
        jmp     .L7
.L9:
        mov     edi, OFFSET FLAT:.LC3
        mov     eax, 0
        call    printf
.L7:
        mov     eax, 0
        pop     rbp
        ret