• TP 7.0 pointer passing convension

    From Anton Shepelev@2:221/360 to All on Saturday, February 15, 2020 20:33:48
    Hello, all

    The Language Guide for Turbo Pascal 7.0 says:

    Variable parameters (var parameters) are always
    passed by reference--a pointer that points to the
    actual storage location.
    [...]
    A pointer-type parameter is passed as two words
    (a double word). The segment part is pushed
    before the offset part so that the offset part
    ends up at the lowest address.

    I have written the following proceudre that adds its
    first argument to the second:

    procedure AtoB(a: byte; var b: byte);
    begin asm
    PUSH AX { store AX }
    MOV DI, [BP+4] { store offset of b in DI }
    MOV ES, [BP+2] { store segment of b in ES }
    MOV AX, [BP+8] { store a in AX }
    MOV [DI], AX { assign AX to a }
    POP AX { restore AX }
    end end;

    Does not it show that the TP documentation is in er-
    ror, and pointers are put on stack backwards?

    ---
    * Origin: nntps://fidonews.mine.nu - Lake Ylo - Finland (2:221/360.0)
  • From Anton Shepelev@2:221/360 to Anton Shepelev on Saturday, February 15, 2020 22:40:34
    I wrote:

    procedure AtoB(a: byte; var b: byte);
    begin asm
    PUSH AX { store AX }
    MOV DI, [BP+4] { store offset of b in DI }
    MOV ES, [BP+2] { store segment of b in ES }
    MOV AX, [BP+8] { store a in AX }
    MOV [DI], AX { assign AX to a }
    POP AX { restore AX }
    end end;

    Here is a fixed version, without redundant opera-
    tions and with single-byte write:

    procedure AtoB(a: byte; var b: byte);
    begin asm
    MOV ES, [BP+2] { store segment of b in ES }
    MOV DI, [BP+4] { store offset of b in DI }
    MOV AX, [BP+8] { store a in AX }
    MOV [DI], AL { assign AL to a }
    end end;

    ---
    * Origin: nntps://fidonews.mine.nu - Lake Ylo - Finland (2:221/360.0)
  • From Anton Shepelev@2:221/360 to Anton Shepelev on Sunday, February 16, 2020 22:12:54
    I wrote:

    Here is a fixed version, without redundant opera-
    tions and with single-byte write:

    procedure AtoB(a: byte; var b: byte);
    begin asm
    MOV ES, [BP+2] { store segment of b in ES }
    MOV DI, [BP+4] { store offset of b in DI }
    MOV AX, [BP+8] { store a in AX }
    MOV [DI], AL { assign AX to a }
    end end;

    Problem solved. Here is the correct code in TP as-
    sembly:

    procedure AtoBRef(a: byte; var b: byte);
    begin asm
    MOV DI, [BP+4] { store offset of b in DI }
    MOV ES, [BP+6] { store segment of b in ES }
    MOV AX, [BP+8] { store a in AX }
    MOV [ES:DI], AL { assign AX to a }
    end end;

    It works as advertised.

    ---
    * Origin: nntps://fidonews.mine.nu - Lake Ylo - Finland (2:221/360.0)