So I'm trying to write a program that will display a grade depending on the user's input

i.e.
90-100 (A)
80-89 (B)
70-79 (C)
60-69 (D)
59 below (F)

this is what I have so far but I don't know what I'm doing wrong. :\

It assembles and it'll let you enter a number but it won't display the letter grade.

INCLUDE Irvine32.inc

.data
GradeA BYTE "A",0
GradeB BYTE "B",0
GradeC BYTE "C",0
GradeD BYTE "D",0
GradeF BYTE "F",0
grade DWORD 100 DUP(?)
msg1 BYTE "Enter a number:",0

.code
main PROC
	
	mov edx,OFFSET msg1
	call WriteString
	call ReadDec
	mov esi,grade

	.IF esi >= 90
	   jmp @G01
	.ELSEIF (esi >= 80)
	   jmp @G02
	.ELSEIF (esi >= 70)
	   jmp @G03
     .ELSEIF (esi >= 60)
	   jmp @G04
     .ELSEIF (esi <= 59)
	   jmp @G05
	.ENDIF

main ENDP

@G01 PROC
	
	mov esi,OFFSET GradeA
	call WriteString

@G01 ENDP

@G02 PROC

	mov esi,OFFSET GradeB
	call WriteString

@G02 ENDP

@G03 PROC

	mov esi,OFFSET GradeC
	call WriteString

@G03 ENDP

@G04 PROC

	mov esi,OFFSET GradeD
	call WriteString

@G04 ENDP

@G05 PROC

	mov esi,OFFSET GradeF
	call WriteString

@G05 ENDP
END main

You're jumping to rather than calling PROCs

Maybe
call @G01
jmp done


Where done is a label at the end of your if/elseif chain.

I'm sorry I don't want to make this harder for you but I don't understand what you mean, but if I understood it correctly this is what you're talking about?

.IF (esi >= 90)
   call @G01
.ELSEIF (esi >= 80)
   call @G01
.ELSEIF (esi >= 70)
   call @G01
.ELSEIF (esi >= 60)
   call @G01
.ELSEIF (esi <= 59)
   call @G01
.ENDIF

Edited 6 Years Ago by Juniahh: n/a

Do you know the difference between "jump" and "call" ?

and your code looks exactly the same, only with worse formatting.

Do you know the difference between "jump" and "call" ?

Not as much as I should I'm pretty new at this.

I decided to make it smaller to tackle it little by little and eventually get it to work right. What I don't know is if I'm 1.) Using the right jump 2.) How can I get the users input to be compared to 90 so it will give the grade 'A'.

.data
GradeA BYTE "A",0
grade DWORD 100 DUP(?)
msg1 BYTE "Enter a number:",0

.code
main PROC
	
	mov edx,OFFSET msg1
	call WriteString

	mov ebx,90
	call ReadDec

	cmp eax,ebx
	jge G01

main ENDP

G01 PROC
	
     mov esi,OFFSET GradeA
     call   writeString
     call   CRLF
     
     exit

G01 ENDP

END main

Edited 6 Years Ago by Juniahh: n/a

I'm sorry for the double post but I didn't read anything against it. If there is then I'm sorry for the inconvenience.

I figured out the issue that I had above using the debugger (which I now know how to use a bit better), the program now displays the grade according to the user's input. The problem now is I don't know how to print a certain message if the user enters anything other than numbers 0-100 (by that I mean -1 etc, 101 etc, or string values). I don't know what I have to use in order for the string to appear.

Here is the new code, I hope it isn't too big

INCLUDE Irvine32.inc

.data 
GradeA BYTE "Your grade is A",0
GradeB BYTE "Your grade is B",0
GradeC BYTE "Your grade is C",0
GradeD BYTE "Your grade is D",0
GradeF BYTE "Your grade is F",0
inPrompt BYTE "Invalid Input",0

error DWORD 0 DUP(0)
grade DWORD 100 DUP(?)
msg1 BYTE "Enter a number:",0

