;加點分哈~~~~~~~~~~~~~~~~~~~~~~~~~~~
;-----------------------------------------------------------------
;-------------------------------
;宏定義
display MACRO string
mov ah,09h
lea dx,string
int 21h
ENDM
;-------------------------------
;********************************數據段
data segment
array db 100 dup(0) ;數組開辟空間
string1 db "Please input a string ended with ENTER: $" ;字符串以$結束
string2 db "The length of the string = $"
string3 db "The string you inputed is: $"
crlf db 13,10,13,10,"$" ;13回車,10換行
data ends
;**********************************
;**********************************代碼段
code segment
assume ds:data,cs:code ;段對應關系的說明
main proc far ;far子程序調用時的參數
;-----------------------------------------
start:
push ds
sub ax,ax ;清零
push ax ;壓棧
mov ax,data ;將數據傳送入數據段
mov ds,ax
;---------------------------------------
;主程序開始
;---------------------------------------------------------
;顯示"Please input a string ended with ENTER: $"的內容
display string1
;----------------------------------------------------------
;鍵盤輸入字符串以回車鍵結束
mov bx,offset array ;設定基址
mov di,0
input:
mov ah,01h
int 21h
cmp al,20h ;比對空格鍵不能輸入空格
je input
cmp al,0dh ;和'回車鍵'進行比較
je next
mov [bx+di],al ;存儲輸入字符
inc di
mov cx,di ;用cx保存di值
cmp di,64h
jbe input
;-----------------------------------------------
;輸出字符串的長度
next:
display crlf
display string2
mov ax,cx
mov bl,10h
div bl ;除以10
mov bh,ah ;將余數暫存起來
add al,30h
mov dl,al ;商
mov ah,02h
int 21h
add bh,30h
mov dl,bh ;余數
mov ah,02h
int 21h ;說明:最後結果兩位數是十六進制的
mov dl,'H'
mov ah,02h
int 21h
;-------------------------------------------
;輸出字符串
display crlf
display string3
mov bx,offset array ;設定基址
mov si,0
again:
mov al,[bx+si]
mov dl,al
mov ah,02h
int 21h
inc si
cmp si,cx
jbe again
ret
main endp ;主函數結束
;********************************************
code ends ;代碼段定義結束
end start ;這個程序段全部結束