(13 Points) One way to calculate the harmonic mean of two numbers x and y is usi
ID: 3920301 • Letter: #
Question
(13 Points) One way to calculate the harmonic mean of two numbers x and y is using the expression 3. 2xy Complete the following windows32 program to input two numbers and calculate and display their harmonic mean in dddd.dd format. The boxed areas indicate where code is missing. ; student' s name here ; program to input two numbers, i then calculate and display their harmonic mearn ; current date here 586 . MODEL FLAT INCLUDE ?o.h : header file for input/output STACK 4096 DATA DWORD 2 DWORD 2 prompt1 BYTE "First number", o prompt2 BYTE "second number", o inArea BYTE 20 DUP (2) mean BYTE11 DUP (?), 0 meanLbl BYTE "Harmonic mean" meanout BYTE 4 DUP (?),,2 DUP (2),Explanation / Answer
as per requirement blank spaces contain required code (in bold)
and comments in program specify explanation for used instructions.
Code here
;-----------------------------------------------------------------------
.586
.MODEL FLAT
INCLUDE io.h
.STACK 4096
.DATA
x DWORD ?
y DWORD ?
prompt1 BYTE "First number", 0
prompt2 BYTE "Second number", 0
inArea BYTE 20 DUP (?)
mean BYTE 11 DUP (?), 0
meanLbl BYTE "Harmonic Mean", 0
meanOut BYTE 4 DUP(?), '.', 2 DUP (?), 0
.CODE
_MainProc Proc
input prompt1, inArea, 20
atod inArea
mov x,eax
;repeat for second number
input prompt2, inArea, 20
atod inArea
mov y,eax
;calculate 100*(harmonic mean) in EAX
mov eax,x ;here mult(x*y) result in eax
mov edx, y
mul edx
mov ebx,2 ;here mult(2*(above result)) result in eax
mul eax
mov x,eb ;here addition(x+y) result in ebx destination register
add ebx,y
fdiv ebx ; here divison where divisor in ebx and divident in eax result in eax
mov eax,100 ; here 100*(harmonic mean) and result in eax
fmul eax
mov mean,eax
dtoa mean, eax ; convert to ASCII char
;copy digits, one at a time to meanOut
fld mean ;load floating-point value
mov cx, 2
mov si,6
fstp ax ;store floating-point value and pop
loop1:
mov meanOut[si], ax
dec cx
jnz loop1
mov si,4
mov cx,4
loop2:
mov meanOut[si],ax
dec cx
jnz loop2
;output label and mean
mov dl, meanLbl
mov ah, 02
int 21h
mov cx, 7
l1:
lea si, meanOut
mov bl, meanOut[si]
mov dl, bl
mov ah, 2
int 21h
inc si
loop l1
mov eax,0
ret
_MainProc ENDP
END
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.