What does it mean to say that a programming language is machine independent? Tra
ID: 3697770 • Letter: W
Question
What does it mean to say that a programming language is machine independent? Translate the following Python program into the machine language described in Appendix C. Translate the statement Halfway = Length + Width into the machine language of Appendix C, assuming that Length, Width, and Halfway are all represented in floating-point notation. Translate the high-level statement into the machine language of Appendix C, assuming that W, X, Y, and Z are all values represented in two's complement notation, each using one byte of memory. Why was it necessary to identify the type of data associated with the variables in question 4 in order to translate the statements? Why do many high-level programming languages require the programmer to identify the type of each variable at the beginning of a program?Explanation / Answer
Answer to 1-
Machine independent means the source code can run on
various platforms, without modification for the sake of a particular operating system or hardware. Such languages are Java, Python, and to a large degree Perl and PHP.
C/C++, and C# are the opposite, because their source code can be written to work only on a particular type of machine. Programming languages are machine independent because the package you get contains a translator for your machine.
When you run Visual Basic or Turbo Pascal, you are actually running something called a compiler. The compiler reads the language and converts that language into a sequence of instructions in the language for the machine running that compiler.
The sequence can be a hardware-level translation or a half-way translation called a program code compilation. In the latter case, there is a run-time system that interprets the program code in a "shell" environment that makes it look like you are executing instructions independent of the hosting machine.
Answer to 2-
movl $0, %ecx
loop:
cmpl $3 %ecx
addl $1 %ecx
jle loop
Answer to 3-
ORG 100 /origin of program is location 100
LDA L /Load operand from location Length
ADD W /Add operation form location Width
STA H /Store sum in location halfway
HLT /Halt computer
DEC 83 /Decimal operand
DEC –2 /Decimal operand
DEC 0 /Sum stored in location halfway
END
Answer to 4-
LDA X
cmpl $0 X
je loop
jne else
endloop:
loop:
LDA Y
ADD w
STA Z
HLT
DEC 83
DEC -2
DEC 0
jmp endloop
else:
LDA Y
ADD X
STA Z
HLT
DEC 83
DEC -2
DEC 0
jmp endloop
Answer to 5-
A variable definition means to tell the compiler where and how much to create the storage for the variable. A variable definition specifies a data type, and contains a list of one or more variables of that type. A variable provides us with named storage that our programs can manipulate. Each variable has a specific type, which determines the size and layout of the variable's memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable.
note- the above explanation can help to answer the given question. and to answer 2,3,4,5 in clear Appendix C data is need to be mentioned.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.