Hypotenuse of a number (Assembly Language)

; Program to compute hypotenuse of a number

DATA SEGMENT ;INITIALIZE DATA SEGMENT
NUM1 DD 4.0 ;INTIALIZE NUM1 ANY DATA.
;WHEN DATA DOUBLE IS DEFINED, DEFINE THE NUMBER WITH DECIMAL
NUM2 DD 3.0 ;INTIALIZE NUM1 ANY DATA.
;WHEN DATA DOUBLE IS DEFINED, DEFINE THE NUMBER WITH DECIMAL
RES DD ? ;INITIALIZE RES
DATA ENDS ;END OF DATA SEGMENT

CODE SEGMENT ;INITIALIZE CODE SEGMENT
START: ;START THE CODE
ASSUME CS:CODE,DS:DATA ;ASSUMPTION OF CODE AND DATA
MOV AX,DATA ;MOVE DATA INTO ACCUMULATOR AX REGISTER
MOV DS,AX ;MOVE AX INTO DATA SEGMENT REGISTER DS
FINIT ;INITIALIZE THE STACK
FLD NUM1 ;LOAD EFFECTIVE NUMBER
FMUL ST(0),ST(0) ;MULTIPLY THE TOP OF THE STACK TWICE AND STORE THE RESULT IN STACK ITSELF
;MULTUPLY A*A
FLD NUM2 ;LOAD EFFECTIVE NUMBER
FMUL ST(0),ST(0) ;MULTIPLY THE TOP OF THE STACK TWICE AND STORE THE RESULT IN STACK ITSELF
;MULTIPLY B*B
FADD ST,ST(1) ;ADD (A*A)+(B*B)
FSQRT ;PERFROM SQUAREROOT OF THE NUMBER AT THE TOP OF THE STACK
FSTP RES ;POP THE RESULT FROM TOP OF THE STACK
MOV AH,4CH ;END OF CODE
INT 21H ;END OF CODE
CODE ENDS ;END OF CODE SEGMENT
END START ;END OF START
;INPUT
; NUM1 – 4.0
; NUM2 – 3.0

;TO VIEW THE OUTPUT GO TO DUMP AND OPEN NUMERIC PROCESSOR
;AT THE START OT THE PROGRAM BEFORE TRACING THE PROGRAM USING F7

;OUTPUT
; RES – 5.0

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s