Calculating an expression in assembly code

Viewed 103

I have written an assembly code for calculating area mentioned in the following formula
enter image description here

I feel I have overcomplicated the code. Need suggestions if the same could be done in a simpler way. I am calculating sqrt of 5 than mul by 2. Each thing is done in a separate line.
Is there a way to do it one line or shorter way

INCLUDE Irvine32.inc


.data
testString BYTE "test",0

invalidValueString BYTE "invalid value entered for length of edge!",0
enterEdgeLength BYTE "Enter the length of the edge e : ",0
areaString BYTE "Area : ",0
volumeString BYTE "Volume : ",0
radiusString  BYTE "Midsphere Radius : ",0
edgeLength real4 ?
five real4 5.0
four real4 4.0
two real4 2.0
six real4 6.0
three real4 3.0
fortySeven real4 47.0
ninetyNine  real4 99.0
twelve real4 12.0


.code

call crlf

start:
mov edx, offset enterEdgeLength
call writestring
call readfloat            ; reads the edge length into ST(0)
fstp edgeLength           ; edgeLength variable will contain the length entered
cmp edgeLength, 0         ; comparing with 0 
jl negativeValue          ; if it's less than 0 print error msg and loop to start
cmp edgeLength, 0
je stop                   ; if length entered is 0 exit the program
jmp properValue

negativeValue: 
     mov edx, offset invalidValueString   
     call writestring
     call crlf
     jmp start
properValue:                   ; call each method one by one to calculate
    call area                  ; area, volume and radius
    call volume 
    call radius
    call crlf
    fstp ST(0)                 ; clear the stack before looping again
    jmp start
    stop:
    exit

area proc
finit                     
fld five                ; calculating the constant that is to be multiplied
fsqrt                   ; with edgelength squared
fmul two
fld five
fadd
fsqrt
fmul six
fld three
fsqrt
fadd
fmul five
                        ; the constant expression is in ST(0)
fmul edgeLength              
fmul edgeLength         ; multiply the edgelength squared to ST(0) to get area

call crlf
mov edx, offset areaString
call writestring
call writefloat
fstp ST(0)
area endp
0 Answers
Related