Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Swapping a Int64 var (using ASM) 19 1,111
writing Bios 6 444
What are the %fs and %gs registers? 3 1,211
File Not Found Exception 12 109
Note: This is the second blog post in a series on email clearinghouses (https://www.xmatters.com/alert-management/blog-email-has-failed-us?utm_campaign=70138000000ydLoAAI&utm_source=exex&utm_medium=article&utm_content=blog-post).   Every month t…
We need a new way to communicate time sensitive or critical info.   The best part of my role at xMatters is visiting our clients all over the world to learn about how they operate their businesses, share insights that xMatters has gleaned across…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

14 Experts available now in Live!

Get 1:1 Help Now