view ppc/test/search.p @ 4:9f5c8e19f204 tip basis

Oops: fix for lab0
author Mike Spivey <mike@cs.ox.ac.uk>
date Mon, 15 Oct 2018 21:58:03 +0100
parents 5dd13b8deb54
children
line wrap: on
line source
(* search.p *)

const target = "abracadabra";

var i: integer; found: boolean;

begin
  i := 0; found := false;
  while not found do
    found := target[i] = 'd';
    i := i + 1
  end;
  print_num(i);
  newline()
end.

(*<<
7
>>*)

(*[[
MODULE Main 0 0
IMPORT Lib 0
ENDHDR

PROC MAIN 0 0 0
!   i := 0; found := false;
CONST 0
STGW _i
CONST 0
STGC _found
!   while not found do
JUMP L3
LABEL L2
!     found := target[i] = 'd';
GLOBAL g1
LDGW _i
LDIC
CONST 100
EQ
STGC _found
!     i := i + 1
LDGW _i
CONST 1
PLUS
STGW _i
LABEL L3
LDGC _found
JNEQZ L4
JUMP L2
LABEL L4
!   print_num(i);
LDGW _i
CONST 0
GLOBAL lib.print_num
PCALL 1
!   newline()
CONST 0
GLOBAL lib.newline
PCALL 0
RETURN
END

GLOVAR _i 4
GLOVAR _found 1
! String "abracadabra"
DEFINE g1
STRING 616272616361646162726100

! End
]]*)