15,314,449 members
1.00/5 (1 vote)
See more:
```can anyone help me fix this program or give any suggestions?
a program to calculate the volume of a sphere with the input radius (r)
I tried it but it's an error,
Eror:
when I give input, the program doesn't run
thank you```

What I have tried:

```; TO FIND VOLUME OF SPHERE
DSEG SEGMENT 'DATA'
RES DB ?
MSG DB 'VOLUME OF SPHERE IS','\$'
DSEG ENDS
CSEG SEGMENT 'CODE'
ASSUME CS:CSEG, DS:DSEG
MOV AX,DSEG
MOV DS,AX ; INITIALIZE DATA SEGMENT
MOV AH,01H
INT 21H ; INPUT THE RADIUS AND STORE IN AL
SUB AL,30H ; CONVER ASCII OF RADIUS INTO HEX
IMUL AX ; DX:AX <- AX * AX = (RAD)^3
MOV BL,58H ; 4/3 * 22/7 = 88/21= 58H/15H
IMUL BL ; AX=AX * 58H
MOV BL,15H
DIV BL ; AL <- AX/BL IS THE VOLUME OF SPHERE
MOV RES, AL ; PUT THE RESULT IN M/L 'RES'
LEA DX,MSG
MOV AH, 09H
INT 21H ; PRINT "THE AVERAGE IS"
MOV DL,RES
ADD DL,30H ; ADD 30H TO GET DISPLAY OF NUMBER AS CHAR
MOV AH, 02H ;
INT 21H ; PRINT RESULT
MOV AH,4CH
INT 21H
CSEG ENDS
END```
Posted
Updated 21-Dec-21 20:03pm
v2
jeron1 21-Dec-21 21:15pm

"it's an error", what is it? and what is the error?
Richard MacCutchan 22-Dec-21 4:25am

The answer is likely to be far more than a single digit, e.g. a sphere of radius 2 is just over 33 units in volume. So you need a loop that successively divides AX by 10, and converts the remainder to a digit. You then need to print those digits in reverse order. Since you allow input of any digit for the radius, you need to cater for a radius of 9 which gives a volume of approximately 3053.

## Solution 1

"It doesn't work" is probably the most useless problem report we get - and we get it a lot. It tells us nothing about what is happening, or when it happens.
So tell us what it is doing that you didn't expect, or not doing that you did.
Tell us what you did to get it to happen.
Tell us any error messages.

In this case, you will need to start debugging your code: Assembly Code Debugging in WinDbg - Windows drivers | Microsoft Docs[^] may help.