用汇编语言编一个程序,要求如下:

来源:百度知道 编辑:UC知道 时间:2024/07/12 03:50:35
从键盘输入并显示最多50个字符(以回车符结尾),将它们存放到内存中从TABLE单元开始的区域,检索第一个为零的字符,并显示出它是输入的第几个字符。

用十进制形式显示字符位置的代码如下:
DSEG SEGMENT
msgi db "please input a string:$";显示信息,提示输入一串字符
buf db 50,0
table db 50 dup (?);输入字符串缓冲区
msgd db 0dh,0ah,"the location is:$";显示信息,提示0所在位置
DSEG ENDS
CSEG SEGMENT
assume cs:CSEG, ds:DSEG,es:DSEG
MAIN PROC FAR ;主程序入口
mov ax, dseg
mov ds, ax
mov es,ax

lea dx,msgi;显示信息,提示输入一串字符
mov ah,9
int 21h

lea dx,buf;输入字符串
mov ah,0ah
int 21h

lea si,buf
mov cl,[si+1];输入字符实际个数存入CX中
mov ch,0
lea di,table;输入字符起始地址存入DI
mov al,30h;要查找的字符0送AL
cld;置方向标志为地址增量
repnz scasb
jnz tj

lea dx,msgd;显示信息,提示0所在位置
mov ah,9
int 21h
sub di,offset table
mov bx,di
call disp;用十进制形式显示位置
tj:
mov ah,1;按任意键退出
int 21h
mov ax, 4c00h ;程序结束,返回到操作系统系统
int 21h
MAIN ENDP

disp proc near
mov cx,10000d
call dec_div
mov cx,1000d
call