做的匆忙,细节还要你自己修改一下:)
第一题
datarea segment
arr db 1,-2,3,0,60,-30,45,52,90,70
len dw 10 ;length of arr
positive db 10 dup(?) ;>0
c1 dw ?
negative db 10 dup(?) ;<0
c2 dw ?
c3 dw ?
datarea ends
coderea segment
main proc far
assume cs:coderea,ds:datarea
start:
push ds
sub ax,ax
push ax
mov ax,datarea
mov ds,ax
mov si,0 ;index of arr
mov di,0 ;index of positive
mov bx,0 ;index of negative
repeat:
cmp si,len
jge exit
cmp arr[si],0
jl movetonegative
jg movetopositive
inc si
jmp repeat
movetonegative:
mov al,arr[si]
mov negative[bx],al
inc bx
inc si
jmp repeat
movetopositive:
mov al,arr[si]
mov positive[di],al
inc di
inc si
jmp repeat
exit:
add di,1
add bx,1
mov c1,di
mov c2,bx
add c1,30h
mov dl,byte ptr c1 ;output the length of positive
mov ah,2
int 21h
add c2,30h
mov dl,byte ptr c2 ;output the length of negative
mov ah,2
int 21h
mov dl,byte ptr len
add dl,30h
mov ah,2
int 21h
ret
main endp
coderea ends
end
第二题
data segment
ary dw 1,-2,3,0,60,-30,45,52,90,70
conut dw 10
s1 dw ?
data ends
stack segment
dw 100 dupOP(?)
tos label word
stack ends
code1 segment
main proc far
assume cs:code1, ds:data, ss:stack
start:
mov ax, stack
mov ss, ax
mov sp, offset tos
push ds
sub ax, ax
push ax
mov ax, data
mov ds, ax
mov bx, offset ary
push bx
mov bx, offset count
push bx
mov bx, offset s1
push bx
call far ptr proadd
ret
main endp
code1 ends
code2 segment
assume cs:code2
proadd proc far
push bp
mov bp, sp
push ax
push cx
push si
push di
mov si, [bp+0ah]
mov di, [bp+8]
mov cx, [di]
mov di, [bp+6]
code2 ends
end start
xor ax, ax
next:
add ax, [si]
add si, 2
loop next
mov [di], ax
pop di
pop si
pop cx
pop ax
pop bp
ret 6
proadd endp