Assembly language
You have this code posted as an answer to one of your questions already, but I want to know how would you write this code without conditional control flow ; directives like .ELSE, .ELSE IF? I am having a hard time figuring it out.
.data
str1 BYTE “Enter an integer score: “,0
str2 BYTE “The letter grade is: “,0
.code
main PROC
call Clrscr
mov edx,OFFSET str1 ; input score from user
call WriteString
call ReadInt
call Crlf
.IF eax >= 90 ; multiway selection structure to
mov al,’A’ ; choose the correct grade letter
.ELSEIF eax >= 80
mov al,’B’
.ELSEIF eax >= 70
mov al,’C’
.ELSEIF eax >= 60
mov al,’D’
.ELSE
mov al,’F’
.ENDIF
mov edx,OFFSET str2
call WriteString
call WriteChar ; display grade letter in AL
call Crlf
exit
main ENDP
END main
Answer
You can replace the conditional directives with the following sequence
test eax, 90
jb elseif1
mov al,’A’
jmp endif
elseif1
test eax,80
jb elseif2
mov al,’B’
jmp endif
elseif2
testeax,70
jb elseif3
mov al, ‘C’
jmp endif
elseif3
test eax, 60
jb else
mov al, ‘D’
jmp endin
else
mov al, ‘F’
endif