0

Code below works, but only divides the first digit in the number and the output for remainder will always be zero. And division does not really work for example dividing 57/12 will return a quotient of 5.

.MODEL SMALL
.STACK 200
.DATA
    CRLF      DB  0DH, 0AH, '$'
    PROMPT1   DB  'Enter the first 2-digit number (10-99): ','$'
    PROMPT2   DB  'Enter the second 2-digit number (10-99): ','$'
    PROMPT3   DB  'The quotient is: ', '$'
    PROMPT4   DB  'The remainder is: ', '$'
    QUOTIENT  DB  ?             ; quotient
    REMAINDER DB  ?             ; remainder
    NUM1      DB  2 DUP (?)     ; array to store first number
    NUM2      DB  2 DUP (?)     ; array to store second number
.CODE
.STARTUP  
    MOV AX, @DATA
    MOV DS, AX
    ; Prompt user for first number
    LEA DX,PROMPT1              ;DISPLAY PROMPT1
    MOV AH,09H
    INT 21H  
    
    ; Read first number
    MOV CX, 2                   ; read two digits
    LEA DI, NUM1                ; point DI to first digit of NUM1
    MOV AH,01H
    READ1:
    INT 21H
    SUB AL,30H                  ; convert the character to number
    MOV [DI], AL                ; save digit in NUM1 array
    INC DI
    LOOP READ1
    
    LEA DX,CRLF                 ;MOVE CURSOR TO NEXT LINE
    MOV AH,09H
    INT 21H
    
    ; Prompt user for second number
    LEA DX,PROMPT2              ;DISPLAY PROMPT2
    MOV AH,09H
    INT 21H
    
    ; Read second number
    MOV CX, 2                   ; read two digits
    LEA DI, NUM2                ; point DI to first digit of NUM2
    MOV AH,01H
    READ2:
    INT 21H
    SUB AL,30H                  ; convert the character to number
    MOV [DI], AL                ; save digit in NUM2 array
    INC DI
    LOOP READ2
    
    ; Calculate quotient and remainder
    MOV AH, 0                   ; clear AH
    MOV AL, [NUM1]              ; copy first digit of NUM1 to AL
    MOV BL, [NUM2]              ; copy first digit of NUM2 to BL
    DIV BL                      ; divide AL by BL
    MOV QUOTIENT, AL            ; save quotient in QUOTIENT variable
    MOV REMAINDER, AH           ; save remainder in REMAINDER variable
    
    ; Display quotient and remainder
    LEA DX, CRLF
    MOV AH, 09H
    INT 21H
    
    LEA DX, PROMPT3 
    MOV AH, 09H
    INT 21H
    
    MOV DL, QUOTIENT
    ADD DL, 30H
    MOV AH, 02H
    INT 21H
    
    LEA DX, CRLF
    MOV AH, 09H
    INT 21H
    
    LEA DX, PROMPT4
    MOV AH, 09H
    INT 21H
    
    MOV DL, REMAINDER
    ADD DL, 30H
    MOV AH, 02H
    INT 21H
    
.EXIT
END

I've tried everything I could find but it would still be the same. The main point for this was to really make us store the value of the input in an array then divide it.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Zatania
  • 13
  • 3
  • When you single-step with a debugger, what values are in AL and BL right before `div bl`? Presumably `5` and `1` since you didn't do anything with the 2nd digit, just stored it in the array of digits without converting each of your 2-byte inputs to one 8-bit integer. And 5/1 is 5 with no remainder. – Peter Cordes May 01 '23 at 04:35

0 Answers0