Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6819591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:19:29+00:00 2026-05-26T21:19:29+00:00

I am working to take input from a user twice, and compare the input.

  • 0

I am working to take input from a user twice, and compare the input. If they are the same, the program exits. If not, it reprints the input from the first time, and waits for the user to type something. If it is the same, the same thing as before occurs. If not, the same thing as before occurs.

Input and looping is not the problem. The main problem is the result I am getting from the program. My following is what I am doing codewise:

%include "system.inc"

section .data
    greet:      db 'Hello!', 0Ah, 'Please enter a word or character:', 0Ah
    greetL:     equ $-greet     ;length of string
    inform:     db 'I will now repeat this until you type it back to me.', 0Ah
    informL:    equ $-inform
    finish:     db 'Good bye!', 0Ah
    finishL:    equ $-finish
    newline:    db 0Ah
    newlineL:   equ $-newline


section .bss

input: resb 40  ;first input buffer
check: resb 40  ;second input buffer

section .text

    global _start
_start:


greeting:
    mov eax, 4
    mov ebx, 1
    mov ecx, greet
    mov edx, greetL %include "system.inc"

    section .data
        greet:      db 'Hello!', 0Ah, 'Please enter a word or character:', 0Ah
        greetL:     equ $-greet     ;length of string
        inform:     db 'I will now repeat this until you type it back to me.', 0Ah
        informL:    equ $-inform
        finish:     db 'Good bye!', 0Ah
        finishL:    equ $-finish
        newline:    db 0Ah
        newlineL:   db $-newline


    section .bss

    input: resb 40  ;first input buffer
    check: resb 40  ;second input buffer

    section .text

        global _start
    _start:


    greeting:
        mov eax, 4
        mov ebx, 1
        mov ecx, greet
        mov edx, greetL
        sys.write

    getword:
        mov eax, 3
        mov ebx, 0
        mov ecx, input
        mov edx, 40
        sys.read

        sub eax, 1  ;remove the newline
        push eax    ;store length for later

    instruct:
        mov eax, 4
        mov ebx, 1
        mov ecx, inform
        mov edx, informL
        sys.write

        pop edx     ;pop length into edx
        mov ecx, edx    ;copy into ecx
        push ecx    ;store ecx again (needed multiple times)

        mov eax, 4
        mov ebx, 1
        mov ecx, input
        sys.write

        mov eax, 4  ;print newline
        mov ebx, 1
        mov ecx, newline
        mov edx, newlineL
        sys.write

        mov eax, 3  ;get the user's word
        mov ebx, 0
        mov ecx, check
        mov edx, 40
        sys.read

        xor eax, eax

    checker:
        mov ebx, check
        mov ecx, input
        cmp ebx, ecx    ;see if input was the same as before

        jne loop    ;if not the same go to input again
        je done     ;else go to the end
        pop edx
        mov ecx, edx
        push ecx
        mov eax, 4
        mov ebx, 1
        mov ecx, check
        sys.write   ;repeat the word

        mov eax, 4
        mov ebx, 1
        mov ecx, newline
        mov edx, newlineL
        sys.write



    loop:
        mov eax, 3  ;replace new input with old
        mov ebx, 0
        mov ecx, check
        mov edx, 40
        sys.read

        jmp checker

    done:

        mov eax, 1  
        mov ebx, 0  
        sys.exit
    sys.write

getword:
    mov eax, 3
    mov ebx, 0
    mov ecx, input
    mov edx, 40
    sys.read

My result is now: EDITED

Hello!
Please enter a word or character:
Nick
I will now repeat this until you type it back to me.
Nick
(I input) Magerko
(I get) M
(I input)Nick
(I get)
(I input)Nick
(I get)

EDITED

And this continues. My checks do not work as intended in the code above, and I eventually don’t even get the program to print anything but a newline. Is there a reason for this?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:19:30+00:00Added an answer on May 26, 2026 at 9:19 pm

    Apart from what @Joshua is pointing out, you’re not comparing your strings correctly.

    checker:
        mov ebx, check  ; Moves the *address* of check into ebx
        mov ecx, input  ; Similarly for input
        cmp ebx, ecx    ; Checks if the addresses are the same (they never are)
    

    Firstly, when you have e.g. label dd 1234 in your data segment mov eax, label will move the address of label to eax while mov eax, [label] will move the contents stored at label (in this case 1234) into eax.

    Note that in the above example I deliberately used a 32-bit variable so that it would fit neatly into eax. If you’re using byte sized variables (like ascii characters) e.g. mybyte db 0xfe you’ll either have to use byte sized register (al, ah, dh etc.) or use the move with zero/sign extend opcodes: movzx eax, byte [mybyte] will set eax to 254, while movsx eax, byte [mybyte] will set eax to -2 (0xfffffffe).

    You also need to do a character by character comparison of the strings. Assuming you save the read string length (you really should be checking for negative return values – meaning errors) in input_len and check_len it could look something like:

        mov eax, [input_len]
        cmp eax, [check_len]
        jne loop       ; Strings of different length, do loop again
        mov ebx, check
        mov ecx, input
    .checkloop:
        mov dl, [ebx]  ; Read a character from check
        cmp dl, [ecx]  ; Equal to the character from input?
        jne loop       ; Nope, jump to `loop`
        inc ebx        ; Move ebx to point at next character in check
        inc ecx        ; and ecx to next character in input
        dec eax        ; one less character to check
        jnz .checkloop ; done?
    
        ; the strings are equal if we reach this point in the code
        jmp done
    

    If you’re interested in another way of doing this in fewer instructions look up rep cmpsb.

    There are a few other problems in the code immediately following your checker code. The pop edx instruction (and the code following, down to the loop label) will not be execute as you’re always jumping either to loop or done.

    jne loop    ;if not the same go to input again
    je done     ;else go to the end
    pop edx   ; Will never be reached!
    

    The reason you’re getting funny characters is from newlineL: db $-newline This should be equ instead of db or you should replace mov edx, newlineL with movzx edx, byte [newlineL]. Since newlineL unlike the other *L names refers to a variable and not a constant equ mov edx, newlineL will use the address of the newlineL variable as the number of bytes to write, when you wanted it to be 1.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a program to simply take in a user's input twice,
I am using the following C code to take input from user until EOF
I am working on a program that is to take the input of 15,000
I'm working on a c++ program and I need to take in a binary
I am building a blackberry application takes input from user then send input to
I'm working on a small web form that requires the user to input (among
I ask for a user to input 4 numbers or letter from 1 -
I want to take person's name and their phone number from the end user
I'm working with several components that take color as a uint, but the colors
I am working with CruiseControl.Net and am trying to take the dry approach as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.