1 / 25

Assembler Tutorial

Assembler Tutorial. This program is part of the software suite that accompanies the book The Digital Core , by Noam Nisan and Shimon Schocken 2003, www.idc.ac.il/csd , forthcoming by MIT Press The software suite was developed by students at the Efi Arazi School of Computer Science at IDC

emelda
Download Presentation

Assembler Tutorial

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Assembler Tutorial This program is part of the software suite that accompanies the book The Digital Core, by Noam Nisan and Shimon Schocken 2003, www.idc.ac.il/csd, forthcoming by MIT Press The software suite was developed by students at the Efi Arazi School of Computer Science at IDC Chief Software Architect: Yaron Ukrainitz

  2. Simulators: • used to build hardware platforms and execute programs; • supplied by us. • Translators: • Written by the students; • Executable solutions available. The book’s software suite: Translators: • Assembler: translates programs written in the Hack assembly language to executable code written in the Hack machine language; • JcVM (modeled after Java’s JVM): translates programs written in the stack-based Virtual Machine (VM) language to assembly programs; • Jack Compiler: translates programs written in the Java-like Jack language to VM programs that can run on the Virtual Machine.

  3. This tutorial describes the Assembler • The Assembler generates binary code that can be tested either in the hardware simulator or in the CPU emulator. The book’s software suite:

  4. Assembler Tutorial • Purpose: learn how to use the supplied Assembler, designed to translate programs from Hack assembly to Hack machine code • Required knowledge: Chapter 5 of the book • Contents: I. Assembly program example II. Command-level Assembler III. Interactive Assembler

  5. Assembler Tutorial Part I: Before we start talking about the Assembler, let’s take a look at a typical assembly program

  6. sum.bin 0000000000010000 1110111111001000 0000000000010001 1110101010001000 0000000000010000 1111110000010000 0000000001100100 1110010011010000 0000000000010010 1110001100000001 0000000000010000 1111110000010000 0000000000010001 1111000010001000 0000000000010000 1111110111001000 0000000000000100 1110101010000111 Assembler Example sum.asm /* sum=1+2+ … +100 */ @i // i=1 M=1 @sum // sum=0 M=0 (loop) @i // if i-100>0 goto end D=M @100 D=D-A @end D;jgt @i // sum+=i D=M @sum M=D+M @I // i++ M=M+1 @loop // goto loop 0;jmp (end)

  7. Example sum.asm /* sum=1+2+ … +100 */ @i // i=1 M=1 @sum // sum=0 M=0 (loop) @i // if i-100>0 goto end D=M @100 D=D-A @end D;jgt @i // sum+=i D=M @sum M=D+M @I // i++ M=M+1 @loop // goto loop 0;jmp (end) The assembly program: • Stored in a text file named Prog.asm • Written and edited in a text editor The assembly process: • Translates Prog.asm into Prog.bin • Comments and white space are ignored • Variables (e.g. i and sum) are allocated to memory • Labels (e.g. loop and end) are psuedo commands that generate no code • Each assembly command is translated into a 16-bit instruction written in the Hack machine language.

  8. Assembler Tutorial • Purpose: learn how to use the supplied Assembler, designed to translate programs from Hack assembly to Hack machine code • Required knowledge: Chapter 5 of the book • Contents: I. Assembly program example II. Command-level Assembler III. Interactive Assembler

  9. Assembler Tutorial Part II: Learn how to use the Assembler from the operating system’s shell level, batch style. (the Assembler that you have to write should have the same GUI and behavior)

  10. The command-level assembler The OS “type” command can be used to inspect the assembly source (.asm file) (in your computer the path will probably be different)

  11. Inspecting the source file Source code is shown

  12. Invoking the Assembler Invoke the Assembler program Name of the source assembly file (full path). This file name is an argument of the Assembler program.

  13. Invoking the Assembler The OS “type” command can be used to inspect the translated code(.bin file)

  14. Inspecting the translated code Binary code is shown Two ways to test the binary code: 1. Invoke the Hardware Simulator, load the Computer chip, then load the code (.bin file) into the internal ROM chip; 2. Load and run the code in the CPU Emulator (much quicker).

  15. Assembler Tutorial • Purpose: learn how to use the supplied Assembler, designed to translate programs from Hack assembly to Hack machine code • Required knowledge: Chapter 5 of the book • Contents: I. Assembly program example II. Command-level Assembler III. Interactive Assembler

  16. Hardware Simulation Tutorial Part III: Learn how to use the interactive assembler

  17. Loading an assembly program 1. To load an assembly program, click here. 2. Navigate to a directory and select an .asm file.

  18. Loading an assembly program • Read-only view of the assembly source code • To edit it, use an external text editor.

  19. Translating a program Immediate translation(no animation) Re-start the translation Stop the translation Translate the entire program Translate line-by-line

  20. 1. Click an assembly command 2. The translated binary code is highlighted Inspecting the translation

  21. Saving the translated code Saves the translated binary code in a .bin file • If an assembly command contains a syntax error, the translation stops with an error message • The “save file” operation is enabled only if the translation was error-free.

  22. Comparing the translated code to a compare-file 1. Load a comparison file 2. Select a comparison (.bin) file

  23. Comparing the translated code to a compare-file 2, Translate the program (any translation mode can be used, as usual) 1. Comparison file is shown

  24. Comparing the translated code to a compare-file The translation of the highlighted line does not match the corresponding line in the compare file.

  25. Mistakes are the portals of discovery James Joyce (1882-1941)

More Related