为什么我的 HLA 程序检查值是否增加,无论输入什么,总是输出为 false?

问题描述 投票:0回答:1

我不明白为什么我的代码输出即使我输入不断增加的值,值也不会增加 输入值:2 输入值:4 输入一个值:10 数值没有增加

我也不明白这是什么意思 “返回调用者后,您的函数不应更改除 DX 之外的任何寄存器的值”。

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

static
    value1: int8;
    value2: int8;
    value3: int8;

procedure increasing( valuel : int8; value2 : int8; value3 : int8 ); @nodisplay; @noframe;
begin increasing;
    // Checking if value2 is greater than value1
    mov( valuel, AL );
    mov( value2, BL );
    mov( value3, CL );

    cmp( AL, BL );
    jge NotIncreasing;

    // Checking if value3 is greater than value2
    cmp( BL, CL );
    jge NotIncreasing;

    // If both conditions are true, it's increasing
    mov( 1, DX );
    jmp Done;

NotIncreasing:
    mov( 0, DX );

Done:
    ret();
    
end increasing;

begin IncreasingCheck;
    stdout.put( "Enter a value: " );
    stdin.get( value1 );

    stdout.put( "Enter a value: " );
    stdin.get( value2 );

    stdout.put( "Enter a value: " );
    stdin.get( value3 );

    // Call the increasing procedure
    call increasing;

    // Output result
    cmp(DX, 1);
    je Increase;
    jmp NoInc;
    
    Increase:
        stdout.put( "The values increase!" );
        jmp EndProgram;

    NoInc:
        stdout.put( "The values don't increase" );

    EndProgram:

end IncreasingCheck;
assembly x86 hla
1个回答
0
投票

我没有读兰迪·海德斯的书,也没有玩他的 HLA,但根据这个

https://www.plantation-products.com/Webster/www.artofasm.com/Linux/HTML/IntermediateProceduresa3.html#998787

看起来您没有将参数传递给

increasing proc
。弹出一些随机值。 此外,程序应该有序言和尾声,以便正确地从堆栈中弹出值。

    push (ebp);         // procedure prologue
    mov (esp,ebp);
    
    
        ...
    
    mov(ebp,esp);       // procedure epilogue
    pop(ebp);
    ret();

这是更正的程序:

procedure increasing( value1 : int8; value2 : int8; value3 : int8 ); @nodisplay; @noframe;
begin increasing;

    push (ebp);
    mov (esp,ebp);
    
    // Checking if value2 is greater than value1
    mov( value1, AL );
    mov( value2, BL );
    mov( value3, CL );

    cmp( AL, BL );
    jge NotIncreasing;

    // Checking if value3 is greater than value2
    cmp( BL, CL );
    jge NotIncreasing;

    // If both conditions are true, it's increasing
    mov( 1, DX );
    jmp Done;

NotIncreasing:
    mov( 0, DX );

Done:
    mov(ebp,esp);
    pop(ebp);
    ret();
    
end increasing;

以及如何触发它:

increasing(value1,value2,value3);

© www.soinside.com 2019 - 2024. All rights reserved.