當前位置:編程學習大全網 - 編程軟體 - 匯編 求平均數 急

匯編 求平均數 急

;................AVGSCORE.ASM.....................

DATA SEGMENT

MES1 DB '92,85,74,81,70,68,65,78,54,43',0AH,0DH

DB '94,100,83,88,79,83,79,69,62,60',0AH,0DH,'$' ;定義用於顯示的字符串

MES2 DW 92,85,74,81,70,68,65,78,54,43

DW 94,100,83,88,79,83,79,69,62,60 ;存放20個十進制數

;-------------------------------------------------

MES3 DB 'AVERAGE SORE=','$'

mes4 dw 100,10,1

DATA ENDS

code segment

assume cs:code,ds:data

start:

mov ax,data

mov ds,ax

MOV DX, OFFSET MES1 ;顯示源串

mov ah,9

int 21h

cld

lea si,MES2 ;定位源數

xor bp,bp

mov cx,20

next:

mov ax,[si]

add bp,ax

inc si

inc si

Q2:loop next

mov ax,bp

xor dx,dx

mov bx,20

div bx

mov bp,ax

lea dx,MES3

mov ah,9

int 21h

call ascii

mov ah,0 ;暫停

int 16h

mov ah,4ch;結束

int 21h

ascii: ;Hex 化為 Ascii

mov dx,bp

lea di,mes4

mov cx,3

Q5:mov ax,dx;余數

xor dx,dx

div word ptr [di]

or al,30h ;商化為 Ascii

cmp al,'0'

jnz Q6

mov al,20h

Q6:

mov ah,0eh;顯示

int 10h

inc di

inc di

loop Q5

ret

code ends

end start

用記事本保存為AVG.ASM,用MASM5.0編譯通過,沒發現妳說的錯誤.

註意記事本保存時,底下編碼應為ANSI格式.

  • 上一篇:SCJP認證怎麽報名
  • 下一篇:C語言:怎樣輸入壹個字母,輸出下壹個字母
  • copyright 2024編程學習大全網