【任务】
内存自BUF单元开始的缓冲区连续存放着100个学生的英文分数,编程序统计其中90~100、60~89、60以下者各有多少人?并把结果连续存放到自RESUT开始的单元中。
【参考解答1】
assume ds:data, ss:stack, cs:code
data segment
buf db 85, 72, 79, 90, 79, 54, 63, 66, 83, 79, 71, 77, 77, 65, 89, 93
db 69, 96, 72, 98, 60, 78, 69, 68, 80, 65, 91, 64, 90, 90, 64, 90
db 99, 55, 84, 56, 80, 54, 55, 66, 53, 54, 83, 61, 52, 92, 66, 51
db 95, 81, 51, 100, 70, 65, 50, 74, 91, 57, 95, 66, 54, 50, 73, 59
db 78, 80, 92, 78, 89, 78, 99, 100, 82, 92, 59, 71, 74, 81, 93, 74
db 98, 57, 57, 96, 76, 79, 57, 67, 52, 84, 87, 54, 67, 72, 59, 75
db 64, 89, 77, 80
resut db 3 dup(0)
data ends
stack segment stack
db 100H dup(0)
stack ends
code segment
start:
mov ax, data
mov ds, ax
mov es, ax
mov ax, stack
mov ss, ax
mov sp, 100H
mov bx, 0
mov cx, 100
ao:mov al, buf[bx]
cmp al, 90
jl l60
inc [resut] ;90-100的人数
jmp com
l60: cmp al, 60
jge k8960
inc [resut+2] ;60以下
jmp com
k8960: inc [resut+1] ;60-89
com: inc bx
loop ao
mov ax, 4c00h
int 21h
code ends
end start
【参考解答2】
assume ds:data, ss:stack, cs:code
data segment
buf db 85, 72, 79, 90, 79, 54, 63, 66, 83, 79, 71, 77, 77, 65, 89, 93
db 69, 96, 72, 98, 60, 78, 69, 68, 80, 65, 91, 64, 90, 90, 64, 90
db 99, 55, 84, 56, 80, 54, 55, 66, 53, 54, 83, 61, 52, 92, 66, 51
db 95, 81, 51, 100, 70, 65, 50, 74, 91, 57, 95, 66, 54, 50, 73, 59
db 78, 80, 92, 78, 89, 78, 99, 100, 82, 92, 59, 71, 74, 81, 93, 74
db 98, 57, 57, 96, 76, 79, 57, 67, 52, 84, 87, 54, 67, 72, 59, 75
db 64, 89, 77, 80
resut db 3 dup(0)
data ends
stack segment stack
db 100H dup(0)
stack ends
code segment
start:
mov ax, data
mov ds, ax
mov es, ax
mov ax, stack
mov ss, ax
mov sp, 100H
lea si, buf
mov cx, 100
cld
ao:lodsb ;lodsb指令见后说明
cmp al, 90
jl l60
inc [resut] ;90-100的人数
jmp com
l60: cmp al, 60
jge k8960
inc [resut+2] ;60以下
jmp com
k8960: inc [resut+1] ;60-89
com: loop ao
mov ax, 4c00h
int 21h
code ends
end start
【指令说明】
- 汇编语言中,串操作指令LODSB/LODSW是块读出指令,其具体操作是把SI指向的存储单元读入累加器,其中LODSB是读入AL,LODSW是读入AX中,、,然后SI自动增加或减小1或2位。当方向标志位DF=0时,则SI自动增加;DF=1时,SI自动减小。
- 与LODSB/LODSW类似的,STOSB/STOSW是块写入指令,其具体操作是把累加器的内容写入到指向的存储单元中。其中STOSB是从AL中读入,STOSW是从AX中读入,然后SI自动增加或减小1或2位。当方向标志位DF=0时,则SI自动增加;DF=1时,SI自动减小。