Guest User

Untitled

a guest
Apr 24th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. #include <stdlib.h>
  2.  
  3. // --------------------------------------------------------------
  4. /* stores the value at the specified register. Success/fail -
  5. * if the address is illegal or the value is illegal (>8, >4)
  6. * it will fail.
  7. */
  8.  
  9. int storeRegister(int address, const unsigned char value);
  10.  
  11. // --------------------------------------------------------------
  12. /* gets the value from register specified by "address" and places it
  13. * into the value. It is success/fail - it will fail if
  14. * the address is illegal (>8)
  15. */
  16.  
  17. int fetchRegister(int address, unsigned char value);
  18.  
  19.  
  20. // --------------------------------------------------------------
  21. /* dumps contents of registers to specified file, in decimal and hex.
  22. * Each register is printer per line following decimal and hex value.
  23. * Primarily for debugging use and to view the contents of memory
  24. * after the "simulator" has terminated.
  25. */
  26.  
  27. void registersDump(FILE *f);
  28.  
  29. ----------------header end
  30. #include <stdlib.h>
  31. #include <stdio.h>
  32. #include "Memory.h"
  33.  
  34. static unsigned char registers[9];
  35. static char regNames[9] = {"%eax","%ebp","%ebx",
  36. "%ecx","%edi","%edx",
  37. "%esi","%esp","PC" };
  38.  
  39. // --------------------------------------------------------------
  40. /* stores the value at the specified register. Success/fail -
  41. * if the address is illegal or the value is illegal (>8, >4)
  42. * it will fail.
  43. */
  44.  
  45. int storeRegister(int address, const unsigned char value){
  46. registers[address] = value;
  47. }
  48.  
  49. // --------------------------------------------------------------
  50. /* gets the value from register specified by "address" and places it
  51. * into the value. It is success/fail - it will fail if
  52. * the address is illegal (>8)
  53. */
  54.  
  55. int fetchRegister(int address, unsigned char value){
  56. value = registers[address];
  57. }
  58.  
  59. // --------------------------------------------------------------
  60. /* dumps contents of registers to specified file, in decimal and hex.
  61. * Each register is printer per line following decimal and hex value.
  62. * Primarily for debugging use and to view the contents of memory
  63. * after the "simulator" has terminated.
  64. */
  65.  
  66. void registersDump(FILE *f){
  67. int i;
  68. for(i = 0; i<8; i++){
  69. fprintf(f, "
Add Comment
Please, Sign In to add comment