Olexiy  Pyvovarov
Olexiy Pyvovarov

Reputation: 890

Create data when the program is running assembly

Well, The question is simple: How can I allocate space for data in code.

I try to do the following:

ReadArrayLength PROC
pusha   
    messageArrayLength db "Enter the number of the bytes in array: $"
    mov dx, OFFSET messageArrayLength
    mov ah, 09h
    int 21h
popa
ret
ENDP

But when I'm debugging the program and call this procedure, my turbo assembler get stuck. Is there any way how can I create a new data field and manipulate it?

Upvotes: 0

Views: 65

Answers (2)

user205036
user205036

Reputation:

The standard way of embedding data in the assembly code is:

some_proc proc near

  call @after_data  ; <-- store on the stack the return address

@return_address:    ; it will point exactly here

  db   'String',0   ; a string
  db   0FFh,0FEh    ; array of bytes
  dd   0ABBAh       ; DWORD

@after_data:

  pop  dx            ; pop the return address from the CALL
                     ; dx = offset @return_address
  ...    
some_proc endp

This creates offset independed code too.

Upvotes: 0

The simplest solution here seems to be jumping over the data:

ReadArrayLength PROC
  pusha   
  jmp @@1
  messageArrayLength db "Enter the number of the bytes in array: $"
@@1:
  mov dx, OFFSET messageArrayLength
  mov ah, 09h
  int 21h
  popa
  ret
ENDP

Upvotes: 2

Related Questions