?
Solved

How to Echo keyboard input, store to array, and print array

Posted on 2006-11-30
4
Medium Priority
?
2,115 Views
Last Modified: 2012-06-27
Hi everyone, I was hoping someone can help with an assignment from my assembly class, I'll be asking the instructor on friday but was hoping to get an answer sooner.

As the subject says, I need a chunk of code that will echo keyboard input to the screen while storing it to an array, and then being able to re-print what is stored. The actual assignment is to print it out in reverseorder but I am just trying to figure out how to get it stored in the array and then print its contents before I worry about reversing it.

So, I think I am fairly close I am just having trouble printing it, maybe I am not storing it properly? This is what I have:

declared in dseg: InitialString       DB      100 DUP(?)

My main code:

mov si, 0
ReadString:
MOV AH, 01
INT 21H
MOV bx, OFFSET InitialString
MOV [bx+si], al       ;store string
inc si
CMP al,0DH            ;check for carriage return
JE EXIT
jmp ReadString


EXIT:

mov si, 0
mov cx, 100
PrintString:
MOV ah, 02

MOV bx, OFFSET InitialString
mov dl, [bx+si]
int 21h
inc si
dec cx
loop PrintString



Please advise on where I am going wrong
0
Comment
Question by:Mooligan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 11

Accepted Solution

by:
dimitry earned 500 total points
ID: 18051681
mov si, 0
mov cx, 100
PrintString:
MOV ah, 02

MOV bx, OFFSET InitialString
mov dl, [bx+si]
int 21h
inc si
;;;;;;;;dec cx  <- this is part of loop operator
loop PrintString
0
 
LVL 2

Expert Comment

by:MarkRR
ID: 18067373
See if this helps.

declared in dseg: InitialString      DB     100 DUP(?)

My main code:

;-- Locate data segment I was using MASM directive .Data
mov ax, @data
mov ds, ax

mov si, 0
ReadString:
MOV bx, OFFSET InitialString
MOV [bx+si], al      ;store string

;-- move Int 21h call
MOV AH, 01
INT 21H

inc si
CMP al,0DH          ;check for carriage return
JE EXIT
jmp ReadString


EXIT:

mov si, 1
mov cx, 63h
PrintString:
MOV ah, 02

MOV bx, OFFSET InitialString
mov dl, [bx+si]
int 21h
inc si
;-- dec cx  not needed.
loop PrintString

MarkRR
0
 

Author Comment

by:Mooligan
ID: 18197288
My apologies I thought I closed this. Dimitry's suggestion was right on, it led me to my solution.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Learn how to use the free Acronis True Image app to easily transfer data between iPhones and Android phones.
Check out the latest tech news, community articles, and expert highlights in August's newsletter.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question