将数组中的正数和负数分离到两个数组
程序运行:
代码:
datas segmenta dw -1,2,3,4,-2,-3,5,6,7,8,9,-10,13,15,-5,-24,-36,34,53,-90count dw ($-a)/2p dw 20 dup(?)n dw 20 dup(?)pNumber dw 0nNumber dw 0outputpNumberPrompt db 'the plus size:$'outputnNumberPrompt db 0dh,0ah,'negtive size:$'datas endsstacks segmentdw 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 si,0mov di,0mov bx,0mov cx,counts:mov ax,a[bx]cmp ax,0jg plus ;ax为正数,则保存于p数组jl negtive ;ax为负数,则保存于n数组jmp s2 ;ax为0,则忽视plus:mov p[si],ax ;保存ax于p数组inc pNumber ;p数组长度加一add si,2 ;p数组单元下标加二jmp s2 ;跳转到s2negtive:mov n[di],ax ;保存ax于n数组inc nNumber ;n数组长度加一add di,2 ;n数组单元下标加二s2:add bx,2 ;a数组单元下标加二loop s;输出正数数组的长度提示lea dx,outputpNumberPromptmov ah,9int 21h;输出正数数组的长度mov ax,pNumbercall print;输出负数数组的长度提示lea dx,outputnNumberPromptmov ah,9int 21h;输出负数数组的长度mov ax,nNumbercall printretmain endpprint proc near;获取输出数的十进制字符保存在栈中mov bx,10mov cx,0sa: mov dx,0div bxpush dxinc cxcmp ax,0jne sa;输出数字字符mov ah,2ss1:pop dxadd dl,30hint 21hloop ss1ret
print endp
codes endsend main