Simple program problem

I've written a program that prints a number on the screen.It uses two loops.The first one inverts the numbers digits and the second prints the inverted number's digits.It works fine with positive nums but when I use X as negative number the result is 65536-X.Can somebody find out what am I doing wrong?Thanks a lot.

LOADA X
RPEAT DIVD #10
STOREA X
STOREB TEMP1
LOADA TEMP2
MULA #10
ADDA TEMP1
STOREA TEMP2
LOADB #0
STOREB
LOADA X
SUBA #45
BEQA NEG
ADDA #45
BGTA RPEAT
LOADA TEMP2
LOOP DIVD #10
STOREA TEMP2
STOREB TEMP1
LOADA TEMP1
ADDA #48
OUTA 1
LOADB #0
STOREB
LOADA TEMP2
BGTA LOOP
JMP TELOS
NEG LOADA #45
OUTA 1
LOADA TEMP2
JMP LOOP
TELOS SVC 0
X DC 12345
TEMP1 DS 1
TEMP2 DS 1
TEMP3 DS 1
END

Comments

  • You're in the wrong group. This doesn't look like x86 asm.

    : I've written a program that prints a number on the screen.It uses two loops.The first one inverts the numbers digits and the second prints the inverted number's digits.It works fine with positive nums but when I use X as negative number the result is 65536-X.Can somebody find out what am I doing wrong?Thanks a lot.
    :
    : LOADA X
    : RPEAT DIVD #10
    : STOREA X
    : STOREB TEMP1
    : LOADA TEMP2
    : MULA #10
    : ADDA TEMP1
    : STOREA TEMP2
    : LOADB #0
    : STOREB
    : LOADA X
    : SUBA #45
    : BEQA NEG
    : ADDA #45
    : BGTA RPEAT
    : LOADA TEMP2
    : LOOP DIVD #10
    : STOREA TEMP2
    : STOREB TEMP1
    : LOADA TEMP1
    : ADDA #48
    : OUTA 1
    : LOADB #0
    : STOREB
    : LOADA TEMP2
    : BGTA LOOP
    : JMP TELOS
    : NEG LOADA #45
    : OUTA 1
    : LOADA TEMP2
    : JMP LOOP
    : TELOS SVC 0
    : X DC 12345
    : TEMP1 DS 1
    : TEMP2 DS 1
    : TEMP3 DS 1
    : END
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion