tags:

views:

168

answers:

1

hi all , i am trying to read a string from user in TASM assembly , i know i need a buffer to hold the input , max. length and actual length , but i seem to forgot how exactly we declare a buffer

my attempt was smth like this

Buffer db 80 ;max length
       db ?  ;actual length
       db 80 dup(0);i think here is my problem but can't remember the right format

Thanks in advance

+1  A: 

The DB (define byte) directive is used to allocate byte-sized blocks of memory. The section that comes after the DB specifies the value that should be placed into the allocated memory. For example, if you wanted to define a single byte of memory with the value 65, you could use the following directive.

SingleByte   DB  65        ; allocate a single byte and write 65 into the byte

The DUP (duplicate) directive is used to duplicate a series of characters. The series of characters to be duplicated are specified within the parentheses that follow DUP. The number before DUP specifies the number of times that the series of characters should be duplicated. For example, if you wanted to define a 10-byte block of memory where each byte had the value 65, you could use the following directive.

TenBytes     DB  10 DUP(65); allocate 10 bytes and write 65 into each byte

In your case, you do not care what values are stored in each byte in the buffer originally, so you can use ? as the byte that is being duplicated. If you wanted to instead initialize each byte to zero, you could replace ? with 0.

Buffer       DB  80 DUP(?) ; set aside 80 bytes without assigning them any values

The maximum length and the actual length of the buffer should be managed using separate variables. In all, you probably want something of the following nature.

Buffer       DB  80 DUP(0) ; 80-byte buffer initialized to all zeros
BufferMaxLen DB  80        ; maximum length of Buffer
BufferLen    DB  0         ; actual length of Buffer
Matthew T. Staebler