实验内容
1) 设有10个学生成绩分别是76, 69,84,73,88,99,63,100和80。试编写一个子程序统计60-69分,70-79分,80-89分,90-99分和100分的人数,并分别放到S6,S7,S8,S9,S10单元中,要求用带参数的子程序调用
2)计算三组字数据中正数、负数和零的个数,并分别存入PCOUNT、MCOUNT、ZCOUNT单元。设三组数据首地址分别为ARRAY1、ARRAY2、ARRAY3。数据个数分别在CNT1、CNT2、CNT3。
子程序功能:统计一组字数据中正数、负数、零的个数。
主程序功能:三次调用子程序并将结果累加。源代码
1)
; multi-segment executable file template.
data segment
; add your data here!
pkey db "press any key...$"
grades dw 76,69,84,73,88,99,63,100,80,70
s6 db 0
s7 db 0
s8 db 0
s9 db 0
s10 db 0
table dw 6 dup(?)
ten db 10 ;用于运算
two db 2 ;用于运算
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
; set segment registers:
mov ax, data
mov ds, ax
mov es, ax
mov table,offset grades
mov table+2,offset s6
mov table+4,offset s7
mov table+6,offset s8
mov table+8,offset s9
mov table+10,offset s10
mov bx,offset table
call sta
call print
mov ax, 4c00h ; exit to operating system.
int 21h
ends
sta proc near
mov si,[bx]
mov cx,10
loop1:
mov ax,[si]
add si,2
div ten
sub al,5
mul two ;通过(成绩/10-5)*2来得到需要加一的地址
mov di,ax
mov ax,[bx][di]
mov di,ax
inc [di]
loop loop1
ret
sta endp
crlf proc near
mov dl,0dH
mov ah,2
int 21H
mov dl,0aH
mov ah,2
int 21H
ret
crlf endp
print proc near
mov cx,5
mov si,2
loop2:
mov di,[bx+si]
mov dl,[di]
add dl,30H
add si,2
mov ah,2
int 21H
call crlf
loop loop2
ret
print endp
end start ; set entry point and stop the assembler.
2)
; multi-segment executable file template.
data segment
; add your data here!
pkey db "press any key...$"
array1 dw 7,6,5,4,3,2,1,0,-1,-2,-3,-4,-5,-6,-7,-8
cnt1 dw 16
array2 dw 5,4,3,2,1,0,-1,-2,-3,-4,-5
cnt2 dw 11
array3 dw 2,1,0,-1,-2
cnt3 dw 5
pcount dw 0
mcount dw 0
zcount dw 0
table dw 6 dup(?)
ten dw 10
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
; set segment registers:
mov ax, data
mov ds, ax
mov es, ax
mov table,offset array1
mov table+2,offset cnt1
mov table+4,offset array2
mov table+6,offset cnt2
mov table+8,offset array3
mov table+10,offset cnt3
mov bx,offset table
call func
mov bx,offset table+4
call func
mov bx,offset table+8
call func
mov ax,pcount
call print ;以十进制输出正数的个数
mov ax,mcount
call print ;以十进制输出负数的个数
mov ax,zcount
call print ;以十进制输出零的个数
mov ax, 4c00h ; exit to operating system.
int 21h
ends
func proc near
mov si,[bx]
mov di,[bx+2]
mov cx,[di]
loop1:
mov ax,[si]
add si,2
cmp ax,0
jl tag1
jz tag2
inc pcount
jmp tag3
tag1:
inc mcount
jmp tag3
tag2:
inc zcount
tag3:
loop loop1
ret
func endp
crlf proc near
mov dl,0dH
mov ah,2
int 21H
mov dl,0aH
mov ah,2
int 21H
ret
crlf endp
print proc near ;通过除10压栈再出栈实现十进制输出
mov cx,0
loop2:
mov dx,0
div ten
inc cx
push dx
cmp ax,0
jz loop3
jmp loop2
loop3:
pop dx
add dl,30H
mov ah,2
int 21H
loop loop3
call crlf
ret
print endp
end start ; set entry point and stop the assembler.