我需要注释此代码的帮助。
我的作业表明我需要“将每行的内容写为代码注释”。
我不确定我是否正确评论了
.386
.model flat
.data
quote byte "Machines do feel",0 ; message output
message byte SIZEOF quote DUP(0),0
.code
start proc ; start of the procedure
mov esi, 0 ; value of esi is zero
mov ecx, SIZEOF quote ; stores size of the text in ecx
LP:
mov al, quote[esi]
mov message[esi],al
inc esi ; increment esi's value
loop LP ; loop
ret
start endp
end start
答案 0 :(得分:1)
我没有看到任何理由仅因为汇编语言而使注释规则显着不同。 “评论为什么。”但是因为寄存器名很烂,所以我们必须注释一下它们的用途,就像其他无法使用好名字的情况一样。
.386
.model flat
.data
quote byte "Machines do feel",0 ; message output
message byte SIZEOF quote DUP(0),0
.code
start proc
mov esi, 0 ; esi = offset counter
mov ecx, SIZEOF quote ; ecx = loop counter
LP:
mov al, quote[esi] ; Copy bytes from quote to message
mov message[esi],al
inc esi
loop LP
ret
start endp
end start
此缩进不是惯用的,但它是一致的,因此我不会对此进行讨论。
但是,为什么要像它的入口点那样称呼这个起点?作为入口点,这没有任何意义。
答案 1 :(得分:1)
如果您的作业表明您需要“写每行的内容作为对代码的注释”;那么您需要写每行的内容(而不仅仅是每条指令的内容)。
假设您不需要注释空白行(“仅限空白”);您还没有评论的11行。
例如(仅前几行),您可能想要以下内容:
.386 ;Tell assembler that the code is intended for an 80386 CPU (e.g. allow 32-bit instructions)
.model flat ;Tell assembler to use the "flat" memory model (no use of segments and segment registers)
.data ;Tell assembler that subsequent lines are for the ".data" section of the output file
当然(正如其他人提到的那样),您永远不会在常规编程中这样做-纯粹是为了满足作业的要求。