【问题标题】:Why is "(" expected instead of "=" in the statement maxVal=input为什么在语句 maxVal=input 中需要“(”而不是“=”
【发布时间】:2020-10-18 18:23:17
【问题描述】:
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;

【问题讨论】:

  • 我不知道这种语言,但可能还有其他语法错误使编译器感到困惑(os it assembler?)。例如,您的赋值语句是否都应该像在程序的静态常量部分一样使用:=

标签: hla


【解决方案1】:

环境

  • 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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-19
    • 2017-09-27
    • 1970-01-01
    相关资源
    最近更新 更多