S t r u k t a ------------- An Assembler Precompiler by Dipl.Ing. Rolf-Dieter Klein Strassbergerstr.34 8000 Muenchen 40 West Germany Price for STRUKTA including Source on a 8"Floppy is $25 Iî  thå worlä oæ microcomputinç therå arå twï maiî programminç systems®  Firsô  thå  assembleò  anä  seconä  thå  higè  leveì languages®  Programminç  iî  assembleò  ió  ofteî  verù  hard¬ especiallù  wheî verù largå programó havå tï  bå  constructed® Programminç  iî á higè leveì languagå ió verù smart¬  buô  thå compileró  arå noô verù efficienô anä iô ió nearlù  impossiblå tï   programí  standalonå  computeró  witè  realtimå  problemó becauså toï mucè codå ió generated®  Thougè thå compileró werå improveä  thå  amounô  oæ codå ió mucè morå thaî  aî  assemblù writteî  program®  Foò  thió  reasoî  STRUKTÁ  waó  developed® STRUKTÁ  ió  á reaì compileò foò CP/Í environmenô buô iô  onlù compileó thå structurinç statements®  Thaô ió thå resô oæ  thå programí ió normaì assembler¬ herå Z80-Assembleò ¨ foò examplå M8° ). Thå  compileò takeó alì whaô hå understandó anä  compileó  it¬ thå  resô remainó aó iô ió iî thå programm®  Sï iô ió possiblå to use all features of an exisiting assembler. Thå  mosô  erroró iî assembleò programminç arå tï  generatå  á reliablå  controì  structure®  Iî assembleró  therå  arå  onlù Š 1 JUMPs¬  RETURNó  anä CALLó aó controì structure®  Iô ió nearlù impossible to get a modern structured and modular program. Á seconä probleí ariseó wheî constructinç conditionaì jumpó oî comparisioî oæ valueó oò wheî rangechecking® STRUKTÁ generateó thå  appropriatå codå anä preventó thå programmeò froí  makinç mistakes. The language STRUKTA -------------------- Thå Keywordó oæ Struktá arå á mixturå oæ PASCAÌ anä  ADA®  Thå best things of both was taken. Struktá containó seveî maiî keywordsº  REPEAT¬ WHILE¬ LOOP¬ DÏ EXIT¬  EXITIÆ  anä  IF®  Á  BEGIΠ ENÄ ió  noô  exisitenô  buô thereforå closinç keywordó werå takenº UNTIL¬ ENDWHILE¬ ENDDO¬ ENDIF¬ ENDIÆ anä ELSE. Thå compileò workó recursivå anä sï thå commandó caî bå nesteä neary unlimited. The compiler also is written in STRUKTA. Witè  thå abovå statementó iô ió possiblå tï  writå  JUMP-freå Assemblerprogramms®  Oæ  courså CALLó anä RETó arå alloweä foò the purpose of a procedure construction. The DO-construct: Witè  thå  DÏ  commanä iô ió possiblå tï builä  loopó  witè  á loopcounter. Example: DO b,5 assemblystatements ENDDO Thå DÏ statementó haó tï parameters®  Thå firsô ió á  registeò Š 2 name¬  alloweä arå thå registeró A¬  B¬ C¬ D¬ E¬ H¬ L¬ BC¬ DE¬ HL¬ IØ anä IY® Thå registeró arå noô saved¬ sï thå useò haä tï uså á pusè poð iæ hå wanô tï uså thå registeró withiî thå looð foò  aî  otheò purpose®  Thå codå ió generateä  correctlù  foò singlå  anä  doublå registers¬  eveî thå registeró  ix,iù  arå allowed¬  buô sð ió forbidden® Thå seconä parameter¬ whicè caî bå omitteä ió useä tï iniô thå loop®  Iæ omitteä thå  registeò is assumed to be loaded by the user. Example for codegeneration: DO b,5 LD b,5 .L1: nop nop ENDDO DEC B JP NZ,.L1 and with double register: DO hl,1000 LD hl,1000 .L2: nop nop ENDDO DEC HL LD A,L OR H JP NZ,.L2 Bù  thå  waù  compileò labeló allwayó starô witè  .Ì  anä  thå followó  á dezimaì numbeò 1...6553¶ max®  Sï dï noô uså labeló whicè  looë  likå this®  Buô remember¬  yoõ onlù havå  tï  uså labeló foò procedurå nameó anä variables¬ becauså JUMPó arå nï longer necessary. Š 3 The LOOP-construction --------------------- Thå  LOOP-Statemenô ió useä tï builä loopó witè multiplå  exiô possibilities®  Thereforå  thå keywordó EXITIÆ anä  EXIÔ  alsï belonç tï thå looð construction®  Thå enä oæ thå looð ió giveî witè thå ENDLOOÐ command. EXITIÆ  getó  aî  additionaì  parameter¬  thå  condition®  Thå condition can be very complex. Example: LOOP EXITIF (hl)=0 ld (hl),' ' inc b EXITIF b=5 inc hl ENDLOOP The loop code is very tricky. LOOP LD HL,.L1 EX (SP),HL .L2: nop nop EXITIF a=0 OR A RET Z Š 4 EXITIF (hl)='a' LD A,(hl) CP 'a' RET Z nop nop ENDLOOP JP .L2 .L1: Witè thió constructioî thå exiô commandó becomå verù short®  Á reô  instructioî  caî bå useä tï leavå them®  Oî  nesteä  looð allways the inner loop is leaved and the next loop taken. The REPEAT construct -------------------- Iô ió á speziaì caså oæ loops®  Thå conditioî ió aô thå enä oæ the loop and therefore UNTIL gets a condition as parameter. Example: REPEAT call ci ;get consol input push af call calc ;do something pop af UNTIL not a in ['0'..'9','A'..'Z'] A small example for the generated code: REPEAT .L1: nop nop UNTIL B=0 LD A,B Š 5 OR A JP NZ,.L1 The WHILE construct ------------------- Thå  WHILÅ  statemenô askeä foò thå conditioî aô thå starô  oæ the loop and it is terminated with ENDWHILE. Example: call ci WHILE a=' ' call ci ENDWHILE Codegeneration: WHILE b=(hl) .L1: ld a,b cp (hl) JP NZ,.L2 nop nop ENDWHILE JP .L1 .L2: The IF-construction ------------------- Witè thió statemenô iô ió possiblå tï takå decisions®  ELSEIF¬ Š 6 ELSE and ENDIF also belong to this statement. Examples: IF b<=(hl) nop ENDIF ; IF a=0 nop ELSE nop ENDIF ; IF (ix+9)='a' nop ELSEIF b=0 nop ELSEIF b=8 nop ELSE nop ENDIF ; Š 7 IF Z nop ELSEIF a=0 AND b=0 nop ENDIF The Conditions: --------------- STRUKTÁ  ió verù flexiblå iî thå constructioî  oæ  conditions® Firsô alì oæ thå standarô conditionó caî bå used¬  foò examplå Z¬  NZ¬  C¬  NC¬  P¬ M¬ PE¬ PO® Twï additionaì conditionó werå provided OV and NV which are mainly used internaly. Everù Conditioî maù bå useä togetheò witè thå keywordó AND¬ OÒ and NOT. Brackets [ and ] can be used to nest the conditions. Example: NOT Z AND [P OR PO] Á  rangå constructioî witè IÎ likå iî PASCAÌ ió possible®  Thå syntaø isº  registeò IÎ Û lisô ]® Thå lisô caî contaiî singlå elements or ranges in any mixture. Example: b IN [0,4,66..99,2,100..111] Thå  conditionó  oæ  thå  abovå statemenô  ió  truå  wheî  thå contenså  oæ registeò  ió ° oò ´ oò á valuå betweeî 6¶ tï  9¹ includinç 6¶ anä 99¬ oò ² oò 10° oò á valuå betweeî 10° tï 11± including 100 and 111. Noô  onlù numberó arå allowed¬  buô alsï nameó  oò  characteró Š 8 enclosed in quotes: c IN ["A".."Z",space,'0'..'9'] Thå  lasô  grouð  arå thå  relations®  Á  comparisioî  betweeî registers, and values can be performed. As relations the following symbols are used: > < <= >= = <> Example: A < B (HL)='A' (IX+9)<>(IY+10) alpha=B (HL)<=L Aó Registeró onlù A,B,C,D,E,H,Ì anä thå indirekô (HL)¬ (IX+n)¬ (IY+n) are allowed. Valueó   caî  bå  singlå  characters¬   constantó  oò   simplå expressions with + and - for construktions like A <= maxchar-1 Thå generateä codå ió optimized® Iæ Registeò Á ió useä thå LD- instructionó ió omitted¬ arå comparisioî witè ° yieldó iî Á OÒ A or a XOR A is used to clear the accumulator. Thå   compileò  STRUKTÁ  ió  calleä  witè  thå  namå  oæ   thå struktaprogramm¬  wherå  thå prograí haó thå extensioî oæ .STÒ Thå resulô oæ thå compilatioî ió á filå witè thå extensioî  oæ froí Microsoft. Example: Your file is TEST.STR You type STRUKTA TEST and you get TEST.MAC Iæ   STRUKTÁ  ió  calleä  withouô  argumentó  iô  enteró   thå interactivå mode®  Therå yoõ caî learî Struktá becauså yoõ caî Š 9 inpuô  á  STRUKTA-linå anä yoõ immediatelù geô  thå  generateä code displayed on your terminal. STRUKTÁ  haó  alsï somå switchesº  /à meanó  compilatioî  anä removing of all comments for a short file. /Ì  meanó listinç tï thå consolå insteaä oæ generatinç á  filå and /P means listing to the printer. STRUKTÁ  compileó aó fasô aó 300° (reallù threethousand© lineó peò  minutå  whicè alsï showó thå efficiencù oæ  thå  languagå becauså  STRUKTÁ  ió writteî iî STRUKTÁ  (thå  preversioî  waó writteî  iî  PASCAÌ  anä 31Ë long¬  STRUKTÁ ió  no÷  10Ë  witè enhanceä  erroò handleò anä morå constructionó aó  thå  PASCAÌ versioî ). 10