1

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?

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
Flask_KR
  • 269
  • 1
  • 6
  • 14

1 Answers1

1

You're not setting up ds.

mov dx, @data

Did you mean something like:

push @data
pop ds
Jens Björnhager
  • 5,632
  • 3
  • 27
  • 47
  • `int21h, AH = 02h` takes the character to output in dl, you're initializing dx to the address of DATA1, not the data on that address. Thirdly, 53h is `'S'`, why do you expect it to print `'20'`? – Jens Björnhager Nov 29 '12 at 04:33
  • Thank you for your answer! so, how can I read data on address of DATA1? and, 'MOV DX, offset DATA1' means DX <- DATA1's address? oh, 53h is 'S' but, I mean number(in decimal, 83). I want to print number of DATA1 like '83'. so, I added 30h to make ascii code. – Flask_KR Nov 29 '12 at 04:45
  • Try mov dl, [DATA1]. There is no single digit '83', so if you need to output a number larger than 10, you need an `int2string` routine. – Jens Björnhager Nov 29 '12 at 04:52
  • Surely you don't mean `int 12h`! ... and this looks like Masm/Tasm/Jwasm - definitely not Nasm. ... but try `mov ax, @data` ` mov ds, ax` to set up your data segment... – Frank Kotler Nov 29 '12 at 06:14
  • Wow! thank you for all!! and YES! 'int 12h' is miss typed.. 'int 21h' is correct. sorry for confuse; – Flask_KR Nov 29 '12 at 06:56