-1

Assume that you have a Pep/8 type computer and the following disk files:

  • File A: A Pep/8 assembly language assembler written in machine language.
  • File B: A C++-to-assembly language compiler written in assembly language
  • File C: A C++ program that will read numbers from a data file and print their median
  • File D: A data fie for the median program of file C.

To compute the median, you must make the four computer runs described schematically in figure 5.28. Each run involves an input file that will be operated by a program to produce the output file. The output file produced by the one run may be used either as the input file or as the program of a subsequent run. Describe the contents of files E, F, G and H, and label the empty blocks in figure 5.27 with the appropriate letter.

Figure 5.28 input window ,

Run 1  -- A -- E
Run 2    -   -- F3
Run 3  --     -- G
Run 4  --   --

I figure: C++-->>(compiler )-->>assembly language-> ( assembler)--> machine code
I see that pep 8 assembler generates space for variables . But lets say i Have this file with data: where and how does it fit the flow? Is it translated to machine language at the same time the source c++ is compiled? How to answer the original question?

  • No, the data file is of course processed by the median program itself. – Jester Nov 25 '15 at 00:32
  • data file -- median program (c++) --- whats the output? – user1652946 Nov 25 '15 at 00:44
  • or rather : data file ===>median program.exe ===> what's the output (machine code, assembly or what else?) what happens to it? – user1652946 Nov 25 '15 at 01:02
  • Well the description says "print their median" so that's the output. But that's a single number, not a file. Presumably. – Jester Nov 25 '15 at 01:08
  • Run 1: c++ program to read median==>assembly compiler==> assembly code . Run2: assembly code==>> assembler ===> machine code (this is the exec) – user1652946 Nov 25 '15 at 01:39
  • Run 1: c++ program to read median==>assembly compiler==> assembly code . Run 2: assembly code==>> assembler ===> machine code (this is the exec). Run 3: data file==>> exec in machine code==> output. Whats the 4th run? – user1652946 Nov 25 '15 at 01:46

1 Answers1

0
  1. Assemble the c++ compiler using the assembler to get machine code.
  2. Compile the median c++ code using the compiler from step #1, this will give you median assembly code.
  3. Assemble the median assembly code from step #2, this will give you median machine code.
  4. Run the median machine code program on the input data file, this will give you the output.
Jester
  • 56,577
  • 4
  • 81
  • 125
  • Why not compile straight into machine code, assuming the type of computer/Cpu is known? Why the intermediate assembly step? – user1652946 Nov 25 '15 at 02:17
  • You could, if you were not given these set of rules. You only have one file that can produce machine code and that's your assembler. – Jester Nov 25 '15 at 02:22
  • In real life, is there the intermediate step? While compiling a simple C++ or other higher order language on a PC, is there still an assembler involwed and if so , why? – user1652946 Nov 25 '15 at 02:26
  • Depends on the toolchain. `gcc` produces asm code which is then assembled, visual studio produces machine code directly I believe. `llvm` also produces some intermediate language. This way you can reuse the parts. – Jester Nov 25 '15 at 02:30