[I tried] Nand2 Tetris Chapter 6

Last time (Nand2Tetris Chapter 5 Part 2) is a continuation.

I used it as a reference. Alone Nand2Tetris / Hiraku

The following are topics to be learned while actually moving hands in this book. * hardware * Architecture * operating system * Programming language * Compiler * Data structures and algorithms * Software engineering <-now
I wrote it in the footer, but it took 11 hours and 30 minutes. I worked hard. # Chapter 6 Assembler The second half of this book from here. The first half was hardware, but the second half seems to be software.

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

[I tried] Nand2 Tetris Chapter 6
I tried 100 language processing knock 2020: Chapter 3
I tried 100 language processing knock 2020: Chapter 1
I tried 100 language processing knock 2020: Chapter 2
I tried 100 language processing knock 2020: Chapter 4
I tried PyQ
I tried AutoKeras
I tried papermill
I tried django-slack
I tried Django
I tried spleeter
I tried cgo
I tried using argparse
I tried using anytree
I tried competitive programming
I tried using aiomysql
I tried using Summpy
I tried using coturn
I tried using "Anvil".
I tried using Hubot
I tried using ESPCN
I tried PyCaret2.0 (pycaret-nightly)
I tried deep learning
I tried AWS CDK!
I tried using Ipython
I tried to debug.
I tried using PyCaret
I tried using cron
I tried Kivy's mapview
I tried using ngrok
I tried using face_recognition
I tried to paste
I tried using Jupyter
I tried using PyCaret
I tried moving EfficientDet
I tried shell programming
I tried using Heapq
I tried using doctest
I tried Python> decorator
I tried running TensorFlow
I tried Auto Gluon
I tried using folium
I tried using jinja2
I tried AWS Iot
I tried Bayesian optimization!
I tried using folium
I tried using time-window
I tried Value Iteration Networks
I tried fp-growth with python
I tried scraping with Python
I tried AutoGluon's Image Classification
I tried Learning-to-Rank with Elasticsearch!
[I tried using Pythonista 3] Introduction
I tried using easydict (memo).
I tried to organize SVM.
I tried face recognition using Face ++
I tried using Random Forest
I tried clustering with PyCaret
I tried using BigQuery ML
I tried "K-Fold Target Encoding"
I tried to implement PCANet