simon987 / Much-Assembly-Required

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

Assembler outputs incorrect binary when subtracting a register by a label in a memory displacement operand #172

Closed Francessco121 closed 6 years ago

Francessco121 commented 6 years ago

When using a memory displacement, the operator is not taken into account when the displacement value is a label.

For example:

label:
  mov X, [X + label]
  mov Y, [Y - label]

The encoded value to be added to the registers will be the same for both mov instructions, instead of the second one being negated.

Disassembling the previous example results in the following (note, the actual address isn't really relevant):

mov X, [X + 0x000d]  ; A9 41 00 0D
mov Y, [Y + 0x000d]  ; B1 81 00 0D

The issue seems to be that this code block only gets the address of the label and doesn't check the operator. With an integer literal, handling of the operator is offloaded to Integer.decode.

simon987 commented 6 years ago

You're right, it doesn't check the sign for labels. This is quite an easy fix, one would only have to check the sign (first character of the string) and apply it to data

bobbyjudd commented 6 years ago

Is this issue still up for grabs?

simon987 commented 6 years ago

@bobbyjudd Yes. Let me know if you need assistance with the issue / project setup (Ideally in the slack channel, see README.md for the link)

Thank you!