0 Replies - 532 Views - Last Post: 29 December 2018 - 09:27 PM

#1 starter2018   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 29-December 18

A problem with assembly x86 code I wrote

Posted 29 December 2018 - 09:27 PM

Hello,

The program assembles and executes but do not returns the correct answer. I needed to write the code y= (x+7.3)/9y

where x is an integer and y is a real number. See my code below. All suggestions and help are welcome

INCLUDE Irvine32.inc
INCLUDE floatio.inc

HANDLE TEXTEQU <DWORD> 
GetProcessHeap PROTO 
HeapAlloc PROTO, hHeap:HANDLE,dwFlags:DWORD,dwBytes:DWORD 
HeapFree PROTO, hHeap:HANDLE,dwFlags:DWORD,lpMem:DWORD

MFALLOC MACRO size 
push ebx 
mov ebx, size 
imul ebx, 8
push ebx 
call Alloc 
pop ebx 
ENDM 
.data

c1 REAL4 7.3	
c2 REAL4 9.0
display BYTE "Value is: ", 0
x BYTE "Please,enter a number for x: ", 0
y BYTE "Please,enter a number for y: ", 0

.code

Alloc PROC 
push ebp 
mov ebp, esp
invoke GetProcessHeap 
cmp eax, 0 
je fini 
invoke HeapAlloc, eax, 8, [ebp+8]
fini: 
pop ebp 
ret 4 
Alloc ENDP

Free PROC 
push ebp 
mov ebp, esp
invoke GetProcessHeap
cmp eax, 0
je fini 
invoke HeapFree, eax, 8, [ebp+8]
fini: 
pop ebp 
ret 4 
Free ENDP 

ReadFP PROC 
push ebp ; The Housekeeping 
mov ebp, esp
push edx ; To protect edx 

finit ; To Initialize FPU 

mfalloc 1 ; Allocate 1 floating point in memory 
cmp eax, 0 ; If the allocation fails
je fini ; This jump to fini and return null 
; If the allocation succeeds 
mov edx, [ebp + 8]
call writestring
call ReadFloat ; To read floating point number 
fst QWORD PTR [eax] ; Save the number to the allocated memory
Fini: 
pop edx ; To restore edx 
pop ebp ; The housekeeping 
ret 4 
ReadFP ENDP 

WriteFP PROC 
push ebp 
mov ebp, esp 
push eax
; To initialize FPU 
mov eax, [ebp+12]
FLD DWORD PTR[eax]
call showfpustack

FLD c1
;call showfpustack	

FADD

;call showfpustack	

FLD c2
;call showfpustack	

mov eax, [ebp+8]
FLD DWORD PTR[eax ]

call showfpustack	
FMUL
;call showfpustack	
call crlf
FDIV
call writefloat
pop eax
pop ebp
ret 8
WriteFP ENDP 


main PROC 
finit
push OFFSET x 
call ReadFP 
mov ebx, eax

push OFFSET y 
call ReadFP 
mov ecx, eax
mov edx, offset display
call writestring
push ebx
push ecx
call WriteFP	
exit

main ENDP
END main
:code:

This post has been edited by modi123_1: 29 December 2018 - 09:31 PM
Reason for edit:: In the future please use the [code] tag button in the editor


Is This A Good Question/Topic? 0
  • +

Page 1 of 1