program MaxMin;
#include("stdlib.hhf")
static
count: int32:=0;
input: int32;
maxVal: int32;
minVal: int32;
sum: int32:=0;
boolVar : boolean:= true;
begin MaxMin;
while(boolVar) do
stdout.put("Enter a number, 0 to stop:");
stdin.get(input);
if(input==0)then
break;
elseif(count == 0)then
maxVal=input;
minVal=input;
elseif(input>maxVal)then
maxVal=input;
elseif(input<minVal)then
minVal=input;
endif;
add(input,sum);
add(1,count);
endwhile;
stdout.newln();
stdout.put("Total: ",sum,nl,"Count: ",count,nl,"Maximum: ",maxVal,nl,"Minimum: ",minVal,nl);
end MaxMin;
问问题
49 次
1 回答
0
环境
- HLA(高级汇编器 - HLABE 后端,LD 链接器)版本 2.16 build 4409(原型)
- Ubuntu 20.04.1
解决方案
- 问题是
maxVal=input;
HLA 中的语句无效。要纠正这个问题,我们的mov
说明如下:mov(input, maxVal);
。 - 但是,在此更正之后,您将看到以下错误:
Assembling "src.hla" to "src.o"
Error in file "src.hla" at line 27 [errid:102032/hlaparse.bsn]:
Memory to memory comparisons are illegal.
Near: << ) >>
hlaparse: oututils.c:2480: FreeOperand: Assertion `o->l.leftOperand != ((void *)0)' failed.
Aborted (core dumped)
- 这是因为 HLA 不支持内存对象之间的比较。一种解决方案是将用户输入的数字存储在其中
EAX
并将所有出现的input
变量更改为EAX
。
例子
program MaxMin;
#include("stdlib.hhf")
storage
maxVal: int32;
minVal: int32;
static
count: int32:= 0;
sum: int32:= 0;
boolVar: boolean:= true;
begin MaxMin;
while(boolVar) do
stdout.put("Enter a number, 0 to stop: ");
stdin.geti32();
if (EAX = 0 ) then
break;
elseif ( count = 0 ) then
mov(EAX, maxVal);
mov(EAX, minVal);
elseif (EAX > maxVal) then
mov(EAX, maxVal);
elseif (EAX < minVal) then
mov(EAX, minVal);
endif;
add(EAX, sum);
add(1, count);
endwhile;
stdout.newln();
stdout.put("Total: ",sum,nl,"Count: ",count,nl,"Maximum: ",maxVal,nl,"Minimum: ",minVal,nl);
end MaxMin;
于 2020-11-09T00:49:34.723 回答