Solved

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

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now