|
主题 : : 如何用汇编实现嵌套循环 [待解决] |
回复[ 3次 ]
点击[ 567次 ] | |
荣誉值:0
信誉值:0
注册日期:2009-11-24 07:22 |
data segment
str db 100 ;句子
db ?
db 100 dup(?)
data ends
sseg segment stack
dw 20h dup(?)
tos label word
sseg ends
code segment
assume cs:code,ss:sseg,ds:data
start:
mov ax,offset data
mov ds,ax
mov ax,sseg
mov ss,ax
mov ah,0ah ;输入句子
mov dx,offset str
int 21h
mov ah,2 ;换行输出
mov dl,0dH
int 21h
mov dl,0aH
int 21h
mov bx,offset str ;将$ 赋给句末
mov al,str+1
and ah,0h
add bx,ax
add bx,2
mov al,24h
mov [bx],al
mov dx,offset str ;将句子输出
add dx,02h
mov ah,9h
int 21h
mov ah,2 ;换行输出
mov dl,0dH
int 21h
mov dl,0aH
int 21h
mov bx,offset str
add bx,1
and dx,0h
next: ;与空格和$比较
inc bx
mov ah,0
mov al,[bx]
cmp al,24h ;$
je out1
cmp al,20h ;空格
je next
mov cx,bx
inc dl ;记录单词个数
inc ah ;记录各个单词长度
mov si,0h ;记录最长单词首地址
next1: ;与空格或$比较
inc bx
mov al,[bx]
cmp al,20h
je next
cmp al,24h
je out1
inc ah
cmp dh,ah ;dh记录最长单词长度
jb lp1
jmp next1
lp1: mov dh,ah
mov si,cx
jmp next1
jmp out1
out1:
add dl,30h
mov ah,02h
int 21h
mov ah,2 ;换行输出
mov dl,0dH
int 21h
mov dl,0aH
int 21h
mov dl,dh
add dl,30h
mov ah,02h
int 21h
mov ah,2 ;换行输出
mov dl,0dH
int 21h
mov dl,0aH
int 21h
mov cl,dh
and ch,0h
next2: ;输出最长单词
mov dl,[si]
mov ah,02h
int 21h
inc si
loop next2
mov ah,01h
int 21h
mov ah,4ch
int 21h
code ends
end start
我这个程序已经能把一个最长单词输出,请问如果最长单词有多个应该怎么输出? | | |