Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. #include "endereco.hpp"
  4. #include "instrucao.hpp"
  5. #include "blocoMemoria.hpp"
  6. #include "mmu.hpp"
  7. #include "maquina.hpp"
  8.  
  9. using namespace std;
  10.  
  11. int main(int argc, char const *argv[]){
  12. int tamanhoRam= 1000;
  13. int tamanhoCache1 = 8;
  14. int tamanhoCache2 = 16;
  15. int tamanhoPrograma = 49984;
  16. int qdePalavrasBloco = 4;
  17.  
  18. Instrucao *memoriaInstrucoes = gerarInst(tamanhoPrograma);
  19.  
  20. for(int i=0; i<tamanhoPrograma; i++){
  21. gerarEndInst(posToPointInst(memoriaInstrucoes, i));
  22. }
  23.  
  24. BlocoMemoria *ram = gerarBM(tamanhoRam);
  25. BlocoMemoria *cache1 = gerarBM(tamanhoCache1);
  26. BlocoMemoria *cache2 = gerarBM(tamanhoCache2);
  27.  
  28. montarRam(ram, tamanhoRam, qdePalavrasBloco);
  29. montarCacheVazia(tamanhoCache1, cache1);
  30. montarCacheVazia(tamanhoCache2, cache2);
  31. //montarInstrucaoDoTxT();
  32. carregarInstrucoesTXT(memoriaInstrucoes);
  33.  
  34. // for(int i=0; i<tamanhoPrograma; i++){
  35. // cout<<"Opcode: |"<<getOpcodev(memoriaInstrucoes, i)<<"| b1: |"<<getEndBloco(getAdd1(memoriaInstrucoes, i))<<"| ep1: |"<<getEndPalavra(getAdd1(memoriaInstrucoes, i))<<"| b2: |"<<getEndBloco(getAdd2(memoriaInstrucoes, i))<<"| ep2: |"<<getEndPalavra(getAdd2(memoriaInstrucoes, i))<<"| b3: |"<<getEndBloco(getAdd3(memoriaInstrucoes, i))<<"| ep3: |"<<getEndPalavra(getAdd3(memoriaInstrucoes, i))<<"|"<<endl<<endl;
  36. // }
  37.  
  38. //montarInstrucoesProgramaAleatorio(memoriaInstrucoes, tamanhoPrograma, qdePalavrasBloco, tamanhoRam);
  39. //montarInstrucoesProgramaMultiplicacao(512, 1024);
  40. maquina(&memoriaInstrucoes, &ram, &cache1, &cache2);
  41. deleteBM(cache2);
  42. deleteBM(cache1);
  43. deleteBM(ram);
  44. deleteInst(memoriaInstrucoes);
  45. cout<<"terminoun";
  46. cout<<"----------------------------------------------------"<<endl;
  47. return 0;
  48. }
  49.  
  50. #include "instrucao.hpp"
  51. using namespace std;
  52. struct instrucao {
  53. Endereco *add1;
  54. Endereco *add2;
  55. Endereco *add3;
  56. int opcode;
  57. };
  58.  
  59. Instrucao * gerarInst(int q){
  60. return new Instrucao[q];
  61. }
  62. Instrucao * gerarInst(){
  63. return new Instrucao;
  64. }
  65.  
  66. void gerarEndInst(Instrucao* inst){
  67. inst->add1= gerarEnd();
  68. inst->add2= gerarEnd();
  69. inst->add3= gerarEnd();
  70. }
  71.  
  72. void deleteInst(Instrucao *a){
  73. delete[] a;
  74. }
  75. Instrucao *posToPointInst(Instrucao *z, int k){
  76. Instrucao *aux=&z[k];
  77. return aux;
  78. }
  79. void juntarInst(Instrucao *a, Instrucao*b){
  80. a->add1 = getAdd1(b);
  81. a->add2 = getAdd2(b);
  82. a->add3 = getAdd3(b);
  83. a->opcode = getOpcode(b);
  84. }
  85.  
  86. void juntarInst(Instrucao *a, Instrucao*b, int i){
  87. setAdd1(&a[i], getAdd1(b));
  88. setAdd2(&a[i], getAdd2(b));
  89. setAdd3(&a[i], getAdd3(b));
  90. setOpcode(&a[i], getOpcode(b));
  91. }
  92.  
  93. Endereco *getAdd1(Instrucao *c) {
  94. return c->add1;
  95. }
  96.  
  97. Endereco *getAdd1(Instrucao *c, int i) {
  98. Instrucao *aux=&c[i];
  99. return aux->add1;
  100. }
  101.  
  102. void setAdd1(Instrucao *c, Endereco *add1) {
  103. c->add1 = add1;
  104. }
  105.  
  106. Endereco *getAdd2(Instrucao *c) {
  107. return c->add2;
  108. }
  109. Endereco *getAdd2(Instrucao *c, int i){
  110. return c[i].add2;
  111. }
  112.  
  113. void setAdd2(Instrucao *c, Endereco *add2) {
  114. c->add2 = add2;
  115. }
  116.  
  117. Endereco *getAdd3(Instrucao *c) {
  118. return c->add3;
  119. }
  120.  
  121. Endereco *getAdd3(Instrucao *c, int i){
  122. return c[i].add3;
  123. }
  124.  
  125. void setAdd3(Instrucao *c, Endereco *add3) {
  126. c->add3 = add3;
  127. }
  128.  
  129. int getOpcodev(Instrucao *c, int i) {
  130. return c[i].opcode;
  131. }
  132.  
  133. int getOpcode(Instrucao *c) {
  134. return c->opcode;
  135. }
  136.  
  137. void setOpcode(Instrucao *c, int opcode) {
  138. c->opcode = opcode;
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement