在数组中查找最小的偶数,并输出
程序运行:
代码:
datas segmentminEven dw 0DATA dw 10 dup(101,1,21,81,5,261,3,421,4,541)DATACount dw ($-DATA)/type DATAoutputPrompt db 'min even is AX=$'outputNonEven db 'DATA array have not even!$'
datas endsstacks segment stackdb 100h dup(?)stacks endscodes segmentassume cs:codes,ds:datas,ss:stacks
main proc far
start:push dsmov ax,0hpush axmov ax,datas ;初始化dsmov ds,axmov ax,1 ;初始化axlea bx,DATA ;获取DATA偏移地址mov cx,100s:mov dx,[bx] ;复制数据and dx,1 ;判断是否为偶数jnz s1 ;若为奇数,则跳转s1cmp ax,1 ;判断ax是否为1jz s2 ;若ax为1,则跳转s2cmp ax,[bx] ;判断ax与[bx]大小jle s1 ;若ax小于等于[bx],则跳转s1s2:mov ax,[bx] ;ax大于[bx]时,保存最小于axs1:add bx ,type DATA ;数组下标索引下一单元loop scmp ax,1 ;判断ax是否为1je nonEven ;若为1,则DATA数组没有偶数mov minEven,ax ;保存最小偶数axlea dx,outputPrompt ;输出ax提示mov ah,9int 21h mov ax,minEven ;输出axcall printjmp exitnonEven:lea dx,outputNonEven ;输出没有偶数提示mov ah,9int 21hexit:retmain endpprint proc nearmov bx,10mov cx,0sprint:mov dx,0div bxpush dxinc cxcmp ax,0jne sprintsprint1:pop dxadd dl,30hmov ah,2int 21hloop sprint1retprint endpcodes endsend main