我在理解HLA中的这个任务时遇到了麻烦。
编写一个程序来生成一个数字表格,如下所述。此表应由用户提供的单个整数值构建。程序将显示一个包含各种数字的正方形5X5。输入的数字应该以类似于X的模式出现在表格的对角线上。除了X图案之外,每个其他的点都应该填充一个数字。这些多余的数字应该以比输入的数字大1开始,每使用一个额外的多余数字就递增1。
例如,当用户输入起始值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中显示它。是否需要为每行的列添加更多变量。出于测试目的,我只添加了一列。如果你能帮上忙,我会很感激。谢谢!
发布于 2020-06-03 05:31:21
环境
(高级汇编程序-硬件后端,POLINK链接器)
笔记
示例
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;
https://stackoverflow.com/questions/61222635
复制相似问题