+ -
当前位置:首页 → 问答吧 → 一个汇编程序,统计一个数组的正负数及零的个数,请帮忙看看有什么错误!!!谢谢!!!

一个汇编程序,统计一个数组的正负数及零的个数,请帮忙看看有什么错误!!!谢谢!!!

时间:2011-06-19

来源:互联网

DATAS SEGMENT
NUMBER DW 1,2,3,4,5,6,0,0,-1,-2
LEN EQU $-NUMBER
  COUNT1 DB 0
COUNT2 DB 0
COUNT3 DB 0
  ;此处输入数据段代码  
DATAS ENDS

STACKS SEGMENT
  ;此处输入堆栈段代码
STACKS ENDS

CODES SEGMENT
  ASSUME CS:CODES,DS:DATAS,SS:STACKS
MAIN:
  MOV AX,DATAS
MOV DS,AX
MOV CX,LEN
LEA SI,NUMBER
MOV AX,0
CMP AX,[SI]
JB NEXT2
JA NEXT3
INC COUNT2
INC SI
LOOP MAIN
JMP NEXT3
NEXT1:
INC COUNT1
INC SI
LOOP MAIN
JMP NEXT3

NEXT2:
INC COUNT3
INC SI
LOOP MAIN
JMP NEXT3
NEXT3:  
MOV DL,COUNT1
OR DL,30H
MOV AH,02H
INT 21H
  ;此处输入代码段代码
  MOV AH,4CH
  INT 21H
CODES ENDS
  END MAIN

作者: byte_z   发布时间: 2011-06-19

Assembly code
;
;This Program Compiled Sucess by Masm 6.15
;
assume    cs:code,ds:data
data    segment
array    db    0,1,2,-3,4,2,-9,0,0,12,-8
_pos    db    0
_neg    db    0
_zero    db    0
numpos    db    'numbers of positive is : $'
numneg    db    'numbers of negative is : $'
numzero    db    'numbers of zere is : $'
data    ends
code    segment
start:
    mov ax,data
    mov ds,ax

    mov bx,offset array
    mov cx,lengthof array
s:
    cmp byte ptr [bx],0
    jg z
    cmp byte ptr [bx],0
    jl f
    inc _zero
    jmp jx
z:
    inc _pos
    jmp jx
f:
    inc _neg
jx:
    inc bx
    loop s

    mov dx,offset numpos
    mov ah,9
    int 21h
    mov dh,0
    mov dl,_pos
    call disp
    call crlf    

    mov dx,offset numneg
    mov ah,9
    int 21h
    mov dh,0
    mov dl,_neg
    call disp
    call crlf

    mov dx,offset numzero
    mov ah,9
    int 21h
    mov dh,0
    mov dl,_zero
    call disp

    mov ah,4ch
    int 21h
;input:dx
disp    proc uses dx
    mov ax,dx
    xor dx,dx
    mov bx,10
    mov cx,0
d2:    cmp ax,10
    jb ok2
    div bx
    add dl,30h
    push dx
    xor dx,dx
    inc cx
    jmp d2
ok2:    add al,30h
    push ax
    inc cx
d3:    pop dx
    mov ah,2
    int 21h
    loop d3
    ret
disp    endp
;
crlf    proc uses ax dx
    mov ah,2
    mov dl,13
    int 21h
    mov dl,10
    int 21h
    ret
crlf    endp
;
code    ends
end    start

作者: masmaster   发布时间: 2011-06-19