views:

864

answers:

2

This is my first post on this site. I am taking an X86 assembly class and I am having a bit of trouble with my second project. The project is very simple. The program needs to take in a simple string from the user and display it back. I have gotten the program to take input from the user but I can't seem to store it. Here is what I have so far:

BITS 32
global _main
section .data

prompt db "Enter a string: ", 13, 10, '$'
input resd 1 ; something I can using to store the users input.

name db "Name: ******", 13, 10,'$'
StudentID db "********", 13, 10, '$'
InBoxID db "*************", 13, 10, '$'
Assignment db "************", 13, 10, '$'
version db "***************", 13, 10, '$'

section .text
_main:

mov ah, 9
mov edx, prompt
int 21h
mov ah, 08h
while:
 int 21h
            ; some code that should store the input.
 mov [input], al
 cmp al, 13
 jz endwhile
 jmp while
endwhile:

mov ah, 9
    ; displaying the input.

mov edx, name
int 21h
mov edx, StudentID
int 21h
mov edx, InBoxID
int 21h
mov edx, Assignment
int 21h
mov edx, version
int 21h
ret

I am assembling this using NASM. Thanks for the help in advance!

+1  A: 

It looks like you aren't using a proper buffer to store the users input.

This site has a large x86 tutorial split up into 23 sections, one for each day you are suppose to do that section.

Here on day 14 he shows an example of reading in a string from the user and storing it into a buffer, then printing it back out again.

Simucal
I would of answered the question outright, but I'm only familiar with MIPs assembly and x86 assembly has some distinct differences. If you follow that days tutorial you should be able to get the desired result.
Simucal
+1  A: 

You're only reading the characters without storing them. Instead of storing into that 'input', you should store AL either directly into StudentID/InBoxID/Assignment/Version. You could take advantage of their relative positions in memory and write a single loop to fill all of them, as in a contiguous space.

It could go like this:

; For each string already padded with 13, 10, $
; at the end, use the following:
mov ah, 08h
mov edi, string
mov ecx, max_chars
cld
while:
        int 21h
        stosb         ; store the character and increment edi
        cmp ecx, 1    ; have we exhausted the space?
        jz out
        dec ecx
        cmp al, 13
        jz terminate  ; pad the end
        jmp while
terminate:
        mov al, 10
        stosb
        mov al, '$'
        stosb
out:
        ; you can ret here if you wish

I didn't test, so it might have mistakes in it.

Or you could use other DOS functions, specifically INT21h/0Ah. It could be more optimal and/or easier.

Eduard - Gabriel Munteanu
I guess that would be part of my question. How would I go about storing the contents of al into a string of some sort.
Xill
Okay, added some example code.
Eduard - Gabriel Munteanu