我从我的同伴那里得到了这个汇编程序。.我的老师提供了它。不幸的是我错过了它。.请有人告诉我程序写的内容(输入/输出或目标)
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
MOV DX,0
MOV AH,1
INT 21H
WHILE_:
CMP AL,0DH
JE END_WHILE
INC DX
INT 21H
JMP WHILE_
END_WHILE:
MAIN ENDP
END MAIN
答案 0 :(得分:2)
我已为您评论:
.MODEL SMALL ; We're writing code for x86-16
.STACK 100H ; Give us a stack of 256 bytes
.CODE ; What follows is the code
MAIN PROC
MOV DX,0 ; Set the counter keeping track of the length of the string to 0
MOV AH,1 ; The DOS service we want is to read a character from standard input
INT 21H ; Call said DOS service
WHILE_:
CMP AL,0DH ; Is the character we read a carriage return?
JE END_WHILE ; if so jump to the end of the program
INC DX ; if not increment the counter keeping track of the string length
INT 21H ; Call the DOS service for reading the standard input again
JMP WHILE_ ; Jump back to _WHILE
END_WHILE:
MAIN ENDP ; Exit the procedure
END MAIN
为便于记录,您可以更简洁,更现代地编写本程序集:
.model small
.stack 0x100 ; This style of hex literal is more common nowadays
.code
main proc
mov ah, 1 ; We don't need to set this continually since nothing clobbers it
mov dx, -1
_while:
inc dx
int 0x21
cmp al, `\r` ; most modern assemblers will support string literals
jne _while
main endp
end main