x86128: (Default)
[personal profile] x86128
Внёс мелкие исправления и добавил выдачу листинга помимо трассировки. Дальше буду смотреть в сторону принципов изложенных в книге дракона по компиляторам.

Для примера:
module towers;

var
    n : integer;

procedure write2ln(x, y: integer);
begin
    writeint(x);
    writespace(1);
    writeint(y);
    writeln
end write2ln;

procedure hanoy(n, x, y, z: integer);
begin
    if n > 0 then
        hanoy(n-1, x, z, y);
        write2ln(x, y);
        hanoy(n-1, z, y, x)
    end

end hanoy;

begin
    n := 3;
    hanoy(n, 1, 2, 3)

end towers.


Листинг выглядит так:
TEXT:
00000:    write2ln VLOAD            -2
00001:             SYSCALL    writeint
00002:             DEALLOC           1
00003:             CONST             1
00004:             SYSCALL  writespace
00005:             DEALLOC           1
00006:             VLOAD            -1
00007:             SYSCALL    writeint
00008:             DEALLOC           1
00009:             SYSCALL     writeln
00010:             RETURN             
00011:       hanoy VLOAD            -4
00012:             CONST             0
00013:             RELOP             >
00014:             BR_ZERO          L0
00015:             VLOAD            -4
00016:             CONST             1
00017:             BINOP             -
00018:             VLOAD            -3
00019:             VLOAD            -1
00020:             VLOAD            -2
00021:             CALL             11
00022:             DEALLOC           4
00023:             VLOAD            -3
00024:             VLOAD            -2
00025:             CALL              0
00026:             DEALLOC           2
00027:             VLOAD            -4
00028:             CONST             1
00029:             BINOP             -
00030:             VLOAD            -1
00031:             VLOAD            -2
00032:             VLOAD            -3
00033:             CALL             11
00034:             DEALLOC           4
00035:          L0 
00036:             RETURN             
00037: towers_main ALLOC             1
00038:             CONST             3
00039:             VSTOR            -1
00040:             VLOAD            -1
00041:             CONST             1
00042:             CONST             2
00043:             CONST             3
00044:             CALL             11
00045:             DEALLOC           4
00046:             STOP          12345

CONSTANT TABLE:

PROCEDURE TABLE
    write2ln: 0
       hanoy: 11
 towers_main: 37


Результат работы:
1 2
1 3
2 3
1 2
3 1
3 2
1 2
STOP at 46, CYCLES=316, max stack size: 27

Profile

x86128: (Default)
x86128

April 2023

S M T W T F S
      1
2345678
9101112131415
16171819202122
232425 26272829
30      

Style Credit

Expand Cut Tags

No cut tags
Page generated May. 22nd, 2025 03:52 am
Powered by Dreamwidth Studios