-3

我从我的伙伴那里得到了这个汇编程序..我的老师提供了它。不幸的是我错过了..请有人告诉我这个程序的目的是什么(输入/输出或目标)

.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
4

1 回答 1

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
于 2019-05-16T12:27:14.967 回答