Turbo Assembler Password Verification: Homework Solution

  • Thread starter Mastur
  • Start date
In summary: I'll try again in a few hours.In summary, the user is not able to enter a password that is longer than 9 characters. If the user types in an incorrect character, an "incorrect password" message will appear. Otherwise, the password will be displayed as "correct password." To input the password, the user would use the 0Ah buffered STDIN input DOS function. To compare the user's input against the stored password, the "cmp al,67" instruction can be used. If the user's input does not match the stored password, an "incorrect password" message will appear.
  • #1
Mastur
41
0

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.
 
Physics news on Phys.org
  • #2
When you enter code, you should put [ code ] and [ /code ] tags (without the extra spaces) around your code. I've done that below.
Mastur said:

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.

passwdPrompt db "Please enter your password."

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.
 
  • #3
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:
  • #4
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.
 
  • #5
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.
 
  • #6
Mastur said:
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.
Mastur said:
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.
Mastur said:
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?
Mastur said:
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.
 

1. What is Turbo Assembler and what is a common problem with it?

Turbo Assembler is a software tool used in programming to convert assembly language code into machine code. A common problem with it is that it can sometimes produce incorrect results or unexpected errors.

2. Why does Turbo Assembler sometimes produce incorrect results?

This can happen due to a variety of reasons such as coding errors, incorrect use of instructions or directives, or compatibility issues with the target system.

3. How can I troubleshoot a Turbo Assembler problem?

The first step in troubleshooting a Turbo Assembler problem is to carefully review your code for any syntax or logic errors. You can also refer to the Turbo Assembler documentation or seek help from online forums or communities.

4. What are some common errors in Turbo Assembler?

Some common errors in Turbo Assembler include syntax errors, undefined symbols, segment violations, and incorrect use of directives or registers.

5. Is there any alternative to Turbo Assembler for assembly language programming?

Yes, there are many other assemblers available such as MASM, NASM, and FASM. It is recommended to research and choose an assembler based on your specific needs and target system.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
20
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
3K
  • Programming and Computer Science
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
9K
  • Programming and Computer Science
Replies
7
Views
6K
  • Programming and Computer Science
Replies
4
Views
4K
  • Programming and Computer Science
Replies
7
Views
7K
  • Programming and Computer Science
Replies
11
Views
4K
Back
Top