P-code机

計算機科學中,P-code機(英語:P-code machine)是一種被設計來執行P-code的虛擬機器。P-code是一種被設計來運行在虛擬CPU上的匯編語言,即是我們現代所稱Bytecode的前身。P-code机这个词可用于形容所有这类机器(例如Java虚拟机MATLAB预编译的代码),或者特指最有名的P-code机,來自於Pascal語言,特別是UCSD Pascal實作。

虽然這個概念在1966左右年就已首次实现(于BCPL的O-code与Euler语言的P - a code),[1]但P-code这个词直到70年代初才首次出现。 1973年Nori, Ammann, Jensen, Hageli和Jacobi编写的Pascal-P編譯器[2] 和1975年尼克劳斯·维尔特写的Pascal-S編譯器是早期的两个生成P-code的编译器

P-code可以是一種與特定硬體平台無關的中間碼,一種虛擬機器碼。程式原始碼會先被轉換成P-code;轉換成P-code的程序,之後會由一個軟體來進行直譯。這個軟體可以模擬出一個假想的CPU來讀取p-code,之後將p-code轉換成實體機器碼來執行。但如果有足够的商业利益,可能可以實作做出该规格CPU的硬件实现(例如Pascal MicroEngine和Java处理器)。

UCSD p-Machine

架构

如很多其他p-code机一样,UCSD p-Machine是一个堆疊結構機器,这意味着大多数指令从堆栈中获取它们的操作数,并将结果放回堆栈上面。因此,“add”指令将堆栈最顶部的两个元素替换成它们的和。有几条指令就取一个参数。像Pascal一样,p-code是强类型语言,原生支持boolean (b), character (c), integer (i), real (r), set (s)和pointer (a)类型。

一些简单的指令:

Insn.   Stack   Stack   Description
        before  after
 
adi      i1 i2   i1+i2   add two integers
adr      r1 r2   r1+r2   add two reals
dvi      i1 i2   i1/i2   integer division
inn      i1 s1   b1      set membership; b1 = whether i1 is a member of s1
ldci     i1      i1      load integer constant
mov      a1      a2      move
not      b1      ~b1     boolean negation

环境

与其他基于堆栈的环境(如ForthJava虚拟机)不同的是,p-系统非常类似于真正的目标CPU,它只有一个堆栈供过程栈帧(提过返回地址等)和局部指令参数共享。机器的其中三个寄存器指向这个堆栈(向上增加):

第五个寄存器 PC 指向当前指令的代码区。

调用约定

栈帧是这样的:

EP ->
      local stack
SP -> ...
      locals
      ...
      parameters
      ...
      return address (previous PC)
      previous EP
      dynamic link (previous MP)
      static link (MP of surrounding procedure)
MP -> function return value

程序调用序列的工作方式如下:下面指令引入调用

 mst n

其中 n 指定嵌套级别的差异(记得Pascal支持过程嵌套)。这个指令会标记这个堆栈,即在上述栈帧中保留起始地5个格子,并初始化前面的 EP、动态链接和静态链接。

范例机器

尼克劳斯·维尔特在他1976年出的书《算法+数据结构=程序》中详述了一个简单的P-code机。这个机器有3个寄存器——一个程序计数器 p,一个基寄存器 b,和一个栈顶寄存器 t。一共有8个指令,其中一个(opr)有多种形式。

这是机器的Pascal代码:

const
	levmax=3;
	amax=2047; 
type 
	fct=(lit,opr,lod,sto,cal,int,jmp,jpc);
	instruction=packed record 
		f:fct;
		l:0..levmax;
		a:0..amax;
	end;

procedure interpret;

  const stacksize = 500;

  var
    p, b, t: integer; {program-, base-, topstack-registers}
    i: instruction; {instruction register}
    s: array [1..stacksize] of integer; {datastore}

  function base(l: integer): integer;
    var b1: integer;
  begin
    b1 := b; {find base l levels down}
    while l > 0 do begin
      b1 := s[b1];
      l := l - 1
    end;
    base := b1
  end {base};

begin
  writeln(' start pl/0');
  t := 0; b := 1; p := 0;
  s[1] := 0; s[2] := 0; s[3] := 0;
  repeat
    i := code[p]; p := p + 1;
    with i do
      case f of
        lit: begin t := t + 1; s[t] := a end;
        opr: 
          case a of {operator}
            0: 
              begin {return}
                t := b - 1; p := s[t + 3]; b := s[t + 2];
              end;
            1: s[t] := -s[t];
            2: begin t := t - 1; s[t] := s[t] + s[t + 1] end;
            3: begin t := t - 1; s[t] := s[t] - s[t + 1] end;
            4: begin t := t - 1; s[t] := s[t] * s[t + 1] end;
            5: begin t := t - 1; s[t] := s[t] div s[t + 1] end;
            6: s[t] := ord(odd(s[t]));
            8: begin t := t - 1; s[t] := ord(s[t] = s[t + 1]) end;
            9: begin t := t - 1; s[t] := ord(s[t] <> s[t + 1]) end;
            10: begin t := t - 1; s[t] := ord(s[t] < s[t + 1]) end;
            11: begin t := t - 1; s[t] := ord(s[t] >= s[t + 1]) end;
            12: begin t := t - 1; s[t] := ord(s[t] > s[t + 1]) end;
            13: begin t := t - 1; s[t] := ord(s[t] <= s[t + 1]) end;
          end;
        lod: begin t := t + 1; s[t] := s[base(l) + a] end;
        sto: begin s[base(l)+a] := s[t]; writeln(s[t]); t := t - 1 end;
        cal: 
          begin {generate new block mark}
            s[t + 1] := base(l); s[t + 2] := b; s[t + 3] := p;
            b := t + 1; p := a
          end;
        int: t := t + a;
        jmp: p := a;
        jpc: begin if s[t] = 0 then p := a; t := t - 1 end
      end {with, case}
  until p = 1;
  writeln(' end pl/0');
end {interpret};

这个机器是用来运行维尔特的PL/0的,一个为教学开发的Pascal子集编译器。

注释

  1. ^ Wirth, N.; Weber, H. EULER: a generalization of ALGOL, and its formal definition: Part II, Communications of the Association for Computing Machinery, Vol.9, No.2, pp.89-99. New York: ACM. 1966. [永久失效連結]
  2. ^ Nori, K.V.; Ammann, U.; Jensen, K.; Nageli, H. The Pascal P Compiler Implementation Notes. Zurich: Eidgen. Tech. Hochschule. 1975. 

延伸阅读

Read other articles:

Artikel ini sebatang kara, artinya tidak ada artikel lain yang memiliki pranala balik ke halaman ini.Bantulah menambah pranala ke artikel ini dari artikel yang berhubungan atau coba peralatan pencari pranala.Tag ini diberikan pada Maret 2023. ScandalsKulit album kumpulan Scandals.Kulit album kumpulan Scandals.Informasi latar belakangAsal MalaysiaPekerjaanVokal / PemuzikArtis terkaitBerkumpulanSitus webhttp://www.liriklagu.com/liriklagu_s/Scandals.htmlMantan anggotaAhwee - Vokal Opie - Gitar U...

 

 

Годы 1533 · 1534 · 1535 · 1536 — 1537 — 1538 · 1539 · 1540 · 1541 Десятилетия 1510-е · 1520-е — 1530-е — 1540-е · 1550-е Века XV век — XVI век — XVII век 2-е тысячелетие XIV век XV век XVI век XVII век XVIII век 1490-е 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500-е 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510-е 1510 1511 1512 1513 1514 1515 1516 ...

 

 

Miss IndonesiaLogo Miss IndonesiaTanggal pendirian2005TipeKontes kecantikanKantor pusat JakartaLokasi IndonesiaJumlah anggota Miss World(2006-sekarang)Miss ASEAN (2005)Bahasa resmi IndonesiaChairwoman and FounderLiliana TanoesoedibjoTokoh pentingMartha TilaarWulan TilaarLina PriscillaSitus webwww.missindonesia.co.id Miss Kalimantan Timur adalah sebuah gelar yang didapat bagi perwakilan provinsi Kalimantan Timur di ajang Miss Indonesia. Pemegang titel saat ini adalah Tabitha Vivi Wijayant...

