kammt/MemeAssembly

[Bug] Broken writechar output command

Closed this issue · 0 comments

Describe the bug
When using the what can I say except T command, the output sometimes just doesn't show up.

This is because for some reason the writechar function no longer sets rdi to 1/stdout; so it just uses whatever value was in rdi before.

It can also be seen when running the example below with strace:

execve("./main", ["./main"], 0x7fffe5d793a0 /* 28 vars */) = 0
[... irrelevant stuff...]
write(5, "T", 1)                        = -1 EBADF (Bad file descriptor)
write(5, "e", 1)                        = -1 EBADF (Bad file descriptor)
write(5, "s", 1)                        = -1 EBADF (Bad file descriptor)
write(5, "t", 1)                        = -1 EBADF (Bad file descriptor)
exit_group(0)                           = ?
+++ exited with 0 +++

To Reproduce

Code example or used MemeASM code
I like to have fun, fun, fun, fun, fun, fun, fun, fun, fun, fun main
    rdi is brilliant, but I like 5
    
    what can I say except T
    what can I say except e
    what can I say except s
    what can I say except t
    
    I see this as an absolute win

Used compiler flags[e.g. -O-1 -c]: none, memeasm -o './main' 'min.memeasm' && strace ./main

Debug Output (not really relevant)

Opening file "min.memeasm" successful, parsing file...
The number of lines are 7
Struct array was created successfully
Parsing line: I like to have fun, fun, fun, fun, fun, fun, fun, fun, fun, fun main
        comparing with I
        comparing with like
        comparing with to
        comparing with have
        comparing with fun,
        comparing with fun,
        comparing with fun,
        comparing with fun,
        comparing with fun,
        comparing with fun,
        comparing with fun,
        comparing with fun,
        comparing with fun,
        comparing with fun
        comparing with {p}
                main contains a parameter
Parsing line:     rdi is brilliant, but I like 1
        comparing with I
                Matching failed, attempting to match next command
        comparing with right
                Matching failed, attempting to match next command
        comparing with no,
                Matching failed, attempting to match next command
        comparing with I
                Matching failed, attempting to match next command
        comparing with {p}:
                Matching failed - chars before or after {p} mismatching, attempting to match next command
        comparing with stonks
                Matching failed, attempting to match next command
        comparing with not
                Matching failed, attempting to match next command
        comparing with bitconneeeeeeect
                Matching failed, attempting to match next command
        comparing with {p}
                rdi contains a parameter
        comparing with \s
                Matching failed, attempting to match next command
        comparing with sneak
                Matching failed, attempting to match next command
        comparing with {p}
                rdi contains a parameter
        comparing with is
        comparing with brilliant,
        comparing with but
        comparing with I
        comparing with like
        comparing with {p}
                1 contains a parameter
Parsing line:     what can I say except T
        comparing with I
                Matching failed, attempting to match next command
        comparing with right
                Matching failed, attempting to match next command
        comparing with no,
                Matching failed, attempting to match next command
        comparing with I
                Matching failed, attempting to match next command
        comparing with {p}:
                Matching failed - chars before or after {p} mismatching, attempting to match next command
        comparing with stonks
                Matching failed, attempting to match next command
        comparing with not
                Matching failed, attempting to match next command
        comparing with bitconneeeeeeect
                Matching failed, attempting to match next command
        comparing with {p}
                what contains a parameter
        comparing with \s
                Matching failed, attempting to match next command
        comparing with sneak
                Matching failed, attempting to match next command
        comparing with {p}
                what contains a parameter
        comparing with is
                Matching failed, attempting to match next command
        comparing with upvote
                Matching failed, attempting to match next command
        comparing with downvote
                Matching failed, attempting to match next command
        comparing with parry
                Matching failed, attempting to match next command
        comparing with {p}
                what contains a parameter
        comparing with units
                Matching failed, attempting to match next command
        comparing with upgrades,
                Matching failed, attempting to match next command
        comparing with they
                Matching failed, attempting to match next command
        comparing with {p}
                what contains a parameter
        comparing with is
                Matching failed, attempting to match next command
        comparing with look
                Matching failed, attempting to match next command
        comparing with {p}
                what contains a parameter
        comparing with UNLIMITED
                Matching failed, attempting to match next command
        comparing with upgrade
                Matching failed, attempting to match next command
        comparing with fuck
                Matching failed, attempting to match next command
        comparing with banana
                Matching failed, attempting to match next command
        comparing with where
                Matching failed, attempting to match next command
        comparing with monke
                Matching failed, attempting to match next command
        comparing with return
                Matching failed, attempting to match next command
        comparing with who
                Matching failed, attempting to match next command
        comparing with {p}
                what contains a parameter
        comparing with wins
                Matching failed, attempting to match next command
        comparing with corporate
                Matching failed, attempting to match next command
        comparing with they're
                Matching failed, attempting to match next command
        comparing with what
        comparing with can
        comparing with I
        comparing with say
        comparing with except
        comparing with {p}
                T contains a parameter
Parsing line:     what can I say except e
        comparing with I
                Matching failed, attempting to match next command
        comparing with right
                Matching failed, attempting to match next command
        comparing with no,
                Matching failed, attempting to match next command
        comparing with I
                Matching failed, attempting to match next command
        comparing with {p}:
                Matching failed - chars before or after {p} mismatching, attempting to match next command
        comparing with stonks
                Matching failed, attempting to match next command
        comparing with not
                Matching failed, attempting to match next command
        comparing with bitconneeeeeeect
                Matching failed, attempting to match next command
        comparing with {p}
                what contains a parameter
        comparing with \s
                Matching failed, attempting to match next command
        comparing with sneak
                Matching failed, attempting to match next command
        comparing with {p}
                what contains a parameter
        comparing with is
                Matching failed, attempting to match next command
        comparing with upvote
                Matching failed, attempting to match next command
        comparing with downvote
                Matching failed, attempting to match next command
        comparing with parry
                Matching failed, attempting to match next command
        comparing with {p}
                what contains a parameter
        comparing with units
                Matching failed, attempting to match next command
        comparing with upgrades,
                Matching failed, attempting to match next command
        comparing with they
                Matching failed, attempting to match next command
        comparing with {p}
                what contains a parameter
        comparing with is
                Matching failed, attempting to match next command
        comparing with look
                Matching failed, attempting to match next command
        comparing with {p}
                what contains a parameter
        comparing with UNLIMITED
                Matching failed, attempting to match next command
        comparing with upgrade
                Matching failed, attempting to match next command
        comparing with fuck
                Matching failed, attempting to match next command
        comparing with banana
                Matching failed, attempting to match next command
        comparing with where
                Matching failed, attempting to match next command
        comparing with monke
                Matching failed, attempting to match next command
        comparing with return
                Matching failed, attempting to match next command
        comparing with who
                Matching failed, attempting to match next command
        comparing with {p}
                what contains a parameter
        comparing with wins
                Matching failed, attempting to match next command
        comparing with corporate
                Matching failed, attempting to match next command
        comparing with they're
                Matching failed, attempting to match next command
        comparing with what
        comparing with can
        comparing with I
        comparing with say
        comparing with except
        comparing with {p}
                e contains a parameter
Parsing line:     what can I say except s
        comparing with I
                Matching failed, attempting to match next command
        comparing with right
                Matching failed, attempting to match next command
        comparing with no,
                Matching failed, attempting to match next command
        comparing with I
                Matching failed, attempting to match next command
        comparing with {p}:
                Matching failed - chars before or after {p} mismatching, attempting to match next command
        comparing with stonks
                Matching failed, attempting to match next command
        comparing with not
                Matching failed, attempting to match next command
        comparing with bitconneeeeeeect
                Matching failed, attempting to match next command
        comparing with {p}
                what contains a parameter
        comparing with \s
                Matching failed, attempting to match next command
        comparing with sneak
                Matching failed, attempting to match next command
        comparing with {p}
                what contains a parameter
        comparing with is
                Matching failed, attempting to match next command
        comparing with upvote
                Matching failed, attempting to match next command
        comparing with downvote
                Matching failed, attempting to match next command
        comparing with parry
                Matching failed, attempting to match next command
        comparing with {p}
                what contains a parameter
        comparing with units
                Matching failed, attempting to match next command
        comparing with upgrades,
                Matching failed, attempting to match next command
        comparing with they
                Matching failed, attempting to match next command
        comparing with {p}
                what contains a parameter
        comparing with is
                Matching failed, attempting to match next command
        comparing with look
                Matching failed, attempting to match next command
        comparing with {p}
                what contains a parameter
        comparing with UNLIMITED
                Matching failed, attempting to match next command
        comparing with upgrade
                Matching failed, attempting to match next command
        comparing with fuck
                Matching failed, attempting to match next command
        comparing with banana
                Matching failed, attempting to match next command
        comparing with where
                Matching failed, attempting to match next command
        comparing with monke
                Matching failed, attempting to match next command
        comparing with return
                Matching failed, attempting to match next command
        comparing with who
                Matching failed, attempting to match next command
        comparing with {p}
                what contains a parameter
        comparing with wins
                Matching failed, attempting to match next command
        comparing with corporate
                Matching failed, attempting to match next command
        comparing with they're
                Matching failed, attempting to match next command
        comparing with what
        comparing with can
        comparing with I
        comparing with say
        comparing with except
        comparing with {p}
                s contains a parameter
Parsing line:     what can I say except t
        comparing with I
                Matching failed, attempting to match next command
        comparing with right
                Matching failed, attempting to match next command
        comparing with no,
                Matching failed, attempting to match next command
        comparing with I
                Matching failed, attempting to match next command
        comparing with {p}:
                Matching failed - chars before or after {p} mismatching, attempting to match next command
        comparing with stonks
                Matching failed, attempting to match next command
        comparing with not
                Matching failed, attempting to match next command
        comparing with bitconneeeeeeect
                Matching failed, attempting to match next command
        comparing with {p}
                what contains a parameter
        comparing with \s
                Matching failed, attempting to match next command
        comparing with sneak
                Matching failed, attempting to match next command
        comparing with {p}
                what contains a parameter
        comparing with is
                Matching failed, attempting to match next command
        comparing with upvote
                Matching failed, attempting to match next command
        comparing with downvote
                Matching failed, attempting to match next command
        comparing with parry
                Matching failed, attempting to match next command
        comparing with {p}
                what contains a parameter
        comparing with units
                Matching failed, attempting to match next command
        comparing with upgrades,
                Matching failed, attempting to match next command
        comparing with they
                Matching failed, attempting to match next command
        comparing with {p}
                what contains a parameter
        comparing with is
                Matching failed, attempting to match next command
        comparing with look
                Matching failed, attempting to match next command
        comparing with {p}
                what contains a parameter
        comparing with UNLIMITED
                Matching failed, attempting to match next command
        comparing with upgrade
                Matching failed, attempting to match next command
        comparing with fuck
                Matching failed, attempting to match next command
        comparing with banana
                Matching failed, attempting to match next command
        comparing with where
                Matching failed, attempting to match next command
        comparing with monke
                Matching failed, attempting to match next command
        comparing with return
                Matching failed, attempting to match next command
        comparing with who
                Matching failed, attempting to match next command
        comparing with {p}
                what contains a parameter
        comparing with wins
                Matching failed, attempting to match next command
        comparing with corporate
                Matching failed, attempting to match next command
        comparing with they're
                Matching failed, attempting to match next command
        comparing with what
        comparing with can
        comparing with I
        comparing with say
        comparing with except
        comparing with {p}
                t contains a parameter
Parsing line:     I see this as an absolute win
        comparing with I
        comparing with like
                Matching failed, attempting to match next command
        comparing with right
                Matching failed, attempting to match next command
        comparing with no,
                Matching failed, attempting to match next command
        comparing with I
        comparing with see
        comparing with this
        comparing with as
        comparing with an
        comparing with absolute
        comparing with win
Number of functions: 1
        Parsing function:
                Iteration stopped at index 7
File parsing done, closing file...
Starting parameter validity check
        Checking parameter main
                Parameter is a valid function name
Starting parameter validity check
        Checking parameter rdi
                Parameter is a 64 bit register
        Checking parameter 1
                Parameter is not a 64 bit register
                Parameter is not a 32 bit register
                Parameter is not a 16 bit register
                Parameter is not an 8 bit register
                Parameter is a decimal number
Starting parameter validity check
        Checking parameter T
                Parameter is not an 8 bit register
                Parameter is a character, translated to: 'T'
Starting parameter validity check
        Checking parameter e
                Parameter is not an 8 bit register
                Parameter is a character, translated to: 'e'
Starting parameter validity check
        Checking parameter s
                Parameter is not an 8 bit register
                Parameter is a character, translated to: 's'
Starting parameter validity check
        Checking parameter t
                Parameter is not an 8 bit register
                Parameter is a character, translated to: 't'
Starting parameter validity check
        Label duplicity check for function in line 1 in file 0
Starting jump label validity check for opcode 20
Starting jump label validity check for opcode 22
Beginning Monke jump label validity check
Starting analysis for "who would win?" command
Starting analysis for "corporate needs you to find the difference..." command
Chose random line for jump marker: 4
Starting analysis of the "Perfectly balanced..." command
        amount of times perfectly balanced was used: 0
        amount of lines to be deleted: 0
Analysis done, freeing memory

System Info (please complete the following information):

  • Linux Distribution: WSL/Ubuntu
  • GCC Version: 9.4.0
  • MemeASM Compiler Version: v1.5 (also reproduces on the latest develop branch)
  • Installation method: Makefile

TL;DR: pls mov rdi, 1