Sha256: 9e89823c1d015215960e4b90fa9af38e80b7d32d933b5fc433059edc8f3a454c

Contents?: true

Size: 709 Bytes

Versions: 2

Compression:

Stored size: 709 Bytes

Contents

module Haxor
  module Vm
    class Stack < Subsystem
      def push(addr)
        value = @vm.subsystem(:mem).read addr
        push_value value
      end

      def push_value(value)
        sp = @vm.subsystem(:registers).read 'sp'
        sp -= Consts::WORD_SIZE
        @vm.subsystem(:registers).write 'sp', sp
        @vm.subsystem(:mem).write sp, value
      end

      def pop(addr)
        value = pop_value
        @vm.subsystem(:mem).write addr, value
      end

      def pop_value
        sp = @vm.subsystem(:registers).read 'sp'
        value = @vm.subsystem(:mem).read sp
        sp += Consts::WORD_SIZE
        @vm.subsystem(:registers).write 'sp', sp

        value
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
haxor-0.3.0 lib/haxor/vm/stack.rb
haxor-0.2.0 lib/haxor/vm/stack.rb