Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    HACK Assembly Ported to FUZE

    Creation share codes
    4
    18
    1195
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L
      LucasJG25 last edited by

      Screenshot (11).png

      Above are the OPCodes used to Operate this computer. As shown there are destination, C instruction and jump comands.

      To edit/write the code in Fuze you need to write it into a string provided in the code.

      IMPORTANT
      I haven't fully tested this VM yet. But so far works fine. Let me know if there are any bugs.

      ROM is supposed to be within the range of 0 to 65535. But due to Memory constraints, ROM is 0 to 30000. RAM has it's full length. Screen was supposed to be 131,072 pixels (512x256), Instead it has 80,000 pixels (400x200).

      There is actual code out there that people have written, (Games, apps, etc.) which you could (in theory) write into FUZE via this VM. Though the screen and ROM won't be the same so some changes to the code will be made when reading code online written in the Hack language. This also means that code compile from the JACK compiler into the HACK assembly code should be able to run in this VM in FUZE too.

      Hope you enjoy.

      Shared Code
      WYC63MND9K

      Doriphor 1 Reply Last reply Reply Quote 10
      • JMM161437
        JMM161437 F last edited by

        0.0... you just keep impressing me

        1 Reply Last reply Reply Quote 2
        • L
          LucasJG25 last edited by

          Update:
          Labels and variables are now working. Should have been working on the first upload but forgot to add them. But they're working now. Enjoy!

          1 Reply Last reply Reply Quote 2
          • L
            LucasJG25 last edited by

            I've managed to speed up the VM a bit by putting a timer on the update() function. As well as removing unnecessary loops based on using arrays to index the OPCodes instead of using IF statements. So far so good.

            1 Reply Last reply Reply Quote 0
            • L
              LucasJG25 last edited by LucasJG25

              Added built in symbols used within the language. See image below.
              Screenshot (12).png

              1 Reply Last reply Reply Quote 0
              • L
                LucasJG25 last edited by LucasJG25

                This is a code example used within the Nand2Tetris course used to introduce the hack assembly language to the student.

                // This file is part of www.nand2tetris.org
                // and the book "The Elements of Computing Systems"
                // by Nisan and Schocken, MIT Press.
                // File name: projects/06/rect/Rect.asm
                
                // Draws a rectangle at the top-left corner of the screen.
                // The rectangle is 16 pixels wide and R0 pixels high.
                
                   @0
                   D=M
                   @INFINITE_LOOP
                   D;JLE 
                   @counter
                   M=D
                   @SCREEN
                   D=A
                   @address
                   M=D
                (LOOP)
                   @address
                   A=M
                   M=-1
                   @address
                   D=M
                   @32
                   D=D+A
                   @address
                   M=D
                   @counter
                   MD=M-1
                   @LOOP
                   D;JGT
                (INFINITE_LOOP)
                   @INFINITE_LOOP
                   0;JMP
                

                All of this code from the example works. However, notice the code @32. This instruction is used mainly to move the pointer which is used to draw to the screen a line down. Thus this draws a rectangle. Adding 32 to the current position would work if the screen was (512x256). But the screen used within the VM is (400x200). So instead you'll need to replace that code with @25. 25 is used in that resolution to move the pointer to the next line directly below the previous location which is above.

                1 Reply Last reply Reply Quote 2
                • PickleCatStars
                  PickleCatStars F last edited by

                  Is this the type of thing that someone interested in assembly might use to ‘get a feel for it’ before possibly moving on to real hardware?

                  L 1 Reply Last reply Reply Quote 1
                  • L
                    LucasJG25 @PickleCatStars last edited by LucasJG25

                    @toxibunny Indeed. In fact you'll learn how to build a computer from nothing but a NAND gate using a HDL language (Hardware description Language) which is used to program hardware in a hardware simulator. Assembly language would be the one abstraction up from that.

                    But yea, you can get a feel for assembly with this before moving on to the real hardware.

                    1 Reply Last reply Reply Quote 4
                    • Doriphor
                      Doriphor @LucasJG25 last edited by Doriphor

                      @LucasJG25 oh! I remember writing a CPU and assembler for this (as part of the NAND to Tetris course). Great job!

                      The book is pretty great btw for those who are interested.

                      @toxibunny Yes but it can give you the impression that assembly is this arcane art that only code wizards can practice properly, when in fact, even in the 80s, assembly was relatively easy in comparison to this thanks to the magic of macros!

                      1 Reply Last reply Reply Quote 3
                      • L
                        LucasJG25 last edited by LucasJG25

                        Here is the same Hack Assembler but attached to a text editor. meaning you don't code in the FUZE editor anymore. But you instead code within the editor running in FUZE. Read the comments as to how to use the editor.

                        TextEditor:
                        Code: LVW53MND9K (pending)

                        Make sure to use the delete key to erase characters from a line of text instead of backspace.

                        To display pixels to the screen give RAM[21451] = 1.

                        1 Reply Last reply Reply Quote 4
                        • L
                          LucasJG25 last edited by LucasJG25

                          Due to memory constraints the ROM had to be reduced. From a whopping 30,000 lines of code to 583 lines. But this reminds me that in every decision when designing software or hardware. There are some sacrifices that have to be made. For example if I had stuck to 30,000 lines of code. Then only 1 file can be used to save and load from. That doesn't really sound to good in terms of saving your code and wanting to make a new project within the text editor without copying the entire text editor code into a new FUZE project.

                          But now with less lines of code. More files can be used. And amazingly a whole 100 files can be accessed. That speaks volumes!!

                          Also, I made the decision to reduce the lines of code to provide a challenge. Is it possible to write 583 lines of assembly code and make a game? And since we have 100 files at our disposal. 100 games!!!

                          Here's the file system working in action

                          I fixed that little bug which didn't show you the correct maximum of characters when loading and saving.

                          1 Reply Last reply Reply Quote 6
                          • JMM161437
                            JMM161437 F last edited by

                            Me: -works hard on my circuit designer and has bugs- LucasJG25:yeah Ima create a full computer that is functional and you can program it... you are really amazing at this stuff!

                            1 Reply Last reply Reply Quote 4
                            • L
                              LucasJG25 last edited by

                              @JMM161437 Thank you! I'm looking forward to your circuit designer. ;)

                              So, I'm currently working on the language (Not updating it but rather learning to code in it.) and I'll post up a little tutorial concerning how to construct functions, if statements and while loops. The more I learn how to code in this assembly code the more tutorials I'll be able to post up which will give some help to those who don't know about assembly or who find it difficult to code in this language.

                              The tutorial will take some time but it will be posted up soon.

                              1 Reply Last reply Reply Quote 0
                              • JMM161437
                                JMM161437 F last edited by

                                well I look forward to it... as for my circuit designer... yeah I'm keeping it DC Electric and keep this up... by the end of it you might be able to emulate Fuze inside of Fuze lol

                                1 Reply Last reply Reply Quote 1
                                • L
                                  LucasJG25 last edited by

                                  @JMM161437 hehe. We'll see. High level languages are more complex than assembly. But practice makes perfect.

                                  1 Reply Last reply Reply Quote 0
                                  • JMM161437
                                    JMM161437 F last edited by JMM161437

                                    @LucasJG25 yeah I like assembly, its fast when it runs and you can manipulate the CPU directly.

                                    1 Reply Last reply Reply Quote 1
                                    • L
                                      LucasJG25 last edited by

                                      Based on what I've tested so far. Functions are done by storing the return address before jumping to complete a task. It's much easier to plan assembly code when you think in line with functions and how they work. The code below goes into a bit of this as well as dealing with IF statements and While loops.

                                      //THIS IS A IF STATEMENT AND WHILE LOOP TEST. 
                                      //R0 IS THE REGISTER THAT HOLDS THE RETURN ADDRESS
                                      //R1 HOLDS THE RETURN VALUE FROM A FUNCTION
                                      //R2 AND R3 ARE USED FOR ARGUMENTS.
                                      //ENTER VALUE INTO R2 OR R3 AND THE PROGRAM WILL EVALUATE
                                      //WHETHER R2 IS GREATER THAN R3 OR VICE VERSA
                                      
                                      @MAIN
                                      0;JMP
                                      
                                      (CALL_CHECK)
                                      	@R2
                                      	D=M
                                      	@R3
                                      	D=D-M
                                      	@IF_TRUE0
                                      	D;JGT
                                      	@50
                                      	D=A
                                      	@R1
                                      	M=D
                                      	@IF_END0
                                      	0;JMP
                                      	(IF_TRUE0)
                                      	@100
                                      	D=A
                                      	@R1
                                      	M=D
                                      	(IF_END0)
                                      	@R0
                                      	A=M
                                      	0;JMP
                                      	
                                      (CALL_DRAW_PIXELS)
                                      	@16
                                      	D=A
                                      	@COUNT
                                      	M=D
                                      	@SCREEN
                                      	D=A
                                      	@R2
                                      	D=D+A
                                      	@SCREEN_PTR
                                      	M=D
                                      	(WHILE_LOOP0)
                                      	@SCREEN_PTR
                                      	A=M
                                      	M=-1
                                      	D=A
                                      	@32
                                      	D=D+A
                                      	@SCREEN_PTR
                                      	M=D
                                      	@COUNT
                                      	M=M-1
                                      	D=M
                                      	@WHILE_LOOP0
                                      	D;JGT
                                      	@R0
                                      	A=M
                                      	0;JMP
                                      	
                                      (MAIN)
                                      	@CC_RET0
                                      	D=A
                                      	@R0
                                      	M=D
                                      	@CALL_CHECK
                                      	0;JMP
                                      	(CC_RET0)
                                      	@CDP_RET0
                                      	D=A
                                      	@R0
                                      	M=D
                                      	@R1
                                      	D=M
                                      	@R2
                                      	M=D
                                      	@CALL_DRAW_PIXELS
                                      	0;JMP
                                      	(CDP_RET0)
                                      	```
                                      1 Reply Last reply Reply Quote 0
                                      • L
                                        LucasJG25 last edited by

                                        Text editor is now updated along with the Hack VM. VM can now take 1428 lines of code. So a much better chance of getting a game made now.

                                        1 Reply Last reply Reply Quote 7
                                        • First post
                                          Last post