我不了解此Assemby语言程序的用途(输入或输出是什么)

时间:2019-05-11 09:32:37

标签: assembly x86-16 microprocessors machine-language

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

.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

1 个答案:

答案 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