Search code examples
assemblymasmirvine32

Finding the volume of a sphere in irvine assembly


I have been given an assignment in my assembly class to create a simple program to find the volume of a sphere given a users input, I have to display a message followed by the volume with a fractional amount... I have come up with the following code but unfortunately am stumped by where remainders go and as such how to call them. Anyone have an idea where I'm messing up and how I could fix it?

INCLUDE Irvine32.inc 
.data
radius byte 0
prompt byte "Please enter the radius of the sphere~ ", 0
volumeMessage byte "The volume of the sphere is~ ", 0
period byte ".", 0
volumeNumber dword 0,  0dh,0ah
volumeFraction dword 0,  0dh,0ah
piMul dword 88
piDiv dword 21

.code
main PROC
    mov edx, OFFSET prompt  
    call WriteString
    call readdec
    mov radius, al

    mul radius
    mul radius

    mul piMul

    div piDiv

    mov volumeNumber, eax
    mov volumeFraction, edx

    mov edx, OFFSET volumeMessage   
    call WriteString
    mov edx, OFFSET volumeNumber
    call WriteDec
    mov edx, OFFSET period
    call WriteString
    mov edx, OFFSET volumeFraction
    call WriteDec

    call WaitMsg            
    exit
main ENDP
END main

Solution

  • From Irvine32.asm:

    ;-----------------------------------------------------
    WriteDec PROC
    ;
    ; Writes an unsigned 32-bit decimal number to
    ; the console window. Input parameters: EAX = the
    ; number to write.
    

    So instead of:

    mov edx, OFFSET volumeNumber
    call WriteDec
    

    you should use:

    mov eax, volumeNumber
    call WriteDec
    

    And similarly for volumeFraction.