Ok So I have to do one thing basically...and thats calculate the gpa using the information from a structure. Now as you know the gpa is calculated by multiplying the gradepoints(A = 4, B = 3, C = 2, D = 1, F = 0) by the number of hours and adding them all together, then dividing the number by the total number of credit hours. In this case I'm just assigning 3 credit hours to each class so the gpa for my data would be calculated as (4*3) + (3*3) + (1*3) + (2*3) + (4*3) = 42. Then divide that by 15(3 hours * 5 classes) and that should be 2.8. Well I got the multiplication part down. Now I'm stuck on how to display the gpa in decimal format. Can somebody help me out thanks
INCLUDE Irvine32.inc
student struct
studentId WORD ?
studentName BYTE 30 DUP("00000000000000000000000000000")
studentGrades DWORD 4,3,1,2,4
studentGPA REAL4 0.0000000
student ends
.data
gpa student <>
val1 DWORD 3
val2 DWORD 15
.code
main PROC
mov esi,OFFSET [gpa.studentGrades - 4]
mov ecx, 5
mov ebx,0
step:
add esi, 4
mov eax,[esi]
mul val1
add ebx,eax
loop step
mov eax,ebx
;call WriteInt
div val2
call WriteInt
exit
main ENDP
END main
well - it isn't an INT - it is a float
but - the DIV instruction won't cut it, either
there are a few ways to do it
you could load the integer into the FPU and use floating point math
Kip's library has a WriteFloat function
another way would be to calculate the value times, say, 100
then insert a decimal point into the resulting string before display
or - split it into 2 INT's and put a decimal point between the strings
Hi,
As Dave says using a library function to display a floating
point number is probably the easiest way to do it. Multiplying
by a hundred and displaying a scaled fraction is also a good way
to go and you will probably learn a bit more.
You can also try fixed point arithmetic, though that may take
a fair bit of effort. This is what you asked for, though in the short
run, probably not what you need. I wrote a little program to help
me visualize how a decimal number can be represented as a binary
number. If you search the forum for "Fixed Point to Decimal
calculator." you will find the thread where I posted an early version
of my program.
Cheers,
Steve
So I should load 42 into the FPU and then try to divide it by 15?
well - a grade for an individual course may be a float, say, 3.5
one way to deal with that would to be to multiply all the grades by 100, for example
then, that 3.5 would become 350
when you are all done calculating the result:
divide it by 100
PUSH the remainder on the stack
display the quotient
display a decimal point
POP the remainder from the stack
display the remainder (which will be 0 to 99)
it will appear as though you handled a float - lol
it is not that difficult to learn the FPU, either
this is especially true for simple add-multiply-divide stuff
Ray's tutorial may be found in the masm32\tutorial\fputute folder
although, i think the one on his website is updated a little
as an exorcise, i would recommend trying it both ways :U