Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Newbie Question

Newbie Question

Newbie Question

I am running under Win95 on a Pentium using MASM. I have the following code:

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

  crlf         db     0Dh,0Ah,'$'

main proc
  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....

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 "$" 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,



**186,000 miles per second. . . not just a good idea, it's the LAW!

RE: Newbie Question

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],'$'

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

RE: Newbie Question


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.



**186,000 miles per second. . . not just a good idea, it's the LAW!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close