Assembly program refuses to accept a larger number [duplicate]

谁说胖子不能爱 提交于 2019-12-12 05:29:55

问题


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.



来源:https://stackoverflow.com/questions/32977190/assembly-program-refuses-to-accept-a-larger-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!