Skip to content
Snippets Groups Projects
Commit f921af27 authored by PEDRO MARTINS E SA's avatar PEDRO MARTINS E SA
Browse files

inicial

parent 71004a2f
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -9,10 +9,10 @@ void aloca_espaco(int tam_alloc);
void* alocaMem(int tam_alloc);
//void arruma_heap();
void arruma_heap();
//void liberaMem(void* bloco);
void liberaMem(void* bloco);
void print_mapa();
#endif
#endif
\ No newline at end of file
No preview for this file type
......@@ -70,12 +70,10 @@ void* alocaMem(int tam_alloc)
}
else
{
if (endr == teto_heap)
{
aloca_espaco(tam_alloc);
(endr) = 0;
8(endr) = tam_alloc;
}
endr = teto_heap;
aloca_espaco(tam_alloc);
(endr) = 0;
8(endr) = tam_alloc;
}
break;
}
......@@ -86,23 +84,15 @@ void* alocaMem(int tam_alloc)
return (endr + 16);
}
cmpq $LIVRE, %rbx
jne fim_if_aloca_mem
void arruma_heap()
{
if (piso_heap == 1)
return;
void *endr_ant, endr;
endr_ant = piso_heap;
endr = piso_heap + 8(endr_ant) + 16;
while (endr < teto_heap)
{
if ((endr == 1) && (endr_ant == 1))
if ((endr == 1) && ((endr_ant) == 1))
8(endr_ant) += 8(endr) + 16;
else
endr_ant = endr;
......
......@@ -8,8 +8,9 @@
str5: .string "INICIANDO O ALOCADOR\n"
pula_Linha: .string "\n"
flag: .string "%d\n" #############APAGARRRRRRRR##########
oi: .string "oi\n" #############APAGARRRRRRRR##########
flag: .string "%d"
flaag: .string "%d, %d \n" #############APAGARRRRRRRR##########
oi: .string "oi\n" #############APAGARRRRRRRR##########
.section .bss
.equ ALOCADOR, 1040
......@@ -75,7 +76,13 @@ finalizaAlocador:
aloca_espaco:
pushq %rbp
movq %rsp, %rbp
#traducao nao feita
movq %rdi, %rax
addq $16, %rax
addq %rax, teto_heap
movq teto_heap, %rdi
movq $12, %rax
syscall
popq %rbp
ret
......@@ -86,11 +93,6 @@ alocaMem:
subq $8, %rsp #aloca espaco para endr
movq %rdi, %r12 #r12 = ponteiro alocado
#movq $flag, %rdi
#movq %r12, %rsi
#call printf
movq piso_heap, %rbx
cmpq $0, %rbx
jne fim_if_aloca_mem
......@@ -108,22 +110,22 @@ alocaMem:
jl else_if_aloca_mem2
addq $16, %r12 #8(endr) -= tam_alloc + 16
subq %r12, 8(%rbx)
addq $16, 8(%rbx) #endr += 8(endr) + 16
addq 8(%rbx), %rbx
movq 8(%rbx), %r13
subq $16, %r12
addq $16, %r13 #endr += 8(endr) + 16
addq %r13, %rbx
movq $OCUPADO, (%rbx)
movq %r12, 8(%rbx)
movq %r12, 8(%rbx)
jmp fim_if_aloca_mem2
else_if_aloca_mem2:
cmpq teto_heap, %rbx
jne fim_if_aloca_mem2
pushq %r12
call aloca_espaco
movq $OCUPADO,(%rbx)
movq %r12, 8(%rbx)
jmp fim_if_aloca_mem2
movq teto_heap,%rbx
movq %r12, %r15
pushq %r12
call aloca_espaco
popq %r12
movq $OCUPADO,(%rbx)
movq %r15, 8(%rbx)
jmp fim_if_aloca_mem2
fim_if_aloca_mem2:
jmp fim_while_aloca_mem
......@@ -144,14 +146,59 @@ alocaMem:
arruma_heap:
pushq %rbp
movq %rsp, %rbp
#traducao nao feita
subq $16, %rsp
movq piso_heap, %r10
movq %r10, -8(%rbp) #endr_ant = piso_heap
movq -8(%rbp), %rax
movq piso_heap, %rbx
addq $16, %rbx
addq 8(%rax), %rbx
movq %rbx, -16(%rbp) #endr = piso_heap + tam_piso + 16
while_arruma_heap:
cmpq teto_heap, %rbx
jge fim_while_arruma_heap
cmpq $1, (%rbx)
jne else_if_arruma_heap
cmpq $1, (%rax)
jne else_if_arruma_heap
movq 8(%rbx), %r10
addq %r10, 8(%rax)
addq $16, 8(%rax)
jmp fim_if_arruma_heap
else_if_arruma_heap:
movq %rbx, %rax
jmp fim_if_arruma_heap
fim_if_arruma_heap:
movq 8(%rbx), %r13
addq $16, %r13
addq %r13, %rbx
jmp while_arruma_heap
fim_while_arruma_heap:
#movq $flaag, %rdi
#movq (%rax), %rsi
#movq (%rbx), %rdx
#call printf
addq $16, %rsp
popq %rbp
ret
#---------------------------------------------------------------------#
liberaMem:
pushq %rbp
movq %rsp, %rbp
#traducao nao feita
movq %rdi, %rbx
movq $LIVRE, -16(%rbx)
call arruma_heap
popq %rbp
ret
#---------------------------------------------------------------------#
......@@ -184,9 +231,10 @@ print_mapa:
addq $1, %r12
jmp for_cabecalho
fim_for_cabecalho:
#movq flag,%rdi
#movq 8(%rbx),%rsi
#call printf
movq $flag,%rdi
movq 8(%rbx),%rsi
call printf
cmpq $LIVRE, (%rbx)
jne else_if_while
......@@ -216,8 +264,10 @@ print_mapa:
jmp fim_if_while
fim_if_while:
addq $16, 8(%rbx)
addq 8(%rbx), %rbx
movq 8(%rbx), %r13
addq $16, %r13
addq %r13, %rbx
jmp while_loop
fim_while_loop:
......
#include <meu_malloc.h>
#include <stdio.h>
int main()
{
void* x;
void *w, *x, *y, *z;
iniciaAlocador();
x = alocaMem(1024);
print_mapa();
finalizaAlocador();
printf("\n");
w = alocaMem(100);
print_mapa();
printf("\n");
x = alocaMem(200);
print_mapa();
printf("\n");
y = alocaMem(300);
print_mapa();
printf("\n");
z = alocaMem(400);
print_mapa();
printf("\n");
liberaMem(x);
print_mapa();
x = alocaMem(50);
print_mapa();
printf("\n");
printf("\n");
liberaMem(y);
print_mapa();
printf("\n");
liberaMem(w);
print_mapa();
printf("\n");
liberaMem(x);
print_mapa();
printf("\n");
liberaMem(z);
print_mapa();
printf("\n");
return (0);
}
teste 0 → 100755
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment