Quantcast

Can an instruction ever have a jump and assignment?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Can an instruction ever have a jump and assignment?

AlexKrel
Like the title says, can they both be in one instruction.

When the instruction map is show it is shown like this

dest = comp ; jmp

But this form never occurs in any of the given assembly programs.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can an instruction ever have a jump and assignment?

AlexKrel
Finished part 1 of the course!

I've been experimenting with my question now that my assembler is done.
You can definitely use destination and jump bits together.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can an instruction ever have a jump and assignment?

AlexKrel
The think the reason you don't see any destination and jump bit combinations in any of the sample codes is because there is almost no practical reason to ever use a statement like

@23
M = D ; JEQ.

Since instructions are taken from ROM and data is stored in RAM, when you use a statement like the one above, you are storing the value of D in in RAM address 23 while jumping to ROM address 23 (if the D value is 0).

A trivial program

@8
D = A
@R0
M = D; JMP

Here, we store the value 8 in D, set A to 0 and then store the value in D in RAM 0, while also jumping back to ROM 0 to start the program over again...So it's possible but it's hard to see a reason to use these kinds of statements.

Let me know if you can find a use for a statement like this.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can an instruction ever have a jump and assignment?

ivant
I think a fairly advanced optimizer could use this kind of instruction to shave off several instructions, but probably it would only account for bragging :)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can an instruction ever have a jump and assignment?

cadet1620
Administrator
In reply to this post by AlexKrel
The general pattern
        D=<something that doesn't use A or M>
    @SOMEWHERE
        0;JMP
can have the D= merged into the jump.

For example, at the bottom of a loop:
    @LOOP
        D=D-1;JGT

But as Ivan said, this is mostly just a trick to save one instruction.

You might also find this thread interesting. It's about jump instructions that change the A register.

--Mark
Loading...