Questions on Simulator

65 views
Skip to first unread message

Murali Krishnan

unread,
Oct 3, 2020, 1:11:53 PM10/3/20
to xos-...@googlegroups.com
I received the following questions about the machine simulator.  Posting to the group for the information of all.   (These questions have nothing to do with OS - they are about the simulator implementation. But can be useful in avoiding errors sometimes - as these will help you to understand the limitations of the simulator). 

Q:  Recently, while working(playing) with the XSM machine, I noticed that I could only print a string with a maximum of 13 characters and that I could print a number only between -2147483648 and 2147483647.

Reason:  The XSM is simulated in C. The simulator is designed to permit only strings of length at most 13 characters and numbers between -MAXINT and MAXINT in C language. 

Q:  In binary, 2147483647 translates to 31 ones (In hexadecimal to 7FFFFFFF) and found that negative numbers are represented in the 2's complement form. So, a total of 32 bits could be used by numbers. And 13 characters could be used by strings. Why is it like that? They are both supposed to be 1 word right? Why the different limits, though? And how are characters expressed in the machine? As ASCII?

Reason:  Since this is not a real machine, these limits are imposed by the simulator code.  Technically, each memory word is a union of two data types - an integer and a character array.


Also, I noticed that if I give the command:
temp= exposcall("Write", -2, "123456789");
It gives the same result as if I have given the command:
temp= exposcall("Write", -2, 123456789);
i.e. Printing the number 123456789. Even, inside double quotes, how is the machine able to identify this as a number?


Note that, if I had given the command,
temp= exposcall("Write", -2, "1234A6789");
The machine identifies it as a string and prints 1234A6789. This was obvious when I tried to print a number inside double quotes just out of limit for numbers(greater than 2147483647), but inside the limit for strings(less than 13 characters). I gave the command:
emp= exposcall("Write", -2, "2147483648");
Giving me the result -2147483648, making it obvious that the mahine identifies it as a number rather than a string.


Reason:  I think the implementation has done an atoi if the input is an integer.  


Why is this happening, sir? Does it mean that I cannot print a number with 12 or 13 digits as a string? (max. 13 characters gets printed for a string)

Answer:  Yes.  You can't go beyond -MAXINT -  MAXINT in C programming language. 

Reply all
Reply to author
Forward
0 new messages