汇编语言(五)之数组中正数和负数分离
生活随笔
收集整理的這篇文章主要介紹了
汇编语言(五)之数组中正数和负数分离
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
將數組中的正數和負數分離到兩個數組
程序運行:
?
代碼:
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?
總結
以上是生活随笔為你收集整理的汇编语言(五)之数组中正数和负数分离的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: USB 启动盘制作工具 Rufus 4.
- 下一篇: 汇编语言(六)之输出字符的前导后字符