minor
This commit is contained in:
parent
f34fddd383
commit
0fa47d204e
@ -80,12 +80,11 @@ module Core
|
|||||||
# not my hand off course, found in the net from a basic introduction
|
# not my hand off course, found in the net from a basic introduction
|
||||||
def fibo context
|
def fibo context
|
||||||
fibo_function = Vm::Function.new(:fibo , [Vm::Integer , Vm::Integer] , Vm::Integer )
|
fibo_function = Vm::Function.new(:fibo , [Vm::Integer , Vm::Integer] , Vm::Integer )
|
||||||
result = fibo_function.args[0]
|
result , int = fibo_function.args
|
||||||
int =fibo_function.args[1]
|
|
||||||
i = Vm::Integer.new(2)
|
i = Vm::Integer.new(2)
|
||||||
|
loop_block = Vm::Block.new("loop")
|
||||||
f1 = Vm::Integer.new(3)
|
f1 = Vm::Integer.new(3)
|
||||||
f2 = Vm::Integer.new(4)
|
f2 = Vm::Integer.new(4)
|
||||||
loop_block = Vm::Block.new("loop")
|
|
||||||
fibo_function.body.instance_eval do
|
fibo_function.body.instance_eval do
|
||||||
cmp( int , 1)
|
cmp( int , 1)
|
||||||
mov( result, int , condition_code: :le)
|
mov( result, int , condition_code: :le)
|
||||||
@ -96,6 +95,7 @@ module Core
|
|||||||
sub( i , int , 2)
|
sub( i , int , 2)
|
||||||
add_code loop_block
|
add_code loop_block
|
||||||
end
|
end
|
||||||
|
|
||||||
loop_block.instance_eval do
|
loop_block.instance_eval do
|
||||||
add( f1 , f1 , f2)
|
add( f1 , f1 , f2)
|
||||||
sub( f2 , f1 , f2)
|
sub( f2 , f1 , f2)
|
||||||
|
@ -29,12 +29,11 @@ module Elf
|
|||||||
end
|
end
|
||||||
set_text binary.string
|
set_text binary.string
|
||||||
end
|
end
|
||||||
|
attr_reader :text
|
||||||
def set_text(text)
|
def set_text(text)
|
||||||
@text.text = text
|
@text.text = text
|
||||||
add_symbol "_start", 0
|
add_symbol "_start", 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_symbol(name, offset, linkage = Elf::Constants::STB_GLOBAL)
|
def add_symbol(name, offset, linkage = Elf::Constants::STB_GLOBAL)
|
||||||
@symbol_table.add_func_symbol name, offset, @text, linkage
|
@symbol_table.add_func_symbol name, offset, @text, linkage
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user