Buddhist monk (1546–1623) This article is about the Ming dynasty Buddhist monk. For the Tang dynasty poet, see Hanshan (poet). Hanshan DeqingHānshān DéqīngChinese woodblock illustration of Hanshan DeqingMonastic and Abbot PersonalBorn5 November 1546Quanjiao, Nanzhili Province (now modern Anhui Province)Died5 November 1623Nanhua Temple, Caoxi, Guangdong ProvinceResting placeNanhua Temple, Caoxi, Guangdong ProvinceReligionBuddhismNationalityChineseParentFather: Cai Yen GaoEraMing DynastyR...

 

 

Cet article est une ébauche concernant l’histoire, la Renaissance et l’Écosse. Vous pouvez partager vos connaissances en l’améliorant (comment ?) selon les recommandations des projets correspondants. La reine d'Angleterre Élisabeth Ire (à droite). Le traité d'Édimbourg, également connu sous le nom de traité de Leith, est un traité établi le 5 juillet 1560 entre les envoyés de la reine Élisabeth Ire d'Angleterre et les représentants français du roi François II afin ...

 

 

1991 film by Robert Benton Billy BathgateOriginal Theatrical PosterDirected byRobert BentonScreenplay byTom StoppardBased onBilly Bathgateby E.L. DoctorowProduced byRobert F. ColesburyArlene DonovanStarring Dustin Hoffman Nicole Kidman Steven Hill Loren Dean Bruce Willis CinematographyNéstor AlmendrosEdited byAlan HeimDavid RayRobert M. ReitanoMusic byMark IshamProductioncompanyTouchstone PicturesDistributed byBuena Vista Pictures DistributionRelease date November 1, 1991 (199...

Private liberal arts college in Vermont, United States Goddard CollegeFormer namesGreen Mountain Central Institute & Goddard SeminaryTypePrivate online collegeEstablished1863; 161 years ago (1863)PresidentDan Hocoy[1]Academic staff64Administrative staff50Students220 (Spring 2024)Undergraduates112Postgraduates208LocationPlainfield, Vermont, United States44°16′44″N 72°26′22″W / 44.2789°N 72.4394°W / 44.2789; -72.4394CampusRural 1...

 

 

Johan Rudolph Thorbecke Ministro-presidente dei Paesi BassiDurata mandato4 gennaio 1871 –4 giugno 1872 MonarcaGuglielmo III PredecessorePieter Philip van Bosse SuccessoreGerrit de Vries Durata mandato1º febbraio 1862 –10 febbraio 1866 MonarcaGuglielmo III PredecessoreSchelto van Heemstra SuccessoreIsaäc Dignus Fransen van de Putte Durata mandato1º novembre 1849 –19 aprile 1853 MonarcaGuglielmo III PredecessoreJacob de Kempenaer SuccessoreFlor...

 

 

1947 history book The Unknown Revolution AuthorVolineSubjectRussian historyPublication date1947 The Unknown Revolution is a 1947 history of the Russian Revolution by Voline. Publication Voline finished the book in 1940 while in Marseilles.[1] After his death in 1945,[2] it was first published posthumously in 1947. Following 1968 events in France, the book was republished in French paperback without additional editorial content by Pierre Belfond [fr] as part of a s...

Musical genre Third streamStylistic originsJazzclassicalCultural originsUnited StatesTypical instrumentsInstruments commonly used in jazzinstruments commonly used in classical music Third stream is a music genre that is a fusion of jazz and classical music. The term was coined in 1957 by composer Gunther Schuller in a lecture at Brandeis University. There are many ways to define third-stream music. It could refer to a group of jazz musicians playing solely, or a jazz soloist performing with a...

 

 

Central中環Stasiun angkutan cepat MTRPeron 1 dan 2 pada Jalur Tsuen WanNama TionghoaHanzi Tradisional 中環 Hanzi Sederhana 中环 Hanyu PinyinZhōnghuánYale KantonJūngwàan Arti harfiahCentral ringTranskripsiTionghoa StandarHanyu PinyinZhōnghuánYue: KantonRomanisasi YaleJūngwàanJyutpingZung1waan4 Informasi umumLokasiDes Voeux Road Central/Chater Road, CentralDistrik Pusat dan Barat, Hong KongKoordinat22°16′55″N 114°09′27″E / 22.2820°N 114.1576°Eþ...

 

 

Political party in Brazil Not to be confused with the American Party for Socialism and Liberation. This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages) This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Socialism and Liberty Party – n...

