Я не понимаю эту программу на языке ассемблера для чего (что будет входом или выходом) - PullRequest
0 голосов
/ 11 мая 2019

Я получил эту программу сборки от моего помощника. Мой учитель предоставил ее. К сожалению, я пропустил ее. Пожалуйста, кто-нибудь скажет мне, для чего написана программа (ввод / вывод или цели)

.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 Ответ

2 голосов
/ 16 мая 2019

Я прокомментировал это для вас:

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