比如,要输出以下矩阵:
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
希望各位高手帮帮忙,我在此先谢过了!
data segment
array byte 25 dup (?)
count equ $-array
data ends
code segment 'code'
assume ds:data,cs:code
start:
mov ax,data
mov ds,ax
mov si,-1
mov cx,count
INP:inc si
mov ah,1
int 21h
mov array[si],al
cmp al,0dh
loopnz INP
cmp array[si],0dh
jnz A1
mov array[si],0
A1:mov cx,count
mov si,0
mov dl,0dh
mov ah,2
int 21h
mov dl,0ah
int 21h
OUTP:mov dl,array[si]
or dl,30h
mov ah,2
int 21h
inc si
mov ax,si
mov bl,5
div bl
cmp ah,0
jnz A2
mov dl,0dh
mov ah,2
int 21h
mov dl,0ah
int 21h
A2:loop OUTP
mov ah,4ch
int 21h
code ends
end start
data segment
array word 25 dup (?)
count equ 25
outnum byte 5 dup (?)
data ends
code segment 'code'
assume ds:data,cs:code
start:
mov ax,data
mov ds,ax
mov si,-2
mov cx,count
INP:inc si
inc si
call inputnum
loop INP
mov cx,count
mov si,0
mov dl,0dh
mov ah,2
int 21h
mov dl,0ah
int 21h
OUTP:call outputnum
mov dl,20h
mov ah,2
int 21h
inc si
inc si
mov ax,si
mov bl,10
div bl
cmp ah,0
jnz A2
mov dl,0dh
mov ah,2
int 21h
mov dl,0ah
int 21h
A2:loop OUTP
mov ah,4ch
int 21h
inputnum proc ;输入一个数的函数,以空格结束
push ax
push bx
push dx
push cx
AGN1:mov ah,1
int 21h
cmp al,' '
jz RET1
sub al,30h
mov ah,0
xchg bx,ax
mov cl,10
mul cl
xchg bx,ax
add bx,ax
jmp AGN1
RET1:mov array[si],bx
pop cx
pop dx
pop bx
pop ax
ret
inputnum endp
outputnum proc ;输出函数
push ax
push bx
push cx
push dx
push di
mov ax,array[si]
mov cx,5
mov di,0
AGN2:mov bl,10
div bl
mov dl,ah
or dl,30h
mov outnum[di],dl
inc di
mov ah,0
loop AGN2
mov cx,5
OUT1:dec di
mov dl,outnum[di]
mov ah,2
int 21h
loop OUT1
pop di
pop dx
pop cx
pop bx
pop ax
ret
outputnum endp
code ends
end start
现在可以接受0-65535的数了。但是输出时不足5位的地方会补0。。。。