0

how can I subtract 2 sign and magnitude binary numbers in assembly (ex : 11110110 and 10101011)

I used SAL then I don't know how to pick out the sign bit, when we shift to left, our signed bit is Carry Flag. then I should use JC or JS? or ...

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 1
    You can just use `test` and then `js` to see if the sign bit is set. You can use `and` to mask it out to get the magnitude. Work from there. – Jester Jan 07 '23 at 18:36
  • sorry , could you pls do it for 11110110 and 10101011 subtraction in emulator for me? – Maryam Shomali Jan 07 '23 at 19:03
  • they are both 8bit signed numbers, in sign & magnitude system. – Maryam Shomali Jan 07 '23 at 19:16
  • 1
    You hinted that you might use `JC` or `JS` — why not write out your own code? You're almost there. Of course, you may not use the "best" way but that is another matter. – Erik Eidt Jan 07 '23 at 19:42
  • What ISA are you writing this emulator on? x86? You can check if their signs are the same or different with `xor al, cl` to set SF in case that helps. (of course `mov` to save a copy of the original.) – Peter Cordes Jan 07 '23 at 23:44

0 Answers0