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

I need help converting this to assembly into an else-if assembly statement using

ID: 3717305 • Letter: I

Question

I need help converting this to assembly into an else-if assembly statement using cmp and jumps. So eax already has a number in it and I need to find which letter grade corresponds to this number.

.IF (eax <= 100 && eax >= 0)
.IF (eax <= 100) && (eax > 89)
mov al,grA
.ELSEIF (eax < 90) && (eax > 79)
mov al,grB
.ELSEIF (eax < 80) && (eax > 69)
mov al,grC
.ELSEIF (eax < 70) && (eax > 59)
mov al,grD
.ELSE
mov al,grF
.ENDIF
.ELSE
mov edx,OFFSET out_of_range
call WriteString
call Crlf
ret
.ENDIF

Explanation / Answer

cmp                 eax, 100

bgt                   END

cmp                 eax, 0

blt                    END

// Now we know eax <= 100 && eax >=0, no need to check with 100 again, just compare with 89

cmp                 eax,89

ble                   L1

mov                 al, grA

b                      END

// When L1 is triggered we know eax<=100 && eax >=0 && eax<=89, check only with 79

L1:

cmp                 eax, 79

ble                   L2

mov                 al, grB

b                      END

// When L2 is triggered we know eax<=100 && eax >=0 && eax<=89, ceax <= 79, heck only with 69

L2:

cmp                 eax, 69

ble                   L3

mov                 al, grC

b                      END

// When L3 is triggered we know eax<=100 && eax >=0 && eax<=89, ceax <= 79,eax<=69 check only with 59

L3:

cmp                 eax, 59

ble                   L4

mov                 al, grD

b                      END

// L4 is triggered when everything above is false

L4:

mov                 al, grF

END:

mov edx,OFFSET out_of_range

call WriteString

call Crlf

ret

.ENDIF

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