1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Turbo Assembler Problem

  1. Jul 3, 2012 #1
    1. The problem statement, all variables and given/known data
    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.
    2. Relevant equations
    Which would be easier to understand, string parsing or per character parsing? And is it possible to run that program without TASM?
    3. 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.
     
  2. jcsd
  3. Jul 3, 2012 #2

    Mark44

    Staff: Mentor

    When you enter code, you should put [ code ] and [ /code ] tags (without the extra spaces) around your code. I've done that below.
    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.
     
  4. Jul 4, 2012 #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 (Text):
    .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: Jul 4, 2012
  5. Jul 5, 2012 #4

    Mark44

    Staff: 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?

    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.
     
  6. Jul 8, 2012 #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.
     
  7. Jul 11, 2012 #6

    Mark44

    Staff: Mentor

    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.
    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.
    No, I don't know what you mean - drop the class?
    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Turbo Assembler Problem
  1. TASM/turbo assambly (Replies: 2)

  2. Assembly Language (Replies: 13)

Loading...