Search code examples
assemblycorewarsredcode

Why isn't this RedCode MOV working?


So, I'm in assembly class, and to keep things interesting, we have tournaments bi-weekly with Core Wars. I'm trying to make a simple application that copies an IMP further down in memory, then jumps back and has two IMPs going at the same time. The idea is once I get this part working to put it into a tight loop and make more than two.

Here's my code:

JMP START        ; Jump to the starting point

ADDR DAT #1, #0  ; Remember the last address we dropped at
MOVE MOV 0, 1    ; The imp to be copied

START            ; Starting point
ADD #-1, ADDR    ; Take 1 off the address
ADD #80, ADDR    ; Move 80 forward
ADD #1, ADDR     ; Make that 81

MOV MOVE, ADDR   ; Move the imp to the ADDR
SPL ADDR         ; Split a new processes at the ADDR

JMP MOVE

However, what's happening is the first MOV/SPL doesn't work, and so only the first IMP is running. Where am I going wrong in this logic? It works if I remove ADDR and just use a magic number.

Here's a screen snippet of the memory before it starts running.

Screen Snippet of Memory

Thanks.


Solution

  • change:

    MOV MOVE, ADDR   ; Move the imp to the ADDR
    SPL ADDR         ; Split a new processes at the ADDR
    

    to:

    MOV MOVE, @ADDR   ; Move the imp to the ADDR
    SPL @ADDR         ; Split a new processes at the ADDR
    

    And change JMP MOVE to JMP START if you want the loop to work.

    Plus you should change the first line to ORG START instead of JMP START


    I think i misunderstood part of you question, it looks like you're only trying to create two imp processes whereas i said to make a loop, you have only 2 imps running if you make it something like this:

    org start
    
    addr dat #0, #1
    
    start
        add #80, addr
        mov imp, @addr
        spl @addr
    
    imp mov $0, $1
    

    But it doesn't jump back to the start and overwrite the original instructions.