0
BR main
sum: .WORD 0
num1: .BLOCK 1
num2: .BLOCK 1
num3: .BLOCK 1

main: LDWA sum,d 
DECI num1,d
ADDA num1,d

DECI num2,d
ADDA num2,d

DECI num3,d
ADDA num3,d

STWA sum,d 
DECO sum,d
STOP
.END

This is a machine language program written to add 3 integers in pep/9 and it is working fine.

I want to add a negative number ex: -3 to the two numbers without using subtraction.

But the conditions are :

  • Store the -3 in hexadecimal.
  • Do not use the subtract,negate,or invert instruction

EXPECTED INPUT : 2, 4, -3;
EXPECTED OUTPUT: 3

How can I do this?

PeeKay
  • 167
  • 2
  • 2
  • 10
  • 1
    *Store the -3 in hexadecimal.* It's not clear what that even means. Hex is a text serialization format for numbers. So you'd need an ASCII `'-'` and an ASCII `'3'`. But perhaps that's a sloppy way of telling you to write the fixed-width 2's complement representation of the number `-3` in your source code, i.e. `2^16 - 3` = `65533` = `0xfffd`. – Peter Cordes May 06 '20 at 14:37
  • That program is not working fine, DECI stores words but the numbers are declared as single bytes. Check out the original here: https://faculty.tarleton.edu/agapie/documents/cosc1302/Chapter06_after_midterm.pdf – Erik Eidt May 06 '20 at 15:11

0 Answers0