简体   繁体   English

HLA程序是死循环?

[英]HLA program is an infinite loop?

So the program I'm trying to write in HLA should do the dollowing: I enter a digit, and it gives a pattern of numbers.所以我试图用 HLA 编写的程序应该执行以下操作:我输入一个数字,它会给出一个数字模式。 The pattern should show all the odd numbers from 1 up to that number followed by all the even numbers from 2 up to that number.该模式应显示从 1 到该数字的所有奇数,然后是从 2 到该数字的所有偶数。 Here is my code:这是我的代码:

program boxit; 
#include ("stdlib.hhf"); 
static iDatavalue : int8 := 0 ; 


Begin boxit; 

    stdout.put("Gimme a decimal value to use as n: "); 

    stdin.get(iDatavalue); 
    mov(iDatavalue, BH); 
DoWhileLp:
DoWhileLpBody:
ForLp:
InitializeForLp:
    mov(BH, CH); 
ForLpTerminationTest:
    cmp(CH, 0); 
    jnl ForLpDone; 
ForLpBody:
    stdout.put("I = ", CH, nl); 
ForLpIncrement:
    dec(CH); 
    jmp ForLpTerminationTest; 
ForLpDone:
    dec(CH); 
DoWhileLpTermination:
    cmp(CH, 0); 
    jbe DoWhileLpDone; 
    jmp DoWhileLpBody; 
DoWhileLpDone:
    stdout.puti8(BH); 

end boxit;

However, it is a infinite loop and I'm not sure how to solve this issue.但是,这是一个无限循环,我不确定如何解决这个问题。

I Highly appreciate any and all help!我非常感谢所有帮助!

ENVIRONMENT环境

  • HLA (High Level Assembler - HLABE back end, LD linker) Version 2.16 build 4409 (prototype) HLA(高级汇编程序 - HLABE 后端,LD 链接器)版本 2.16 build 4409(原型)
  • Ubuntu 20.04.1 Ubuntu 20.04.1

NOTE笔记

  • As mentioned in previous comments:正如之前评论中提到的:
    • Nested loops using the same loop control variable is poor design and leads to hard to debug problems such as an infinite loop.使用相同循环控制变量的嵌套循环设计不佳,会导致难以调试的问题,例如无限循环。
    • This assignment is more simply solved using two sequential loops instead of nested loops.使用两个顺序循环而不是嵌套循环可以更简单地解决此分配问题。
    • Starting with a higher level language to design the algorithm is good practice.从高级语言开始设计算法是一种很好的做法。 The following example provides a working solution using the higher level functionality of HLA which is a good starting point to work towards assembly.以下示例提供了一个使用 HLA 高级功能的工作解决方案,这是进行组装的良好起点。

EXAMPLE例子

program Boxit;
#include ("stdlib.hhf");

begin Boxit;
    stdout.put("Gimme a decimal value to use as n: ");
    stdin.geti32();

    for ( xor(EBX, EBX); EBX <= EAX; add(2, EBX) ) do
        stdout.puti32(EBX);
        stdout.put(", ");
    endfor;

    stdout.newln();

    for ( mov(1, EBX); EBX <= EAX; add(2, EBX) ) do
        stdout.puti32(EBX);
        stdout.put(", ");
    endfor;

end Boxit;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM