Metasm is a Ruby library for assembling, disassembling and understanding the code semantics.
Code was adapted from the Practical Reverse Engineering book and tested with Metasm 1.04 on Ruby 3.0.1.
code_bind.rb
shows how to disassemble and extract the semantics of a given code
block and sym_exec.rb
shows how to execute that same code block by providing
a context with arbitrary values.
Chapter 5 of the Practical Reverse Engineering book with its accompanying Metasm code exercises (and solutions!) provide the best explanation of how to disassemble and then perform symbolic execution on the disassembled blocks. Exercise 2 is especially instructive.