LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-24-2014, 07:47 PM   #1
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,416
Blog Entries: 43

Rep: Reputation: 36
Portable Numbers Format: PRINT Before CRASH Doesn't Work


http://forums.techguy.org/software-d...esnt-work.html
 
Old 04-25-2014, 01:50 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
ummmm .... is this a question??
 
Old 04-25-2014, 04:08 PM   #3
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,416

Original Poster
Blog Entries: 43

Rep: Reputation: 36
Yes. This is a question.
 
Old 04-25-2014, 04:30 PM   #4
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Doesn't have a ? mark and it appears to be a link.

Put some effort into it.
 
Old 04-25-2014, 05:17 PM   #5
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,416

Original Poster
Blog Entries: 43

Rep: Reputation: 36
It's a link the the question.
 
Old 04-26-2014, 12:56 AM   #6
ndc85430
Member
 
Registered: Apr 2014
Distribution: Slackware
Posts: 92

Rep: Reputation: Disabled
You've posted too much code. You need to start by trying to hone in on the problem area - print the values of variables at different points in the code, or use a debugger to step through the code. Once you've found the code that's causing the problem, if you're still stuck, then post just enough to reproduce the problem, along with sample input and output.

As an aside, you've got some really long methods in there (PNF::execute(), for one). This really makes the code much more difficult to follow. Prefer using shorter methods. Google for "clean code" for info about this.
 
Old 04-26-2014, 04:17 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Surely you do not seriously expect someone else to read through 100's of lines of code to find your problem?

And whilst you may have raised a question on the other site, that is no reason to at least provide some background here and advise that you have not copied the copious amount
of code here but have provided a link for efficiency. You didn't even have the courtesy to advise what the link was to. Out of habit I do not click on links that I know nothing about.
Hence my original post.


ndc would appear to have provided some much needed pre-work for you to do before anyone here will attempt to help you.
 
1 members found this post helpful.
Old 04-26-2014, 08:45 PM   #8
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,416

Original Poster
Blog Entries: 43

Rep: Reputation: 36
Here are some code snippits that may have the problem in them.

The PRINT instruction:
Code:
   case IPRINT:
   {
        switch (reg.type)
        {
         case TVOID:
         {
          if (reg.operand != 0)
           crash("Invalid VOID Value.");
          else
          {
           reg.accumulator.print();
          }
         }
         break;

         case TBOOLEAN:
          switch (reg.operand)
          {
           case 0:
            cout << "false";
            break;

           case 1:
            cout << "true";
            break;

           default:
            cout << "true";
            break;
          }
          break;

         case TNUMBER:
          cout << reg.operand;
          break;

         case TCHARACTER:
          cout << (char)reg.operand;
          break;

         case TSTRING:
         {
          unsigned long is = 0;
          for (is = k; mem.get(is) != 0; ++is)          
           cout << (char)mem.get(is);

          i = is + 1;
          j = i + 1;
          k = i + 2;

          i = i - 3;
          j = i + 1;
          k = i + 2;
         }
         break;
              
         default:
          crash("Invalid Type.");
          break;
        };
   }
        break;
The CRASH instruction:
Code:
   case ICRASH:
        switch (reg.type)
        {
         case TSTRING:   
              {           
               unsigned long l;
               String str;
               for (l = k; mem.get(l) != 0; ++l)
               {
                char c = (char)mem.get(l);
                str = str + c;
               }
               i = l;
               crash(str.getString());
              }
              break;
              
         default:
                 crash("Invalid Type.");
                 break;
        }
        break;
The crash() function:
Code:
void PNF::crash(String str)
{
 error(ERROR, str);
 cout << endl;

 cout << "Registers:\n";
 cout << "==========\n";
 cout << "%icount              = " << reg.icount << endl;
 cout << endl;
 cout << "%instruction         = " << reg.instruction << endl;
 cout << "%type                = " << reg.type << endl;
 cout << "%operand             = " << reg.operand << endl;
 cout << "%typeof              = " << reg.type_of << endl;
 cout << "%accumulator         = ";
 reg.accumulator.print();
 cout << endl;
 cout << "%calc                = ";
 reg.calc.print();
 cout << endl;
 cout << "%iname               = " << reg.iname;
 cout << "\n\n";


 for (unsigned long i = 0; i < mem.length(); ++i)
  cout << "memory[" << i << "]: " << mem.get(i) << endl;
 cout << "\n\n";

 for (unsigned long i = 0; i < stk.length(); ++i)
 {
  cout << "Stack[" << i << "]: ";
  stk.top().println();
 }

 for (unsigned long i = 0; i < reg.args.length(); ++i)
  cout << "args[" << i << "]: " << reg.args.get(i) << endl;
 cout << "\n\n";
 
 
 exit(-1);
}
 
Old 04-26-2014, 09:18 PM   #9
des_a
Senior Member
 
Registered: Sep 2006
Posts: 1,416

Original Poster
Blog Entries: 43

Rep: Reputation: 36
The error was actually in my assembler I found out. It was not assembling the code correctly because it was not giving the terminating null at the end of the string for the PRINT instruction. When I added that to assemble correctly, it worked.
 
Old 04-27-2014, 02:40 AM   #10
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Good job on finding the solution and thank you for sharing it
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Print numbers and associated text belonging to an interval of numbers Trd300 Linux - Newbie 27 03-11-2012 05:58 AM
xls2csv doesn' t work with excel date format. zebela Red Hat 3 11-06-2009 01:27 PM
Print screen doesn't work mysticsound Linux - Laptop and Netbook 1 03-17-2005 09:24 AM
portable cd-rw/dvd-rom drive gcc-5240p doesn't work under linux? amimusa Linux - Hardware 0 08-30-2004 10:40 PM
Mozilla problems: Print/print preview doesn't work, not recording sites in history... andy_g_gray Linux - Software 3 01-23-2004 06:27 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration