Practical Computer Architecture with Python and ARM by Alan Clements

Practical Computer Architecture with Python and ARM by Alan Clements

Author:Alan Clements [Alan Clements]
Language: eng
Format: epub, pdf
ISBN: 9781837636679
Publisher: Packt Publishing
Published: 2023-07-31T00:00:00+00:00


Summary

In this chapter, we presented the TC1 simulator, which can take a text file in TC1 assembly language, convert it into machine code, and then execute it. TC1’s instruction set architecture is close to the classic RISC architecture with a register-to-register architecture (i.e., data operations take place on the contents of registers). The only memory operations permitted are loading a register from memory (or a literal) and storing a register in memory.

The simulator has two basic components: an assembler that translates a mnemonic such as ADD r1,r2,r3 into a 32-bit binary instruction, and an interpreter that reads the instruction, extracts the necessary information, and then executes the instruction.

Some of the elements of TC1 are rather unusual. A free-format structure for the source code is provided; for example, you can write ADD r1,r2,r3 or adD R1 r2 r3 and both instructions will be happily accepted. Why? First, it was done to demonstrate the use of string processing in Python. Second, it makes it easier for the user to enter input in their chosen case. All input is automatically converted into uppercase to make the language case-free. Similarly, a comma or space is allowed as a separator between parameters. Finally, the need for [] brackets to indicate indirect addressing was removed. Users may enter LDRI r0,[r1] or LDRI r0,r1.

Similarly, numbers can be entered in different forms (decimal, binary, or hexadecimal); for example, number bases can be indicated in Motorola format or Python format. Most real assemblers don’t permit such luxury.

The first versions of TC1 required all addresses to be numeric; if you wanted to branch to line 30, you had to write BRA 30. It was the remarkable power and ease of use of Python’s dictionary structure that made it so easy to include labels. All you have to do is recognize a label, pop it in the dictionary together with its value, and then, whenever you encounter that label, just look up its value in the dictionary.

We also provided an example assembly language program to test TC1 and a short discussion of how we go about testing various instructions.

Having designed TC1, we created a rather simplified version and called it TC1mini. This simulator does not provide the same flexibility in writing instructions, and it does not have a large instruction set. It also does not encode the instruction into a binary form and then decode it again and execute it. It executes the assembly instruction directly (thanks one more to Python’s dictionary mechanism).

At the end of this chapter, we provided yet another simplified computer simulator to both emphasize the structure of a computer simulator and provide an example of the way in which you can modify the basic design.

In this key chapter, we introduced the TC1 computer simulator and presented its design. We also looked at variations of TC1 to help create a more complete picture of the simulator and assembler. In the next chapter, we will take things a step further and look at some more aspects of the simulator. We will describe several simulators that have different architectures.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.