assume cs:c,ds:d,ss:s
s segment stack
dw 128 dup(?)
s ends
d segment
X dw 10 dup (?)
B dw 10 dup (?)
N dw 0
A dw 100 dup(?)
msg db 'massiv=$'
cr = 0dh
lf = 0ah
string db 255, 0, 255 dup (?)
errmsg db 'error: illegal symbol'
crlf db cr,lf,'$'
negflag dw ?
d ends
c segment
IntegerOut proc
xor cx,cx
mov bx,10
cmp ax,0
jge m
neg ax
push ax
mov ah,6
mov dl,'-'
int 21h
pop ax
m: inc cx
xor dx,dx
div bx
push dx
or ax,ax
jnz m
m1: pop dx
add dx,'0'
mov ah,6
int 21h
loop m1
IntegerOut endp
IntegerIn proc
mov ah,0ah
lea dx,string
int 21h
xor ax,ax
lea si,string+2
mov negflag,ax
cmp byte ptr [si],'-'
jne m2
not negflag
inc si
jmp m3
m2: cmp byte ptr [si],'+'
jne m3
inc si
m3: cmp byte ptr [si],cr
je ex1
cmp byte ptr [si],'0'
jb er
cmp byte ptr [si],'9'
ja er
mov bx,10
mul bx
sub byte ptr [si],'0'
add al,[si]
adc ah,0
inc si
jmp m3
er: lea dx,errmsg
mov ah,9
int 21h
jmp IntegerIn
ex1: cmp negflag,0
je ex
neg ax
ex: push ax
mov ah,9
lea dx,crlf
int 21h
pop ax
ret
IntegerIn endp
start: mov Ax,d
mov Ds,Ax
mov Ah,9
lea Dx,MSG
int 21h
call IntegerIN
mov N,Ax
mov Cx,N
xor Si,Si
K: push Cx
push Si
call IntegerIN
pop Si
pop Cx
mov A[Si],Ax
add Si,2
loop K
;как бы мне сюда эти две процедуры вставить?
exit:
mov Cx,N
xor Si,Si
K2:
push Cx
push Si
mov Ax, A[Si]
call IntegerOut
pop Si
pop Cx
add Si,2
loop K2
mov Ah,4ch
int 21h
c ends
end start
сортировка слиянием (тасм х86)
Код:
[COLOR=red]как бы мне сюда эти две процедуры вставить??[/COLOR]
Код:
msort16:
pusha
mov bp, sp
mov ax, [ bp + 10h + 02h ] ;*firstbyte
mov dx, [ bp + 10h + 04h ] ;size
mov cx, dx
shr cx, 01h
test cx, cx
jz ms16_end
push cx
push ax
push cx
push ax
call msort16
sub dx, cx
add ax, cx
push dx
push ax
push dx
push ax
call msort16
call merge16
ms16_end:
popa
ret 0004h
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;
;
;merge16( char *firstbyte1, int size1, char *firstbyte2, int size2 )
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;
merge16:
pusha
mov bp, sp
mov bx, [ bp + 10h + 04h ] ;*size1
mov si, [ bp + 10h + 06h ] ;*firstbyte2
mov cx, [ bp + 10h + 08h ] ;*size2
mov bp, [ bp + 10h + 02h ] ;*firstbyte1
mov di, offset mass
mov dx, cx
add dx, bx
add bx, bp
add cx, si
cld
m16_fill:
lodsb
cmp al, [ bp ]
jb m16_si
mov al, [ bp ]
dec si
inc bp
stosb
cmp bp, bx
jnz m16_fill
jmp m16_over
m16_si:
stosb
cmp si, cx
jnz m16_fill
mov si, bp
mov cx, bx
m16_over:
sub cx, si
rep movsb
mov cx, dx
lea si, [ di - 01h ]
lea di, [ bx - 01h ]
std
rep movsb
popa
ret 0008h
pusha
mov bp, sp
mov ax, [ bp + 10h + 02h ] ;*firstbyte
mov dx, [ bp + 10h + 04h ] ;size
mov cx, dx
shr cx, 01h
test cx, cx
jz ms16_end
push cx
push ax
push cx
push ax
call msort16
sub dx, cx
add ax, cx
push dx
push ax
push dx
push ax
call msort16
call merge16
ms16_end:
popa
ret 0004h
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;
;
;merge16( char *firstbyte1, int size1, char *firstbyte2, int size2 )
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;
merge16:
pusha
mov bp, sp
mov bx, [ bp + 10h + 04h ] ;*size1
mov si, [ bp + 10h + 06h ] ;*firstbyte2
mov cx, [ bp + 10h + 08h ] ;*size2
mov bp, [ bp + 10h + 02h ] ;*firstbyte1
mov di, offset mass
mov dx, cx
add dx, bx
add bx, bp
add cx, si
cld
m16_fill:
lodsb
cmp al, [ bp ]
jb m16_si
mov al, [ bp ]
dec si
inc bp
stosb
cmp bp, bx
jnz m16_fill
jmp m16_over
m16_si:
stosb
cmp si, cx
jnz m16_fill
mov si, bp
mov cx, bx
m16_over:
sub cx, si
rep movsb
mov cx, dx
lea si, [ di - 01h ]
lea di, [ bx - 01h ]
std
rep movsb
popa
ret 0008h