VM implementation on the Hack platform ����������� �������������(������������������� SP 0 ���"������������������� RAM ������'��(�����C� LCL 1 �������������(�����(������� ��!��������������� ARG 2 �'�����+��������������� THIS 3 The stack: ���������� RAM[256 ###� 2047]; THAT 4 Host ����������������������������� RAM �������� SP 5 . . . RAM static: ���������� RAM[16 ###� 255]; TEMP ���������������(������� static i ��������������� 12 ���(���������� f ������������������������"�'� 13 ����������'�"��� f.i ����������������������"����(������� General �����������'�"����������� RAM +�(������������=>���%���� 14 purpose local,argument,this,that: ������������ ��!��� 15 ������������������������%�����(������������ 16 . . . 2048 ��%���+�������������������4����5#�����"���� Statics �����������(���������������������������� RAM 255 ���������� LCL +� ARG +� THIS +����� THAT #����������� 256 . . . ���� i �������'��(���'��(������������������� Stack ������������"'����������� RAM[segmentBase + i ] 2047 constant: ������'���!��������������� 2048 . . . ���������� constant i ���������������"'� Heap �����'����������������� i. pointer: ���������������# Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 7: Virutal Machine, Part I slide 25
VM implementation on the Hack platform ������������������ SP 0 2�%������%�����%���%����������'�������������� LCL 1 ������������������� RAM +�%������%�����$���� ARG 2 �������������������8������!������������������# THIS 3 (����������+��������%���������$�������������� THAT 4 Host ���������������(����%���������������� 5 . . . RAM � push constant 1 TEMP � pop static 7 ����������������������������(���������� f � 12 13 � push constant 5 General 14 purpose � add 15 � pop local 2 16 . . . � eq Statics ����� 255 256 =# ��������������������(���'������(���������� . . . Stack �����������E��������!�����$���������"�'� 2047 �����������!��!���������������������� 2048 ��������������������� A=M � . . . Heap )# �(�'������������(����������� �'�����!�����'��%��###� + '�����'����� R13 +� R14 +����� R15 # Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 7: Virutal Machine, Part I slide 26
Function call-and-return conventions ���������������� �����������������"��7������8 ��,������ $�������������� ������������� function demo 3 function mult 1 function demo 3 function mult 1 �,�����0�� ���� �� ��������� ... push constant 0 ... push constant 0 ��������� �����������;�������� push constant 7 pop local 0 // result (local 0) = 0 push constant 7 pop local 0 // result (local 0) = 0 ��������� � local, argument, push constant 2 label loop push constant 2 label loop this, that, pointer) add ... // rest of code ommitted add ... // rest of code ommitted push constant 3 label end +����������������,������������ push constant 3 label end call mult push local 0 // push result ��������������������������# call mult push local 0 // push result ... return ... return ����)���)���������������������� ������ +���������������������������������������������0����������������0 ������������������������� � &�������������������������������������0����������������������� ���� � $���������������������0������������������������������������0�������������������������)��������0� � �,�����������������������������������2�������������� call �������������������� ������������������������������������������ ���� � �2������"�������������� ����������� &��������������� :���������������)�������������������������������������������������2����������� � (���������������������� �� ���������������������������������������������������7��"�������8 � ���������������������0�������������� �� %�����")�����0����������������������������(����# � Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 14
Recommend
More recommend