South Madrid derbyDerby at Butarque, played in 2018Location Community of MadridTeamsGetafe CFCD LeganésLatest meetingLeganés 0–3 GetafeLa Liga(17 January 2020)StadiumsColiseum Alfonso Pérez (Getafe)Butarque (Leganés)StatisticsMeetings total35 matches[1]Most winsLeganés (13 matches)[1] The South Madrid derby (Spanish: Derbi del sur de Madrid), is the name given to any association football match contested between Getafe CF and CD Leganés, the two biggest teams in the sou...

 

 

Untuk kegunaan lain, lihat East of Eden (disambiguasi). East of EdenPoster promosi untuk East of EdenGenreActionRomanceDramaDitulis olehNa Yeon-sookLee Hong-kuSutradaraSo Won-youngPemeranSong Seung-heonYeon Jung-hoonLee Da-haeHan Ji-hyePark Hae-jinLee Yeon-heeLagu pembukaReversal of Fate oleh SG Wannabe dan Kim Jong-wookNegara asalKorea SelatanBahasa asliKoreaJmlh. episode56ProduksiProduserKim Jin-manChoi Byeong-kilLokasi produksiKorea Hong Kong Makau FilipinaSinematografiHa Jae-young Jung Se...

 

 

For the town in France, see Bretten, Haut-Rhin. Town in Baden-Württemberg, GermanyBretten Town FlagCoat of armsLocation of Bretten within Karlsruhe district Bretten Show map of GermanyBretten Show map of Baden-WürttembergCoordinates: 49°02′11″N 08°42′22″E / 49.03639°N 8.70611°E / 49.03639; 8.70611CountryGermanyStateBaden-WürttembergAdmin. regionKarlsruhe DistrictKarlsruhe Subdivisions10Government • Lord mayor (2017–25) Martin Wolff[...

Outflow of 3 million refugees from communism in the late 20th century A map of French Indochina. North and South Vietnam were divided north of the city of Hue and had different governments from 1954 until 1976 when the country was formally re-united. The Indochina refugee crisis was the large outflow of people from the former French colonies of Indochina, comprising the countries of Vietnam, Cambodia, and Laos, after communist governments were established in 1975. Over the next 25 years and o...

 

 

Poster BoyPoster layar lebarSutradaraZak TuckerProduserDolly HallHerbert RossJeffrey H. CampagnaRebecca ChaiklinVince P. MaggioDitulis olehLecia RosenthalRyan ShirakiPemeranMatt NewtonKaren AllenMichael LernerJack NoseworthyPenata musikMark GarciaSinematograferLee GeissbuhlerWolfgang HeldWilliam RexerPenyuntingZak TuckerPamela Scott ArnoldTrevor RistowPerusahaanproduksiShallow PicturesDistributorRegent ReleasingTanggal rilis 08 Mei 2004 (2004-05-08) (Tribeca) Durasi98 menitNega...

 

 

周期表(2018年6月時点の版) ドミトリ・メンデレーエフ 周期表(しゅうきひょう、英: periodic table)は、物質を構成する基本単位である元素を、周期律を利用して並べた表である。元素を原子番号の順に並べたとき、物理的または化学的性質が周期的に変化する性質を周期律といい、周期表では性質の類似した元素が縦に並ぶように配列されている。「周期律表」や�...

German WWII fighter aircraft family Bf 109 A Bf 109G-6 of JG 27 Afrika in flight, 1943General informationTypeFighterManufacturerBayerische Flugzeugwerke (BFW)Messerschmitt AGDesigner Willy Messerschmitt, Robert LusserPrimary usersLuftwaffe Royal Hungarian Air ForceNational Republican Air ForceRoyal Romanian Air Force Number built34,248[1] +603 Avia S-199+239 HA-1112HistoryIntroduction dateFebruary 1937First flight29 May 1935[2]Retired9 May 1945, Luftwaffe27 December 1965, Span...

 

 

Place in Styria, SloveniaMarijina VasMarijina VasLocation in SloveniaCoordinates: 46°5′26.65″N 15°21′52.84″E / 46.0907361°N 15.3646778°E / 46.0907361; 15.3646778Country SloveniaTraditional regionStyriaStatistical regionSavinjaMunicipalityLaškoArea • Total7.54 km2 (2.91 sq mi)Elevation562.8 m (1,846.5 ft)Population (2002) • Total79[1] Marijina Vas (pronounced [maˈɾiːjina ˈʋaːs]; Slo...