assemblyx86nasmdata-segment

How can I read data from data segment using x86 assembly?


Im using nasm32, x86 assembly language. I want to read some number from data segment.

.model small 
.stack
.data 
  DATA1 DB 53H,"$"
  DATA2 DB 17H,"$"
.code
.startup
  mov dx, @data
  mov dx, offset DATA1
  add dl,30h
  mov ah, 02h
  int 21h

  mov dl, dh
  add dl, 30h
  mov ah, 02h
  int 12h
  .exit
end

This code return just

20

I supposed DATA1 53h (= 83 (decimal)) value will return. (in ascii character)

But strange number is return. what happened? I don't understand this result.

And how can I fix this code?


Solution

  • You're not setting up ds.

    mov dx, @data
    

    Did you mean something like:

    push @data
    pop ds