perkeyone
something clever
- Reaction score
- 71
x86 assembly i mean
ive tried several things, but was unable to get this program to display the average correctly but failed
the program uses some sort of c++ framework that my professor provided for us.
http://frank.mtsu.edu/~rdetmer/CSCI3160/windows32.zip
the only file from the project that i edited is "example.asm"
heres my code
oh and my teacher requires comments on every line, which i guess saves me the time of trying to explain what is going on to you guys
the output i am trying to achieve will look like this...
"X is the sum
Y is the average"
but for some reason i am only getting this
"X is the sum
is the average"
ive tried several things, but was unable to get this program to display the average correctly but failed
the program uses some sort of c++ framework that my professor provided for us.
http://frank.mtsu.edu/~rdetmer/CSCI3160/windows32.zip
the only file from the project that i edited is "example.asm"
heres my code
oh and my teacher requires comments on every line, which i guess saves me the time of trying to explain what is going on to you guys
Code:
;Program prompts for 4 grades and a final exam grade, then displays the sum and average.
;Calvin Perkey
;10/7/09
.586
.MODEL FLAT
INCLUDE io.h
.STACK 4096
.DATA
prompt1 BYTE "Grade 1?",0
prompt2 BYTE "Grade 2?",0
prompt3 BYTE "Grade 3?",0
prompt4 BYTE "Grade 4?",0
prompt5 BYTE "Final?",0
stravg BYTE 11 DUP (?)
strsum BYTE 11 DUP (?)
sumtext BYTE " is the sum", 13, 10
avgtext BYTE " is the average",0
lable1 BYTE "For these grades:",0
sum DWORD ?
n100 DWORD 100
n6 WORD 6
.CODE
_MainProc PROC
input prompt1, strsum, 40 ;input grade 1
atod strsum ;convert to integer
mov sum, eax ;copy grade 1 to sum
input prompt2, strsum, 40 ;input grade 2
atod strsum ;convert to integer
add sum, eax ;add grade 2 to sum
input prompt3, strsum, 40 ;input grade 3
atod strsum ;convert to integer
add sum, eax ;add grade 3 to sum
input prompt4, strsum, 40 ;input grade 4
atod strsum ;convert to integer
add sum, eax ;add grade 4 to sum
input prompt5, strsum, 40 ;input grade 5
atod strsum ;convert to integer
add sum, eax ;add final grade to sum
add sum, eax ;add final grade to sum again
dtoa strsum, sum ;convert to ascii
mov eax, sum ;copy sum to eax
mul n100 ;multiply the sum by 100 to get 1 decimal place of accuracy
cdq ;prepare for division
div n6 ;divide by 6 to get the average
add eax, 5 ;add 5 so that it will round up
dtoa stravg, eax ;convert to ascii
mov bl, stravg[9] ;copy the tenths place
mov stravg[10], bl ;overwrite the hundredths place with teh tenths place
mov stravg[9], 2eh ;overwrite the tenths place with a decimal
output lable1, strsum[8], strsum[9], strsum[10], sumtext, stravg[6], stravg[7], stravg[8], stravg[9], stravg[10], avgtext ;output results
;This is so frusterating, I can't get it to display the average even though I can see the value in memory!
;I can get it to display by itself but not in the same box with the other strings... I don't get it.
;Does it have something to do with the line feed character?
ret
_MainProc ENDP
END ; end of source code
the output i am trying to achieve will look like this...
"X is the sum
Y is the average"
but for some reason i am only getting this
"X is the sum
is the average"