Hi everyone! I'm new here and I'm very new at this language so here it goes:

I am writing a little program that converts a decimal input to a 16 bit binary number, and it will keep asking for input until the user types in zero. I have already written a good portion of this, but I am not sure how to handle the case if the input is a negative number and I am also not sure how to output it in 16 bits...I think it has something to do with shifting??? If anyone could help it would be greatly appreciated. Thanks in advance....I am using PEP/8 to do this as well:

begin:  stro prompt, d
        deci num, d
  lda num, d
sta num, d
getBin: lda num, d       
cpa 0, i       
breq stop
anda 1, i
sta bin, d
deco bin, d
lda num, d
sta num, d
lda num, d
cpa 0, i
br getBin
stop: STOP
bin: .block 2
num: .block 2
num2:.block 2
prompt: .ascii " Please enter a decimal number:\x00"
Posted on 2009-03-08 13:27:30 by guitarlady3000
I am not familiar with the instructionset you are using here, so I cannot give any comments on the code itself.
I can explain how a negative number is handled though:
You check if the first character is a '-', and remember this for later.
Then you parse the rest of the characters as if it was a positive number.
When you're done parsing, you now negate the parsed number (two's complement). This can be done either by using a 'neg' instruction, or by subtracting from 0.

So in pseudocode:
if (firstchar == '-')
  negative = true;

x = Parse(input);

if (negative)
  x = -x;
Posted on 2009-03-10 07:06:28 by Scali