2

I have been given a small assignment to make a small program in assembly now I am trying to make a grade calculator you input your marks and it tells you the grade

.model small
.stack 100h
.data
Msg1 db 'Enter your total marks from 0 to 99: $'
EightyPlus db 'Congratulation you have got an A $'
.code
start:
Mov ax,@data
Mov ds,ax

Mov ah,09
Lea dx,Msg1
int 21h

mov ah,02
mov dl,10
int 21h


mov ah,01
int 21h

mov bl,01
int 21h

cmp al, '8'
jl exit

;; true1: ;; we don't really need this label anymore, as it is not referenced
mov ah,02
mov dl,10
int 21h

Mov ah,09
Lea dx,[EightyPlus]
int 21h
;; now continue and exit

exit:
Mov ah,4ch
int 21h

end start

Now what I want is that if al input is greater than or equal to 8 it should print grade A but as of now it prints grade A on every input need some help here

The bl is just a gimmick to get two inputs from the user you can ignore it or help me to take more than one character input from user and do the task as I have asked above

EDIT: it was working through this code but now as I have used bl it does not work again

1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56

1 Answers1

1
mov al,01
int 21h

mov bl,01
int 21h

The DOS function to read a character from standard input is int 21h with ah = 01h. See http://www.ctyme.com/intr/rb-2552.htm. You have never initialized ah. And the mov to bl in between is pointless.

It sounds like you want to read a character and use it for your comparison, then read a second character and ignore it. You could do something like:

mov ah, 01h
int 21h
mov bl, al
int 21h ; ah still contains 01, unless DOS is buggy
cmp bl, '8'
jge true1

A second bug is after jge true1. Remember how a conditional jump works: it jumps if the condition is true, and if not, execution continues with the next instruction in memory. In your program, the next instruction is ... the instruction right after the true1 label. So execution continues at true1 regardless of whether the condition was true or false.

Sometimes beginners to assembly think that labels are like functions, and code will automatically "return" when it reaches a new label, as if it were the close brace of a function. That's not true; labels just give you a human-readable way to refer to a particular address, and don't by themselves affect program flow at all.

If you want to skip the output of the EightyPlus string when the condition is false, then you need to jump over it:

cmp bl, '8'
jge true1
jmp exit

true1:
Mov ah,09
Lea dx,[EightyPlus]
int 21h
;; now continue and exit

exit:
Mov ah,4ch
int 21h

But you could do it more efficiently by reversing the test:

cmp bl, '8'
jl exit

;; true1: ;; we don't really need this label anymore, as it is not referenced
Mov ah,09
Lea dx,[EightyPlus]
int 21h
;; now continue and exit

exit:
Mov ah,4ch
int 21h
Nate Eldredge
  • 48,811
  • 6
  • 54
  • 82
  • Thank you so much for this detailed explanation but the problem has just reversed itself before it would print grade A with any input and now it does not print it with any input where it is 8,9,2,4 etc – Ghulam Mustafa Nov 11 '21 at 18:10
  • Please edit your question with your updated code, as well as the exact input that causes the problem (e.g. are you entering one digit or two?). – Nate Eldredge Nov 11 '21 at 18:11
  • please check i have edited the question – Ghulam Mustafa Nov 11 '21 at 18:20
  • @GhulamMustafa: I suggested `mov bl, al` but your program still has the incorrect `mov bl, 01`. The `int 21h / ah = 01h` call returns the character in `al`. We want to save it in `bl` because `al` will be overwritten by the following `int 21h` call. – Nate Eldredge Nov 11 '21 at 18:21
  • so what should i do i am very stuck can not you make this program and send me the code? – Ghulam Mustafa Nov 11 '21 at 18:27
  • @GhulamMustafa: **Take the line `mov bl,01` in your program and change it to `mov bl, al`.** That should be all you need to do. No, I am not going to write your assigned program for you; that would be unethical. On a similar note, when you turn in your assignment, you need to acknowledge that you got help and used code from this post. – Nate Eldredge Nov 11 '21 at 18:28
  • i did it but now it shows grade A on the second input and I want it to depend on the first – Ghulam Mustafa Nov 11 '21 at 18:31
  • I don't understand what you mean by "second input" and "first input". What is the *exact, complete* input you are giving the program that results in undesired output? – Nate Eldredge Nov 11 '21 at 18:33
  • Thank you so much :) – Ghulam Mustafa Nov 11 '21 at 18:40