注册 登录
编程论坛 汇编论坛

汇编求数组中分数段

情.难言ゝ 发布于 2014-05-25 18:08, 1300 次点击
程序代码:
data   segment
       score   dw   76,69,84,90,73,88,99,63,100,80
       mess    db   'the 10 students score :',13,10,'$'
       mess1   db   'the number of the score(60-69):','$'
       mess2   db   'the number of the score(70-79):','$'
       mess3   db   'the number of the score(80-89):','$'
       mess4   db   'the number of the score(90-99):','$'
       mess5   db   'the number of the score(100):','$'     
data   ends

extra  segment
       num1    dw   ?
       num2    dw   ?
       num3    dw   ?
       num4    dw   ?
       num5    dw   ?
extra  ends

code   segment
;宏定义输出指令print         
print  macro   addr
       mov     dx,addr
       mov     ah,09h
       int     21h
       endm

main   proc   far
      assume  cs:code,ds:data,es:extra
start:
       push    ds
       sub     ax,ax
       push    ax
      
       mov     ax,data
       mov     ds,ax
      
       mov     ax,extra
       mov     es,ax
      
;输出这10个成绩
       print   offset mess
       mov     cx,10
       mov     si,offset score
next1:
       print   si
       add     si,2
       loop    next1
      
       call    crlf
       call    son
      
;输出num1、num2、num3、num4、num5的值
       mov     cx,5
       mov     si,offset  mess1
       mov     di,offset  num1
result:
       print   si
       print   di
      
       call    crlf
       add     si,2
       add     di,2
       loop    result
      
       ret
main   endp
;回车换行crlf
crlf   proc    far
       push    dx
       push    ax
      
       mov     ah,02h
       mov     dl,0dh
       mov     dl,0ah
       int     21h
      
       pop     ax
       pop     dx
       ret
crlf   endp

son    proc    near
       push    ax
       push    bx
       push    cx
       push    si
       push    di
      
       mov     bx,69
       mov     cx,10
       mov     si,offset  score
       mov     di,offset  num1
;[si(score)分别与bx(69,79,89,99,109)比较
rotate:
       cmp     [si],bx
       jb      count
       cmp     bx,105
       je      next2
       add     bx,10
       jmp     rotate
count:
       ;inc     [di]
       add     di,2
next2:
       add     si,2
       loop    rotate
      
       pop     di
       pop     si
       pop     cx
       pop     bx
       pop     ax
       ret
son    endp
code   ends
       end     main

2 回复
#2
xkwy00002014-06-09 15:25
拒绝讨论带有‘宏定义’的问题,
原因不会使用‘宏定义’
#3
xkwy00002014-06-11 18:10
http://baike.baidu.com/view/2076445.htm?fr=aladdin
宏定义是C语言提供的三种预处理功能的其中一种,这三种预处理包括:宏定义、文件包含、条件编译。
不带参数宏定义又称为宏代换、宏替换,简称“宏”。 格式: #define 标识符 字符串
其中的标识符就是所谓的符号常量,也称为“宏名”。

print   offset mess   编译没有通过,可能 offset mess 需要是一个变量名  
1