Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie Question 1

Status
Not open for further replies.

Simplicus

Programmer
Nov 7, 2001
3
0
0
US
I am running under Win95 on a Pentium using MASM. I have the following code:

<code>
.model small
.stack 0100h
.data
inputstring label byte
maxkeys db 80
charsinput db ?
buffer db 80,dup(0)

crlf db 0Dh,0Ah,'$'

.code
main proc
.startup
mov AH,0Ah ;get an input string
mov DX,offset inputstring ;place it in mem
int 21h

mov AH,9 ;output a
mov DX,offset crlf ;CR/LF combination
int 21h

<<<need help here>>>

mov AH,9 ;output the buffer
mov DX,offset buffer ;but....it's not terminated
int 21h

.....and so on....

</code>
The problem is that I need to stuff a '$' into buffer at the end of the string so that function 09h of int 21h will know where to terminate the string. If I enter a &quot;$&quot; at the end of the string during the 0Ah call, the program behaves well. My real problem is that I don't know how to get the contents of 'charsinput' so that I can add it to the address of buffer. So the real question is:

How do I refer to the contents of a pointer labeled in the .data segment?

Thanks for your help,

S
Simplicus

**186,000 miles per second. . . not just a good idea, it's the LAW!
 
1. pointers on the 8086-80286 MUST be loaded into si, di, bx, or bp. It can be loaded on any register with the 80386 or better. Your asm file is using an 8086 because you didn't put anything like .286 or .386 in your file.
2. to use a pointer, do this
mov ax,word ptr [si] ;load the word pointed to by the address in si
mov word ptr [di] ;and save it into the word pointed to by the address in di
3. the charinput field is not, technically, a pointer, but an offset... but hey, only a hairsplitter will debate that. Unfortunately I am a hairsplitter. So get this. It is an OFFSET. It is not a pointer.
4. offsets and pointers are indistinguishable, except that an offset is assumed to have a constant displacement:
mov byte ptr buffer[di],'$'

So now your only problem is to load charinput into di.
And hey ho! charinput is a byte and di is a WORD!

I do hope you know how to load a byte into a word...











All right here is how you do it:
mov al,charinput
xor ah,ah
mov di,ax
mov buffer[di],'$'


&quot;Information has a tendency to be free. Which means someone will always tell you something you don't want to know.&quot;
 
Thanks.

1. I realize this.

2. That's what I needed to know. I never took a course in asm. My courses were in COBOL, fortran, and PLI. Yep, I'm old. Thanks for the short course on OFFSETs.

3. I will not refer to an OFFSET as a pointer.
I will not refer to an OFFSET as a pointer.
I will not refer to an OFFSET as a pointer.
I will not refer to an OFFSET as a pointer.

4. Got it.

Seriously, Thanks. It answered my question, and pointed my brain in other directions. By the way, I'm only doing this for fun, not because I'm taking a class. I'm having to re-oil parts of my brain that haven't thought this way in twenty years or so...give me a chance, and I'll post what I can.

S- Simplicus

**186,000 miles per second. . . not just a good idea, it's the LAW!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top