Last time (Nand2Tetris Chapter 5 Part 2) is a continuation.
I used it as a reference. Alone Nand2Tetris / Hiraku
I wrote something like an impression in the comment out. just a little.
I think it took an hour to recognize the constructor as __init__
. .. ..
It took me a while to realize the concept of creating a class.
I haven't written such a code for a while, so
I couldn't remember the basic code, so it's fine I searched for something like "Python string replacement".
input("plz_input:", filename)
I was also doing strange things like this. Even though it's Python. memo
-** Symbol **
In the assembly world, instead of the commands LOAD, R3, 7
, GOTO, 250
, you can use symbols to write LOAD, R3, weight
, GOTO, LOOP
. However, what LOOP
indicates must be set.
Setting method
-** Variable **
You don't have to worry about the actual memory address because the converter sets it automatically.
-** Label **
The beginning of the code area can be set using a label such as LOOP.
/*1+2+3+...+100*/
i = 1
sum = 0
LOOP:
if i = 101 goto END
sum = sum + i
goto LOOP
END:
goto END //Infinitely loop the computer and end execution
Symbol name | Address name |
---|---|
i | 1024 |
sum | 1025 |
LOOP | 2 |
END | 6 |
To convert these to code without symbols
Code that performed symbol resolution
M[1024] = 1
M[1025] = 0
if M[1024] = 101 goto 6
M[1025] = M[1025] + M[1024]
M[1024] = M[1024] + 1
goto 2
goto 6
This method should note the following -Only up to 1024 program codes can be stored. -The memory area of source commands and variables is all expressed by one word. In the case of a converter as well, it is necessary to design in consideration of the word width of the variable.
-** Assembler ** Write a program that performs the following processing with reference to the machine language specifications --Parsing the assembly command and splitting it into basic areas --Generate corresponding machine language bits in each area -Replace symbolic references with numeric memory addresses (if needed) --Combine binary code for each region
End of script - Comparison ended succesfully
It took 11 hours and 30 minutes. Progress repository_GitHub
Recommended Posts