MASM/If else statement
Jump to navigation
Jump to search
globals.masm
nine ptr-size old-ipt arg arg1 arg2 ret
if-else.masm
tmp not-four offset arg-as-bool-times-eight lab if-else alc one get arg nnd vpt set tmp cmt tmp = arg except it's 0x00 if zero and 0xff otherwise alc one get tmp rot one nnd tmp fre tmp nnd vpt set tmp alc one get tmp rot one nnd tmp fre tmp nnd vpt set tmp alc one get tmp rot one nnd tmp fre tmp nnd vpt set tmp alc one get tmp rot one nnd tmp fre tmp nnd vpt set tmp alc one get tmp rot one nnd tmp fre tmp nnd vpt set tmp alc one get tmp rot one nnd tmp fre tmp nnd vpt set tmp alc one get tmp rot one nnd tmp fre tmp set tmp cmt tmp (which is 0x00 or 0xff) is converted to 0x00 (arg = 0) cmt or 0x08 (arg = nonzero) to potentially skip commands alc one get tmp fre tmp nnd one nnd vpt rot one rot one rot one rot one rot one set arg-as-bool-times-eight cmt not-four = 4 nand 4 alc one get one rot one rot one rot one rot one rot one rot one nnd vpt set not-four cmt combines arg-as-bool-times-eight and not-four to create cmt either 4 or 12 alc one get arg-as-bool-times-eight fre arg-as-bool-times-eight nnd vpt nnd not-four set offset cmt adds offset (which is either 4 or 12) to ipt cmt to call either function A (if it's 4) or B cmt (if it's 12) alc ptr-size set tmp adr ipt get offset drf vpt fre tmp set ipt cmt call arg2. this will be skipped if arg cmt equals 0, in which case offset equals 4. cmt not how old-ipt isn't changed, so the label cmt arg2 is pointing to will move ipt back to cmt where it was before calling this if/else cmt statement alc ptr-size set tmp adr arg2 drf vpt fre tmp set ipt cmt to noops (could be anything; won't be executed cmt anyways) so ipt doesn't jump to the wrong place cmt when offset is added set vpt set vpt cmt call arg1 if offset doesn't equal 0, in cmt which case offset equals 12 alc ptr-size set tmp adr arg1 drf vpt fre tmp set ipt
main.masm
if-else print-A print-B loop tmp lab loop alc ptr-size set tmp adr loop drf vpt set ipt lab main cmt contruct nine (aka ptr-size) alc one get one rot one rot one rot one rot one rot one nnd vpt set tmp alc one get one nnd vpt nnd tmp fre tmp set nine cmt set arg to 0 (replace out with any nonzero cmt value like one to get a different result) alc one get out set arg cmt arg1 = print-A alc ptr-size set tmp adr print-A drf vpt fre tmp set arg1 cmt arg2 = print-B alc ptr-size set tmp adr print-B drf vpt fre tmp set arg2 cmt init old-ipt alc ptr-size set tmp adr ipt drf vpt fre tmp set old-ipt cmt call if-else. will print A if arg is cmt nonzero, otherwise B alc ptr-size set tmp adr if-else drf vpt fre tmp set ipt cmt goto loop alc ptr-size set tmp adr loop drf vpt set ipt
printing.masm
tmp new-out two _65 _66 lab print-A alc one get one rot one rot one nnd vpt set tmp alc one get one nnd vpt nnd tmp fre tmp set _65 alc one get one rot one rot one rot one rot one rot one rot one rot one set two alc two set new-out get _65 alc ptr-size set tmp adr new-out get one drf vpt fre tmp get out alc ptr-size set tmp adr new-out drf vpt fre tmp set out alc ptr-size set tmp adr old-ipt get nine drf vpt fre tmp set ipt lab print-B alc one get one rot one rot one nnd vpt set tmp alc one get one rot one rot one rot one rot one rot one rot one rot one nnd vpt nnd tmp fre tmp set _66 alc one get one rot one rot one rot one rot one rot one rot one rot one set two alc two set new-out get _66 alc ptr-size set tmp adr new-out get one drf vpt fre tmp get out alc ptr-size set tmp adr new-out drf vpt fre tmp set out alc ptr-size set tmp adr old-ipt get nine drf vpt fre tmp set ipt