Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3357160
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:36:01+00:00 2026-05-18T02:36:01+00:00

I have a (seemingly) simple question to read in a string and print it

  • 0

I have a (seemingly) simple question to read in a string and print it out again using x86 interrupt based assembly. The problem i’m having is accessing the string that has been read in properly. The variable – input db 20, 0, " " is my initial string. After I call the input interrupt, the 0 should now hold the length of the string, which I need to store and pass to cx when I call the print interrupt. 20 is the max length of input. I end up with two problems – how do I access the length of the string (I’ve using an arbitrary number, which either chops it short or prints garbage after the end) and how do I access the string without the number bit at the start? Any help appreciated, my attempt is:

(I use tasm & Tlink under win 7 32 bit, and also under dos box emulation)

;7. Read in a String of characters and Print the string back out.


.model small
.stack 100h
.data


    colour db 00001111b
    input db 20, 0, "                    "
    strlen dw 20; this should be ?


.code

main:

    call initsegs
    call readstring
    call printstring
    call exit



PROC printstring 

    push ax bx cx dx bp

    mov ah, 13h ; int 13h of 10h, print a string
    mov al, 1 ; write mode: colour on bl    
    mov bh, 0 ; video page zero
    mov bl, colour; colour attribute
    mov cx, strlen; getting this is the problem
    mov dh, 10; row
    mov dl, 10; column
    mov bp, offset input ; es:bp needs to point at string..this points to string but includes its max and length at the start

    int 10h;


    pop bp dx cx bx ax 

    ret

ENDP printstring






PROC readstring 

    push ax dx


    mov ah, 0ah ; function a of 21h - read a string
    mov dx, offset input ; reads string into DS:DX so DX needs be offset of string variable

    int 21h ; call the interrupt
    ;mov strlen ....something
    pop dx ax

    ret

ENDP readstring



PROC exit

    mov ah, 4ch
    INT 21h

    RET

ENDP Exit


PROC initsegs

    push ax

    mov ax, @DATA
    mov ds, ax
    mov es, ax

    pop ax

    RET

ENDP initsegs



end main
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T02:36:01+00:00Added an answer on May 18, 2026 at 2:36 am

    What you have here is known as Pascal String. The original version (used in 16bit Pascal language) used first byte to hold the length of the string, and the rest of bytes contaned the actual string (not zero terminated). This gives maximum length of 255 bytes.

    The version uses 32bit Delphi used slighly different approach:

    struct {
      DWORD allocated_size;
      DWORD used_size;
      char* buff;
    };
    

    It’s similar to your case, but you use BYTE for size instead of DWORD.
    The standard way to work with them is to keep the pointer to the actual character string, and to use negative offsets for special fields, like in:

    lea ax, [input + 2]  //; standard string, could need a trailing '\0'
    mov al, BYTE PTR [input+2 - 1] //; strlen
    mov al, BYTE PTR [input+2 - 2] //; allocated buff size
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a seemingly simple problem though i am unable to get my head
I have a seemingly simple question, but can't find the answer. I have a
I have a seemingly simple requirement, but i can't figure out how to write
So, this is a seemingly simple question, but I'm apparently very very dull. I
I searched and searched for an answer for this seemingly simple question in Commerce
i'm stuck with a seemingly simple problem in mathematics: i need to rotate points
I have no idea. This causes seemingly random time-outs. These in turn break the
Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have a n-tire web application and search often times out after 30 secs. How

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.