您的位置:首页 > 其它

汇编语言-计算总平成绩

2014-05-17 23:39 549 查看

计算总评成绩

题目:从键盘输入一同学的期中成绩、实验成绩、期末成绩和它们在总评成绩中分别占的百分比,计算得到该同学的总评成绩,并显示出来。

要求:该程序提示输入3个成绩和所占百分比。可参考如下的例子显示:

grade 1 ? 85

percent 1 ? 20

grade 2 ? 75

percent 2 ? 20

grade 3 ? 82

percent 3 ? 60

score is : 81

总评成绩 = (期中成绩×百分比1+实验成绩×百分比2+期末成绩×百分比3)/100

; Example assembly language program --
; Author:  karllen
; Date:    revised 5/2014

.386
.MODEL FLAT

ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD

INCLUDE io.h            ; header file for input/output

cr      EQU     0dh     ; carriage return character
Lf      EQU     0ah     ; line feed

.STACK  4096            ; reserve 4096-byte stack

.DATA
promot1_1 BYTE "grade   1 ?  ",0
promot1_2 BYTE "percent 1 ?  ",0
promot2_1 BYTE "grade   2 ?  ",0
promot2_2 BYTE "percent 2 ?  ",0
promot3_1 BYTE "grade   3 ?  ",0
promot3_2 BYTE "percent 3 ?  ",0

value     BYTE 11 DUP(?)
onec      DWORD  ?
twoc      DWORD  ?
threec    DWORD  ?

answer    BYTE "score is: "
average   BYTE 11 DUP(?)
BYTE cr,Lf,0
.CODE
_start:
output   promot1_1    ;enter first grade and percent
input    value,11
atod     value
mov      onec,eax
mov      ebx,eax
output   promot1_2
input    value,11
atod     value
mul      ebx          ;calculate first grade*percent
mov      onec,eax

output   promot2_1    ;enter second grade and percent
input    value,11
atod     value
mov      twoc,eax
mov      ebx,eax
output   promot2_2
input    value,11
atod     value
mul      ebx          ;calculate second grade*percent
mov      twoc,eax

output   promot3_1    ;enter the third grade and percent
input    value,11
atod     value
mov      threec,eax
mov      ebx,eax
output   promot3_2
input    value,11
atod     value
mul      ebx          ;calculate the third grade and percent
mov      threec,eax

add      eax,onec     ;to calculate sum
add      eax,twoc
add      eax,threec

mov      ebx,100
div      ebx          ;to calculate the average

dtoa     average,eax
output   answer

INVOKE  ExitProcess, 0  ; exit with return code 0

PUBLIC _start                   ; make entry point public

END                             ; end of source code


测试

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