Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1.  
  2. #include "passI.h"
  3. #include "assemblerLib.h"
  4.  
  5. using namespace std;
  6.  
  7. bool passI() {
  8. /******************************************************************************************
  9. * Look up for symbols and constants in the source code and remember their location.
  10. *******************************************************************************************/
  11. SourceList& sourceList = getSourceList();
  12.  
  13. Section section = S_TEXT;
  14. long location = 0; // Start postition at 0
  15. for (SourceLine sourceLine : sourceList) {
  16. ParamStack params;
  17. getParams(params, sourceLine);
  18.  
  19. Directive directive = getDirective(sourceLine);
  20. if (directive == D_ORG) {
  21. if (checkEnoughParams(sourceLine, params, 1)) {
  22. changeSectionAndLocation(params.top(), section, location);
  23. }
  24. }
  25.  
  26. string opSym;
  27. if (getExecutable(opSym, sourceLine)) {
  28. } else {
  29. if (directive == D_WORD) {
  30. while (!params.empty()) {
  31. pushLiteral(location, constConv(params.top()));
  32. params.pop();
  33. //location += 4;
  34. }
  35. } else if (directive == D_SPACE) {
  36. checkEnoughParams(sourceLine, params, 1);
  37. //location += stoi(params.top) + 4 - stoi(params.top()) % 4;
  38. //ovo gore ti je zato sto za blok uzimas onoliko kolika je vrednost parametra ali uvek se pomeras za po 4 , znaci ako je npr vrednost param 7 , zauzaces jos 8 lokacija(mora biti prvi veci broj deljiv sa 4)
  39. } else if (directive == D_GLOBL) {
  40. if (checkEnoughParams(sourceLine, params, 1)) {
  41. if (globalSymbolExists(params.top())) {
  42. string msg = "Global symbol already exist: " + string(params.top());
  43. addError(sourceLine, msg);
  44. }
  45. pushGlobalSymbol(params.top(), location);
  46. }
  47. } else if (directive == D_EXTERN) {
  48. if (checkEnoughParams(sourceLine, params, 1)) {
  49. if (externSymbolExists(params.top())) {
  50. string msg = "Extern symbol already exist: " + string(params.top());
  51. addError(sourceLine, msg);
  52. }
  53. pushExternSymbol(params.top(), location);
  54. }
  55. }
  56. }
  57. }
  58.  
  59. return !errorsFound();
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement