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
Solved

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

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
Binary bomb phase 3 10 2,060
Where/When does Bit endianness matters? 7 532
core dump analysis 26 2,623
Convert dialog units to pixels 5 110
If you are looking at this article, you have most likely been hit by some version of ransomware and are trying to find out if there is anything you can do, or what way you should react - READ ON!
Starting your own business is always a daunting process, and for most people it is brand new experience. Avoid the common pitfalls by following these tips to start on the road to success.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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