simon987 / Much-Assembly-Required

Assembly programming game
GNU General Public License v3.0
930 stars 87 forks source link

MOV [mem] [mem] does not work as expected #58

Closed kevinramharak closed 6 years ago

kevinramharak commented 6 years ago

So this piece of code does not work as expected:

main:
    MOV [display_mode], TEXT
    MOV A, text
    MOV [temp], KEY_D
    MOV [A], [temp]        ; this does not work
    MOV [A], KEY_D
    CALL display
    brk

The docs at ousob state this note:

          MOV cannot move from memory to memory or from
          a segment register to a segment register.

Yet the comments in the MovInstruction.java state:

/**
 * The MOV instruction copies data from a source to a destination.
 * it overwrites the value in the destination. The destination can be
 * memory or register, while the source can be an immediate value, memory
 * or register.
 */

I tried to follow the source code line by line, but without a debugger or log files its hard to see what exactly happens

mgiuffrida commented 6 years ago

Oh, so this wasn't intentional? It seems like in most instruction sets (like x86) mov cannot copy from mem to mem, as a design decision.

Not that there's any reason you have to simulate that limitation, just wondering.

kevinramharak commented 6 years ago

Nope check the file diff. Just a simple bug. Should work as documented in the Instruction set docs and source code commets

On 29 Dec 2017 20:03, "Michael Giuffrida" notifications@github.com wrote:

Oh, so this wasn't intentional? It seems like in most instruction sets (like x86) mov cannot copy from mem to mem, as a design decision.

Not that there's any reason you have to simulate this, just wondering.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/simon987/Much-Assembly-Required/issues/58#issuecomment-354487080, or mute the thread https://github.com/notifications/unsubscribe-auth/AONpoNoNkMLLc91GV7KkWZGmYlc8LSsHks5tFTdzgaJpZM4RPLjY .

simon987 commented 6 years ago

8086 had a more compact (but more complex) way to encode instructions but since memory is only word-addressable and we have 128Kb of memory, it makes more sense to allow it