История изменений
Исправление cvs-255, (текущая версия) :
простейший менеджер аллокации памяти на асме, не помню точно, сколько у меня на него тогда времени ушло, давно писал, но немного, минут 20 наверно
.data
hex: .string "0123456789ABCDEF"
pref: .string "0x"
suff: .string "\n"
dig: .byte 0
heaplen: .quad 0
heap:
.text
.globl _start
.type _start, @function
.globl main
.type main, @function
alloc_heap:
movq %rdi, %r8
# 16 bytes for length and flags
# bytes 0...7 = length of block
# bytes 8...15 = 1 if block is active
add $16, %rdi
movq $12, %rax
# %rdi contains number of bytes to alloc
syscall
movq $heap, %rbx
movq heaplen, %rax
add %rax, %rbx
# begin of allocated block
movq %rbx, %r10
# save length of requested block
movq %r8, (%rbx)
# mark block as active
add $8, %rbx
movq $1, %r9
movq %r9, (%rbx)
# mov begining of allocated block to %rax
movq %r10, %rax
add $16, %rax
# update heaplen
movq heaplen, %rbx
add %rdi, %rbx
movq %rbx, heaplen
ret
Исправление cvs-255, :
простейший менеджер памяти на асме, не помню точно, сколько у меня на него тогда времени ушло, давно писал, но немного, минут 20 наверно
.data
hex: .string "0123456789ABCDEF"
pref: .string "0x"
suff: .string "\n"
dig: .byte 0
heaplen: .quad 0
heap:
.text
.globl _start
.type _start, @function
.globl main
.type main, @function
alloc_heap:
movq %rdi, %r8
# 16 bytes for length and flags
# bytes 0...7 = length of block
# bytes 8...15 = 1 if block is active
add $16, %rdi
movq $12, %rax
# %rdi contains number of bytes to alloc
syscall
movq $heap, %rbx
movq heaplen, %rax
add %rax, %rbx
# begin of allocated block
movq %rbx, %r10
# save length of requested block
movq %r8, (%rbx)
# mark block as active
add $8, %rbx
movq $1, %r9
movq %r9, (%rbx)
# mov begining of allocated block to %rax
movq %r10, %rax
add $16, %rax
# update heaplen
movq heaplen, %rbx
add %rdi, %rbx
movq %rbx, heaplen
ret
Исходная версия cvs-255, :
простейший менеджер памяти на асме, не помню точно, сколько у меня на него тогда времени ушло, давно писал, но немного
.data
hex: .string "0123456789ABCDEF"
pref: .string "0x"
suff: .string "\n"
dig: .byte 0
heaplen: .quad 0
heap:
.text
.globl _start
.type _start, @function
.globl main
.type main, @function
alloc_heap:
movq %rdi, %r8
# 16 bytes for length and flags
# bytes 0...7 = length of block
# bytes 8...15 = 1 if block is active
add $16, %rdi
movq $12, %rax
# %rdi contains number of bytes to alloc
syscall
movq $heap, %rbx
movq heaplen, %rax
add %rax, %rbx
# begin of allocated block
movq %rbx, %r10
# save length of requested block
movq %r8, (%rbx)
# mark block as active
add $8, %rbx
movq $1, %r9
movq %r9, (%rbx)
# mov begining of allocated block to %rax
movq %r10, %rax
add $16, %rax
# update heaplen
movq heaplen, %rbx
add %rdi, %rbx
movq %rbx, heaplen
ret