Solved

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

Posted on 2006-11-30
4
2,114 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 125 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

The conference as a whole was very interesting, although if one has to make a choice between this one and some others, you may want to check out the others.  This conference is aimed mainly at government agencies.  So it addresses the various compli…
Resolving an irritating Remote Desktop connection that stops your saved credentials from being used.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

691 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