# Turbo Assembler Problem

## Homework Statement

We were required to use our surnames as a password to our assembly program. If the user inputs incorrect character or string, an "incorrect password" message will appear. Otherwise, it will display "correct password." The problem is I do not know how to ask several inputs. I was thinking of just checking the input per character and if at a wrong character was typed, it will automatically tell that the password is not correct.

## Homework Equations

Which would be easier to understand, string parsing or per character parsing? And is it possible to run that program without TASM?

## The Attempt at a Solution

.model small
.stack 64
.data

dict db 'BEAUTIFUL'
uset DB ;this is the line that I do not know what to put
mess1 db "CORRECT PASSWORD!",'$' mess2 db "INCORRECT PASSWORD!",'$'

.code
main proc far
mov ax,@data
mov ds,ax
mov es,ax
cld
mov si,offset dict
mov di,offset uset
mov cx,09
repe cmpsb
je finish
mov dx,offset mess2
jmp show
finish: mov dx,offset mess1
show: mov ah,09h
int 21h
mov ah,4ch
int 21h
main endp
end main

I was able to grasp the previous lecture since we were only required to integrate simple arithmetic operations of assembly language in C++ program.

Mark44
Mentor
When you enter code, you should put [ code ] and [ /code ] tags (without the extra spaces) around your code. I've done that below.

## Homework Statement

We were required to use our surnames as a password to our assembly program. If the user inputs incorrect character or string, an "incorrect password" message will appear. Otherwise, it will display "correct password." The problem is I do not know how to ask several inputs. I was thinking of just checking the input per character and if at a wrong character was typed, it will automatically tell that the password is not correct.

## Homework Equations

Which would be easier to understand, string parsing or per character parsing? And is it possible to run that program without TASM?

## The Attempt at a Solution

Code:
.model small
.stack 64
.data

dict db 'BEAUTIFUL'
uset DB  ;this is the line that I do not know what to put
mess1 db "CORRECT PASSWORD!",'$' mess2 db "INCORRECT PASSWORD!",'$'

.code
main proc far
mov ax,@data
mov ds,ax
mov es,ax
cld
mov si,offset dict
mov di,offset uset
mov cx,09
repe cmpsb
je finish
mov dx,offset mess2
jmp show
finish: mov dx,offset mess1
show: mov ah,09h
int 21h
mov ah,4ch
int 21h
main endp
end main
I was able to grasp the previous lecture since we were only required to integrate simple arithmetic operations of assembly language in C++ program.

Your code needs to display a prompt to the user, something like "Please enter your password." There should be storage allocated in the data segment for this string.

To display it, you do the same as you did for mess1 and mess2.

It then needs to take input from the user. I think your intent was to store it in uset, which should be defined like this:
uset db 10 dup (?)

That will give you enough space to store 9 characters + terminating null.

To do input, you can use the 0Ah buffered STDIN input DOS function. To call it, set AH to 0Ah, and set DS:DX to the address of the buffer you're storing the string in. Before you call this DOS function, set byte 0 of the input buffer to the number of bytes you expect to read.

After calling this function, byte 1 contains the number of bytes actually read, and bytes 2 through n contain the bytes that were read from the keyboard.

To compare what the user entered as a password against the stored password, which I assume is "BEAUTIFUL", you can do this:
If the two strings have different lengths, the entered string is incorrect.
Otherwise, if the strings differ at some index, the entered string is incorrect.
Otherwise, the user entered the correct password.

For your last question, it's possible for assembly code to call an external function (written in, say, C or C++), but for what you're doing, it will probably be easier to code the whole thing in assembly.

Sorry for the late reply. I wasn't able to go online a while ago because I need to go to school as soon as possible or else I will be late. And sorry, I forgot to put it in the code blocks since I'm feel so tired when I posted that.

Anyway, I tried to understand what you are saying, unfortunately, I really cannot.

By the way, I've thought of other way to do it. Everytime a character is inputted, it will be checking if the user inputted the correct letter. Unfortunately, it still not working. It only accepts one input, afterwards, there will be an error.

Here's my code. I'm still working on it as I post this. Hopefully there'll be progress in an hour or two.

Code:
.model small
.stack 64
.data

mess1 db "Incorrect Password!",'$' mess2 db "Correct Password!",'$'

.code
main proc far
mov ax,@data
mov ds,ax
mov ah,01h

cld

int 21h
cmp al,67
jne incorrectInput

incorrectInput:mov dx,offset mess1
main endp
end main

At the meantime, I am using "go" as the password.

Unfortunately, I didn't progressed. I am still stopped at the error "Illegal Instruction".

Last edited:
Mark44
Mentor
Your latest attempt is a step backward. All you are doing is taking one character as input, and then comparing it to 'C'. If the entered character isn't 'C', execution branches to the incorrectInput label. If the entered character is 'C', execution also branches to the same label. After that, your program is done.

I'm guessing that the error you're getting is due to the statement with the label. In what you show there aren't any spaces betwee the label and its colon, and the mov instruction.

Do you understand what you need to do? Do you have an outline in the form of pseudocode for your assembly program?

Mastur said:
Anyway, I tried to understand what you are saying, unfortunately, I really cannot.
What part of what I said didn't you understand? If you quote what I put in that post and ask specific questions, I'll try to come up with different explanations.

I am trying to do one character input at a time. So if I succeeded with one character, the next characters will be easier.

I do understand what I am trying to do, but, to be honest, I really do not have anything except for this code we did last Monday night. I really do not understand everything except for those mov, cmp, etc. All the written characters after the 'mov', 'cmp', etc were alien words for me.

Although I am still trying if I can solve this problem, if things doesn't work tomorrow, I guess I have no choice but to take the last resort. I know you know what I mean.

By the way, the error I am saying is the one that pops-up after inputting a character. I have the option to Close the program or just ignore it. Both option will kill the program.

Mark44
Mentor
I am trying to do one character input at a time. So if I succeeded with one character, the next characters will be easier.
Not necessarily. If you do input on character at a time, you will need to embed that code in a loop of some kind, with logic that breaks out of the loop at the appropriate time.
I do understand what I am trying to do, but, to be honest, I really do not have anything except for this code we did last Monday night. I really do not understand everything except for those mov, cmp, etc. All the written characters after the 'mov', 'cmp', etc were alien words for me.
You need to understand the syntax of these opcodes. For example, mov works like this:
mov <dest>, <source>

mov copies the value at source address or register to destination.
Although I am still trying if I can solve this problem, if things doesn't work tomorrow, I guess I have no choice but to take the last resort. I know you know what I mean.
No, I don't know what you mean - drop the class?
By the way, the error I am saying is the one that pops-up after inputting a character. I have the option to Close the program or just ignore it. Both option will kill the program.
This is probably due to the fact that your program runs to completion after taking one character as input. As already mentioned, you need a loop if you intend to take more than one character as input.