.code
main PROC
	
	mov edx,OFFSET msg1
	call WriteString
	mov ebx,grade
	call ReadDec
	;'For grade A
	mov ebx,90
	cmp eax,ebx
	jae G01
	;'For grade B
	mov ebx,80
	cmp eax,ebx
	jae G02
	;'For grade C
	mov ebx,70
	cmp eax,ebx
	jae G03
	;'For grade D
	mov ebx,60
	cmp eax,ebx
	jae G04
	;'For grade F
	mov ebx,59
	cmp eax,ebx
	jbe G05


	;'For error
	mov ebx,error
	cmp eax,ebx
	jne next

main ENDP

G01 PROC
	
     call   CRLF
     mov edx,OFFSET GradeA
     call   WriteString
     call   CRLF

     exit

G01 ENDP

G02 PROC

     call   CRLF
     mov edx,OFFSET GradeB
     call   WriteString
     call   CRLF

     exit

G02 ENDP

G03 PROC

     call   CRLF
     mov edx,OFFSET GradeC
     call   WriteString
     call   CRLF

     exit

G03 ENDP

G04 PROC

     call   CRLF
     mov edx,OFFSET GradeD
     call   WriteString
     call   CRLF

     exit

G04 ENDP

G05 PROC

     call   CRLF
     mov edx,OFFSET GradeF
     call   WriteString
     call   CRLF

     exit

G05 ENDP

next PROC

     call   CRLF
     mov edx,OFFSET inPrompt
     call   WriteString
     call   CRLF

     exit

next ENDP

END main

Edited 6 Years Ago by Juniahh: n/a

I figured it out, I even added an accumulation counter for however many times the you're asked for the grade. It also displays and error message if you go above 100 or below 0. Thank you Salem for the help (although very little it helped), you pretty much motivated me (believe it or not) to push through and finish this. Thanks, here's the final code.

INCLUDE Irvine32.inc

.data 
GradeA BYTE "Your grade is A",0
GradeB BYTE "Your grade is B",0
GradeC BYTE "Your grade is C",0
GradeD BYTE "Your grade is D",0
GradeF BYTE "Your grade is F",0
inPrompt BYTE "Invalid Input",0

grade DWORD 100 DUP(?)
msg1 BYTE "Enter a number:",0

.code
main PROC
	
	mov ax,0		;accumulation counter
	mov ecx,5

L1:
	inc ax

	mov edx,OFFSET msg1
	call WriteString
	mov ebx,grade
	call ReadInt

	;'Jumps to error
	mov ebx,101
	cmp eax,ebx
	jae next
	;'For grade A
	mov ebx,90
	cmp eax,ebx
	jae G01
	;'For grade B
	mov ebx,80
	cmp eax,ebx
	jae G02
	;'For grade C
	mov ebx,70
	cmp eax,ebx
	jae G03
	;'For grade D
	mov ebx,60
	cmp eax,ebx
	jae G04
	;'For grade F
	mov ebx,59
	cmp eax,ebx
	jbe G05
	;'Error for below 0
	mov ebx,0
	cmp eax,ebx
	jb next

	loop L1

main ENDP

G01 PROC
	
        call   CRLF
	mov edx,OFFSET GradeA
        call   WriteString
        call   CRLF
	jmp main

     exit

G01 ENDP

G02 PROC

	call   CRLF
	mov edx,OFFSET GradeB
        call   WriteString
        call   CRLF
 	jmp main

     exit

G02 ENDP

G03 PROC

	call   CRLF
	mov edx,OFFSET GradeC
        call   WriteString
        call   CRLF
	jmp main

     exit

G03 ENDP

G04 PROC

	call   CRLF
	mov edx,OFFSET GradeD
        call   WriteString
        call   CRLF
	jmp main

     exit

G04 ENDP

G05 PROC

	call   CRLF
	mov edx,OFFSET GradeF
        call   WriteString
        call   CRLF
	jmp main

     exit

G05 ENDP

next PROC

	call   CRLF
	mov edx,OFFSET inPrompt
        call   WriteString
        call   CRLF
	jmp main

     exit

next ENDP

END main

Edited 6 Years Ago by Juniahh: n/a

Comments
Nicely done
This question has already been answered. Start a new discussion instead.