Boolean Operations – Turbo Pascal Compiler

https://turbopascal.org/boolean-operations

Turbo Pascal Compiler

Boolean Operations

Boolean operations are similar to integer operations. Constant Boolean operations are performed with boolean expressions converted to boolean bytes (0 or 1) and using procedures for integer calculation. Procedure ConstantBooleanOperations; begin LeftExpression.ConvertToBooleanByte; RightExpression.ConvertToBooleanByte; ConstantIntegerOperations; end;

Generating code for Boolean expression is no different from code for integer expressions with the exception of short-circuit evaluations. Boolean operations AND and OR can be decided after only one operant is calculated. If the first operand in boolean operation OR evaluates to True then there is no need to evaluate the second one. Similarly, if the first operand in boolean operation AND evaluates to False then there is no need to evaluate the second one. This procedure takes care for this. Short-circuit evaluation is a great example of the elegance of Turbo Pascal and boolean expressions using jump lists. Procedure GenerateCodeForBooleanOperations; Var LastJumpToTrue, LastJumpToFalse, TempWord: PWord; JumpIfTrueOpCode: Byte; begin If (FullBooleanEval in StatementCompilerSwitches) or not (Operation in [Calc_AND, Calc_OR]) then begin LeftExpression.ConvertToBooleanByte; RightExpression.ConvertToBooleanByte; GenerateCodeForIntegerOperations; Exit; end; LeftExpression.ConvertExpressionToBooleanJump; RightExpression.ConvertExpressionToBooleanJump; LeftExpression.Calculate; LastJumpToTrue := @LeftExpression.Value.LastJumpToTrue; LastJumpToFalse := @LeftExpression.Value.LastJumpToFalse; JumpIfTrueOpCode := LeftExpression.LocationData.JumpIfTrueOpCode; If Operation <> Calc_OR then begin JumpIfTrueOpCode := JumpIfTrueOpCode xor $01; TempWord := LastJumpToTrue; LastJumpToTrue := LastJumpToFalse; LastJumpToFalse := TempWord; end; GenerateCodeForNearJump (LastJumpToTrue^, JumpIfTrueOpCode); GenerateLabelAndSetJumpsToIt (LastJumpToFalse^); RightExpression.Calculate; LeftExpression.EndIntermediateCodeSubroutine; With LeftExpression do UsedRegisters := UsedRegisters + RightExpression.UsedRegisters; JoinJumpsOfBothExpressions (LeftExpression.Value.LastJumpToTrue, RightExpression.Value.LastJumpToTrue); JoinJumpsOfBothExpressions (LeftExpression.Value.LastJumpToFalse, RightExpression.Value.LastJumpToFalse); LeftExpression.LocationData.JumpIfTrueOpCode := RightExpression.LocationData.JumpIfTrueOpCode; end;

https://googleads.g.doubleclick.net/pagead/ads?gdpr=0&us_privacy=1—&client=ca-pub-3118622027477755&output=html&h=250&slotname=9081759943&adk=2759084617&adf=2214989710&pi=t.ma~as.9081759943&w=300&abgtt=9&lmt=1750985735&rafmt=12&format=300×250&url=https%3A%2F%2Fturbopascal.org%2Fboolean-operations&wgl=1&dt=1750985735077&bpp=4&bdt=1879&idt=195&shv=r20250625&mjsv=m202506240101&ptt=9&saldr=aa&abxe=1&cookie_enabled=1&eoidce=1&correlator=1625616222564&frm=20&pv=2&u_tz=-240&u_his=2&u_h=1119&u_w=522&u_ah=1119&u_aw=522&u_cd=24&u_sd=2.069&adx=49&ady=1545&biw=522&bih=955&scr_x=0&scr_y=0&eid=31092194%2C95353387%2C95362656%2C95363434%2C95364338%2C31093163%2C95344790%2C95359266%2C95364333%2C95364390&oid=2&pvsid=2030271569598182&tmod=1449119527&uas=0&nvt=1&ref=https%3A%2F%2Fduckduckgo.com%2F&fc=896&brdim=0%2C32%2C0%2C32%2C522%2C0%2C514%2C1011%2C522%2C955&vis=1&rsz=%7C%7CeEbr%7C&abl=CS&pfx=0&fu=256&bc=31&bz=0.98&pgls=CAEaBTYuOC4x&ifi=1&uci=a!1&btvi=1&fsb=1&dtd=216

https://googleads.g.doubleclick.net/pagead/ads?gdpr=0&us_privacy=1—&client=ca-pub-3118622027477755&output=html&h=280&slotname=9081759943&adk=1091952667&adf=3051215641&pi=t.ma~as.9081759943&w=423&abgtt=9&fwrn=4&fwrnh=100&lmt=1750985735&rafmt=1&format=423×280&url=https%3A%2F%2Fturbopascal.org%2Fboolean-operations&fwr=0&fwrattr=true&rpe=1&resp_fmts=3&wgl=1&dt=1750985735081&bpp=2&bdt=1883&idt=237&shv=r20250625&mjsv=m202506240101&ptt=9&saldr=aa&abxe=1&cookie_enabled=1&eoidce=1&prev_fmts=300×250&correlator=1625616222564&frm=20&pv=1&u_tz=-240&u_his=2&u_h=1119&u_w=522&u_ah=1119&u_aw=522&u_cd=24&u_sd=2.069&adx=49&ady=2848&biw=522&bih=955&scr_x=0&scr_y=0&eid=31092194%2C95353387%2C95362656%2C95363434%2C95364338%2C31093163%2C95344790%2C95359266%2C95364333%2C95364390&oid=2&pvsid=2030271569598182&tmod=1449119527&uas=0&nvt=1&ref=https%3A%2F%2Fduckduckgo.com%2F&fc=896&brdim=0%2C32%2C0%2C32%2C522%2C0%2C514%2C1011%2C522%2C955&vis=1&rsz=%7C%7CEebr%7C&abl=CS&pfx=0&fu=128&bc=31&bz=0.98&pgls=CAEaBTYuOC4x&ifi=2&uci=a!2&btvi=2&fsb=1&dtd=242

assembler block code const declarations entry exit expressions file function identifiers instructions integer intermediate code label mathematical operations new offset omf pointer procedure program read source statements string symbol table symbol tables type unit

https://www.google.com/recaptcha/api2/anchor?ar=1&k=6LfmAm0kAAAAABwLmsvVUEA1EOe-6eUkMRIfPM4q&co=aHR0cHM6Ly90dXJib3Bhc2NhbC5vcmc6NDQz&hl=en&v=h7qt2xUGz2zqKEhSc8DD8baZ&size=invisible&cb=1idf53crbyce

Leave a comment

Design a site like this with WordPress.com
Get started