Assembly 下面的汇编语言代码是如何运行的?

Assembly 下面的汇编语言代码是如何运行的?,assembly,x86,masm,irvine32,Assembly,X86,Masm,Irvine32,我对组装一无所知,但我被分配了一项任务 请告诉我下面的代码是如何运行的?我指的是步骤或程序 TITLE MASM Template (main.asm) ; Description: ; ; Revision date:f INCLUDE Irvine32.inc .data counter dword 1; instruct1 BYTE"How many line are required?: ",0 ;give instruction to user to give the input

我对组装一无所知,但我被分配了一项任务

请告诉我下面的代码是如何运行的?我指的是步骤或程序

TITLE MASM Template (main.asm)

; Description: 
;
; Revision date:f

INCLUDE Irvine32.inc
.data
counter dword 1;
instruct1 BYTE"How many line are required?: ",0 ;give instruction to user to give the input
answer BYTE"Answer:",0

newline BYTE 0Dh, 0Ah

sum BYTE 0

.code
main PROC
mov edx,OFFSET instruct1 ;move instruct1 to edx
call WriteString
call readint;
mov ecx,eax; move ecx to eax
L1:

push ecx;
mov ecx,counter
L2:
mov al,'*';add '*' into al
call writechar;


loop l2;
pop ecx;
inc counter;
call crlf;
loop l1;



exit
main ENDP

end main

此代码打印提示并输入数字。然后它会打印出恒星的行数。第一行是1颗星,第二行是2颗星,依此类推。我对代码进行了注释,以使其更加清晰

代码使用两个嵌套循环来实现这一点。
ecx
寄存器用于两个循环:作为每行上星号的计数器,以及行计数。这就是为什么会按下并弹出
ecx
,这样它就可以在内部循环中有另一个计数

TITLE MASM Template (main.asm)      ;used for listings etc.

; Description: 
;
; Revision date:f

INCLUDE Irvine32.inc                ;include another code file

.data                               ;data segment

counter dword 1                     ;characters per line
instruct1 BYTE"How many line are required?: ",0
answer BYTE"Answer:",0              ;irrelevant to this code
newline BYTE 0Dh, 0Ah               ;used by crlf
sum BYTE 0                          ;irrelevant to this code

.code                               ;code segment

    main PROC                       ;declare code block

    mov edx,OFFSET instruct1        ;message pointer
    call WriteString                ;display message
    call readint                    ;input an integer
    mov ecx,eax                     ;move input to line loop register
L1:
    push ecx                        ;save line count register
    mov ecx,counter                 ;load character counter
L2:
    mov al,'*'                      ;the char we wish to print
    call writechar                  ;output one char
    loop L2                         ;next character (count in cx)
    pop ecx                         ;restore the line counter
    inc counter                     ;increment characters per line
    call crlf                       ;print the newline defined above
    loop L1                         ;next line (count in cx)

    exit                            ;return to OS
    main ENDP                       ;end code block
    end main                        ;end of code file
如果输入为3,则输出为:

*
**
***
顺便说一句,我会批评代码的作者,原因有二

mov ecx,eax     ; move ecx to eax
理由一。评论是背对背的;将行计数器的返回值
eax
移动到
ecx


理由2:永远不要用注释来解释指令的作用,你可以用RTM来解释。使用注释来增加价值,以明确其目的。

猜猜
调用WriteString
调用readint
做什么,然后查看字符串和注释,也许可以从那里开始工作?你能解释一下
调用WriteString
调用readint
是什么吗?tq它所做的是打印一个正方形的
*
字符。因此,如果用户输入2,它将打印两行
**
。如果用户输入4,它将打印4行
***
。如果你问“它是如何工作的?”,你必须更具体。
WriteString
ReadInt
是包含在文件顶部的包含文件“Irvine32.inc”中最有可能提供的函数。我怀疑
WriteString
向控制台写入字符串,而
ReadInt
读取用户从控制台输入的数字。