汇编语言(三)之判断数值是否大于42H并统计个数
在内存中一串数值,判断数值是否大于42H并统计个数
程序运行:
代码:
datas segment
idata equ 100h
nums db idata dup(41h,42h,43h,42h,41h,43h,30h)
count dw $-nums
up dw 0
down dw 0
upNumber db 'up:$'
downNumber db 0dh,0ah,'down:$'
datas ends
stacks segment
stacks ends
codes segment
main proc far
assume cs:codes,ds:datas,ss:stacks
start:
push ds
sub ax,ax
push ax
mov ax,datas ;初始化ds
mov ds,ax
mov cx,count
mov bx,0
s:
cmp nums[bx],42h
ja upAdd ;如果muns[bx]>42h,则跳到up++
jb downAdd ;如果muns[bx]<42h,则跳到down++
jmp s1
upAdd:
inc up ;up++
jmp s1
downAdd:
inc down ;down++
s1:
inc bx
loop s
;输出up提示
lea dx,upNumber
mov ah,9
int 21h
;输出up
mov ax,up
call print
;输出down提示
lea dx,downNumber
mov ah,9
int 21h
;输出down
mov ax,down
call print
ret
main endp
print proc near
mov bx,10
s: mov dx,0
div bx
add dx,30h
push dx
inc cx
cmp ax,0
jnz s
s1: pop dx
mov ah,2
int 21h
loop s1
ret
print endp
codes ends
end main