페이지

2014. 12. 15.

[MASM] 성적 산출 프로그램

1) C++ 구현 예

if (score < 0 | score > 100)
   cout < "Erorr! The score is between 0 and 100“;
else if (score >= 90)
   grade = ‘A’;
else if (score >= 80)
   grade = ‘B’;
else if (score >= 70)
   grade = ‘C’;
else if (score >= 60)
   grade = ‘D’;
else
   grade = ‘F’;


2) 어셈블리 코드

.data
str1 BYTE "Enter an integer score: ",0
str2 BYTE "Your grade is: ",0
str3 BYTE "Eror! The score is between 0 and 100", 0


.code
main PROC
   call Clrscr
   mov edx, OFFSET str1; input score from user
   call WriteString
   call ReadInt
   call Crlf

   cmp eax, 0 ; score < 0
   jl Erorr ; 단축 평가 구현

   cmp eax, 100 ; score > 100
   jg Erorr

   cmp eax, 90 ; score >= 90
   jge Grade_A

   cmp eax, 80 ; score >= 80
   jge Grade_B

   cmp eax, 70 ; score >= 70
   jge Grade_C

   cmp eax, 60 ; score >= 60
   jge Grade_D
   jmp Grade_F


Erorr:
   mov edx, OFFSET str3
   call WriteString
   call crlf
   exit

Grade_A:
   mov al,'A'
   jmp GRADE_PRN

Grade_B:
   mov al,'B'
   jmp GRADE_PRN

Grade_C:
   mov al,'C'
   jmp GRADE_PRN

Grade_D:
   mov al,'D'
   jmp GRADE_PRN

Grade_F:
   mov al,'F'

GRADE_PRN:
   mov edx,OFFSET str2
   call WriteString
   call WriteChar ; display grade leter in AL
   call Crlf

   exit
main ENDP
END main