Results 1 to 3 of 3

Thread: adding two numbers

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    Earth
    Posts
    277

    adding two numbers

    how to add two numbers of 2 digits each

    im using this code but it doesnt work when there is a carry on the MSB

    VB Code:
    1. .MODEL SMALL
    2. .STACK 200
    3. .DATA
    4. CRLF    DB  0DH,0AH,'$'
    5. PROMPT1 DB  'Enter the first positive integer:  ','$'
    6. PROMPT2 DB  'Enter the second positive integer:  ','$'
    7. PROMPT3 DB  'The sum of the two numbers is:  : ','$'
    8. .CODE
    9. .STARTUP
    10.     LEA DX,PROMPT1
    11.     MOV AH,09H
    12.     INT 21H
    13.  
    14.     MOV AH,01H
    15.     INT 21H
    16.     SUB AL,30H ; convert character to number
    17.     MOV CH,AL
    18.    
    19.     MOV AH,01H
    20.     INT 21H
    21.     SUB AL,30H ; convert character to number
    22.     MOV CL,AL
    23.    
    24.     LEA DX,CRLF
    25.     MOV AH,09H
    26.     INT 21H
    27.  
    28.     LEA DX,PROMPT2
    29.     MOV AH,09H 
    30.     INT 21H
    31.    
    32.     MOV AH,01H
    33.     INT 21H
    34.     SUB AL,30H ; convert character to number
    35.     MOV BH,AL
    36.    
    37.     MOV AH,01H
    38.     INT 21H
    39.     SUB AL,30H ; convert character to number
    40.     MOV BL,AL  
    41.  
    42.     ADD CL,BL
    43.     ADC CH,BH
    44.  
    45.     ADD CL,30H ; convert number to character
    46.     ;ADD CH,30H
    47.    
    48.     LEA DX,CRLF
    49.     MOV AH,09H
    50.     INT 21H
    51.  
    52.     LEA DX,PROMPT3
    53.     MOV AH,09H 
    54.     INT 21H
    55.  
    56.     MOV DL,CH
    57.     MOV AH,02H
    58.     INT 21H
    59.  
    60.     MOV DL,CL
    61.     MOV AH,02H
    62.     INT 21H
    63.    
    64. .EXIT
    65. END

    can someone help

  2. #2
    Junior Member
    Join Date
    Oct 2002
    Posts
    21
    hello

    up
    ThiS Is Me
    my email
    [email protected]

  3. #3
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    What is the exact nature of the problem?
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width