Assembly program refuses to accept a larger number

2019-08-31 11:58发布

问题:

This question is an exact duplicate of:

  • Converting a program to accept unsigned integer 1 answer

I am trying to write a program that applies Ulam's conjecture to a number. I have the program working, however it refuses to accept the numbers 38836 and 38838. When these numbers are entered, it gives me the error: NUMBER OUT OF RANGE TRY AGAIN. The stack is at 256, and the variable used is a DW type. I am brand new to assembly and so I apologize if I did not include proper information, or am overlooking something simple, but I am very stuck. Here is what I think may be relevant to my problem.

            DOSSEG
            .MODEL  SMALL, BASIC, FARSTACK

            EXTRN   GETDEC:FAR
            EXTRN   NEWLINE:FAR
            EXTRN   PUTDEC:FAR
            EXTRN   PUTSTRNG:FAR

            .STACK  256


    .DATA
NUM           DW      ?
CNT           DW      0
PROMPT        DB      'Enter an integer: '
TOTAL         DB      'Number Total: '
FLOWMSG       DB      'OVERFLOW      '

       .CODE

ULAMS:                      
  MOV    AX,SEG DGROUP        
  MOV    ES,AX

    LEA      DI,PROMPT
    MOV      CX,18
    CALL     PUTSTRNG
    CALL     GETDEC

    MOV  NUM,AX
    MOV  CNT,0

    --->Rest of program cut for brevity<-----

回答1:

If GETDEC puts the entered value in register AX, which is a 16-bit register, then there is nothing you can do to make GETDEC accept a number that doesn't fit in a 16-bit register.

You'll have to fashion some other way of entering such large numbers; for example, reading in a string and computing the number it represents.