【问题标题】:Incrementing CX counter in Assembly (TASM)在装配中递增 CX 计数器 (TASM)
【发布时间】:2017-02-05 05:47:32
【问题描述】:

我有过去几天一直在编写的汇编代码。它是我的作业,其条件应打印出从“A”到“J”的字符,但每个字母之间有一个星号 输出:A*B*C*....J*.

我们应该添加的限制是我们只能使用一个数据容器dl。另外,我们只能使用循环和跳转条件。

我已经完成了大部分工作,但我一直无法弄清楚为什么我的计数器 cx 在我的代码中没有很好地递增。这是我的代码:

.model
.code
org 100h
s: mov ax, 3   ;
   int 10h     ; just clearing the screen
   mov ah, 2
   mov cx, 1   ; counter is just set to one for possible increment
   mov dl, 'A' ; A is added to data container
   int 21h     ; prints out A
x: mov dl, '*' ; first asterisk is then added to container, replacing A
   int 21h     ; asterisk is printed out A*
   mov dl, 'A' ; asterisk is replace by A in the counter
y: inc dl      ;
   loop y      ; loops at y then increments container dl, A + 1-> B
   int 21h     ; prints out container, A*B
   inc cx      ; where the problem lies. Should increment but not
   cmp dl, 'J' ; if the character in container is not above j, jumps to..
   jna x       ; ..where x is
   int 20h     ; ends but doesnt due to infinite looping, container not reaching 'J'
end s

如果增量有效,我认为每次进程跳转到 x 然后传递到循环 y 时,假设 cx 已递增,它将循环并根据容器的多少递增容器计数器cx 在多次递增后保持不变。这将导致容器达到超过字母J的条件。

所以这几乎是我的问题。提前感谢您为我提供的任何帮助。

【问题讨论】:

  • 也许使用 add 而不是 inc。 add cx, 1 or w.e add指令是。
  • 我没有得到任务描述,dl 的“限制”是什么意思?您也在使用 cx 获取数据。无论如何,如果您正在执行 per-char 流输出,您将不得不通过 '*' 值破坏 dl,然后将其恢复为字母,因此您绝对必须使用其他东西作为数据。那么具体的限制是什么?没有内存缓冲区?没有堆栈使用? dh 不能用?为什么cx可以?顺便说一句,没有int 21h可以直接写入VRAM吗? :D 那么这将是微不足道的 :D (实际上不是,需要更多的寄存器来写入 ptr :/ )
  • 哦,对不起,我想我应该说的限制是我不能将 dl 的值存储到另一个容器中。应该通过添加'*'来销毁它,然后通过循环或跳转条件以我自己的方式恢复它。
  • “你不能存储dl”是唯一的限制吗?然后你可以简单地将'A' 计数到cl 中的'J'。并在字母输出之前将cl 复制到dl,然后用'*' 覆盖dl。我想说的是,我不反对人为限制的练习,但到目前为止,这对我来说没有多大意义。

标签: loops assembly increment tasm


【解决方案1】:

正如您使用调试器所看到的那样,它正在递增。问题是你有一个loop 命令,它将递减CX 直到它为零。因此,递增将始终使CX 为 1。

如果要保留该值,请将CX 推到loop 之前的堆栈,然后将其弹出。并拿一个调试器自己调试代码。

或者既然您只想将DL 增加CX,为什么不直接说ADD DL, CL 而不使用循环?

【讨论】:

  • 谢谢。 :D 我会尝试实现“添加”。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-04
  • 1970-01-01
  • 2016-10-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多