【问题标题】:High Level Assembly (HLA) Programming高级装配 (HLA) 编程
【发布时间】:2020-04-15 06:30:53
【问题描述】:

我无法弄清楚我在 HLA 中的这项任务。

编写一个程序来生成此处描述的数字表。该表应由用户提供的单个整数值构建。该程序将显示各种数字的正方形 5X5。输入的数字应以 X 状出现在整个表格中,沿对角线穿过表格。除了 X 图案之外的每个其他点都应该用一个数字填充。这些多余的数字应该从比输入的数字大一开始,并且每使用一个额外的多余数字就增加一。

例如,当用户输入起始值 15 时,应产生如下输出:

给我一​​个起始值:15

15 16 17 18 15

19 15 20 15 21

22 23 15 24 25

26 15 27 15 28

15 29 30 31 15

例如,当用户输入起始值 20 时,应产生如下输出:

给我一​​个起始值:20

20 21 22 23 20

24 20 25 20 26

27 28 20 29 30

31 20 32 20 33

20 34 35 36 20

(提示:请不要担心表格的格式,如果它与我上面的不完全匹配。目标是使用 HLA 练习,我们真的不知道足够的间距来获得完美的间距。 ..)

我尝试过以下代码,但无法弄清楚。我是 HLA 编程的新手。

program tableX;

#include( "stdlib.hhf" );

// Initiate variable
static
tblX : int32 := 0; // tblX value

// Columns for row 1
column1 : int32 := 0;


// Start the program
begin tableX;

// Ask the user to input a value
stdout.put("Gimme a starting value: ");

// Get the user's inputted value
stdin.get(tblX);

// Get the value into the register EAX
mov(tblX, EAX);
mov(0, EBX);

mov(column1, EAX);
mov(1, EBX);

// Add the values
add(EAX, EBX);
add(1, tblX);

add(EAX, EBX);
add(1, column1);

// Put the value back into the tblX variable
mov(EBX, tblX);

// 1st row
stdout.put(tblX);
stdout.put(column1);




// End the program
end tableX;

我真的很难弄清楚如何以 5x5 显示它。我是否需要为每行的列添加更多变量。我只添加了一列用于测试目的。如果您能对此提供帮助,我将不胜感激。谢谢!

【问题讨论】:

    标签: hla


    【解决方案1】:

    环境

    • HLA(高级汇编器 - HLABE 后端,POLINK 链接器) 版本 2.16 build 4413(原型)
    • Windows 10

    注意

    • 有几种方法可以解决这个问题,这个例子可以改进。

    示例

    program tableX;
    #include( "stdlib.hhf" );
    
    // Initiate variable
    static
        OriginalVal: int32 := 0; // Original value
        DuplicateVal: int32 := 0; // Duplicate value for incrementing
        XPatternArray: int32[9] := [0, 4, 6, 8, 12, 16, 18, 20, 24]; // Indexes for X pattern
    
    // Start the program
    begin tableX;
    
        // Ask the user to input a value
        stdout.put("Gimme a starting value: ");
    
        // Get the user's inputted value
        stdin.get(OriginalVal);
        mov(OriginalVal, DuplicateVal);
    
        // Build and Print Table
        xor(EDX, EDX);
        for ( mov(0, EBX); EBX <= 24; inc(EBX) ) do
    
            mov(EBX, EAX);
            mov(5, ECX);
            idiv(CL);
            if ( AH == 0 ) then
                stdout.newln();
            endif;
    
            if ( EBX == XPatternArray[EDX*4] ) then
                stdout.put(OriginalVal, " ");
                inc(EDX);
    
            else
                inc(DuplicateVal);
                stdout.put(DuplicateVal, " ");
    
            endif;
    
        endfor;
    
    // End the program
    end tableX;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-23
      • 1970-01-01
      相关资源
      最近更新 更多