Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

nightshiftco/LessCursedVM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

2 Commits

Repository files navigation

LessCursedVM

The code that accompanies the LessCursedVM blog post.

import signal
import sys
import threading
from cursed_vm import Asm, CursedVm
def main():
 # Build the guest program
 asm = Asm()
 asm.push_string("Hello, World!\n")
 asm.mov_rsi_rsp()
 asm.print_loop(port=0x10)
 # Handle Ctrl+C
 stop = threading.Event()
 signal.signal(signal.SIGINT, lambda *_: stop.set())
 # Run the VM on a background thread
 def vm_thread():
 with CursedVm() as vm:
 vm.load(asm.code())
 vm.run(lambda port, data: (
 sys.stdout.write(chr(data[0])) or sys.stdout.flush()
 if port == 0x10 and len(data) == 1
 else None
 ))
 t = threading.Thread(target=vm_thread, daemon=True)
 t.start()
 stop.wait()
 print("\nBye.")
if __name__ == "__main__":
 main()

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors

Languages

AltStyle によって変換されたページ (->オリジナル) /