0

I'm using TASM, TLINK and TD (debugger) in DOSBox.

I've recently tried programming a simple ASM 8086 program that is suppose to print the value at address 0100h. When I print the result I get output that resembles:

enter image description here

My code is:

.MODEL SMALL
.STACK
.DATA
.CODE
.STARTUP

MOV SI,0100H
MOV WORD PTR[SI],31
MOV DX,0
MOV AH,09H
MOV DX,[SI]
INT 21H

MOV AH,4CH
INT 21H

END
Michael Petch
  • 43,801
  • 8
  • 98
  • 174
Danielix
  • 5
  • 6
  • And i'm using also DOSBOX – Danielix Apr 21 '16 at 20:39
  • 3
    What do you expect it to print? – Leandros Apr 21 '16 at 20:40
  • 31 that i've moved before in dx, but it print msdos error --symbols-- write failed, disk full? but my disk isn't full – Danielix Apr 21 '16 at 20:45
  • thanks but i MUST print a value of a memory adress example: 0100h – Danielix Apr 21 '16 at 20:48
  • Then set `DX` to that value. – Leandros Apr 21 '16 at 20:49
  • for that i moved that value in DX – Danielix Apr 21 '16 at 20:49
  • What do you expect to be at address `0100H`? – Leandros Apr 21 '16 at 20:50
  • i'm expecting to find 31 and next i'm expecting that in dx theres 31 and with the TURBODEBUGGER i've checked that in the DX reg theres 31 but when i print it, no results. – Danielix Apr 21 '16 at 20:52
  • As said in my answer, it'll print the `$` terminated **string** at the address of `DX`. 31 corresponds to some unprintable value (in ASCII) and since it's not terminated it'll print whatever it finds after that address until it encounters a `$`. – Leandros Apr 21 '16 at 20:55
  • and what i can do to print 31 directly from the memory? – Danielix Apr 21 '16 at 20:55
  • You would have to write a routine to do it for you. There is no built-in support for printing hex values. See [here](http://stackoverflow.com/questions/3853730/printing-hexadecimal-digits-with-assembly) or [here](http://stackoverflow.com/questions/18879672/printing-hex-values-in-x86-assembly). – Leandros Apr 21 '16 at 20:59
  • since i'm trying to do: MOV DX,[SI]+'$' And for now it printed no strange symbols but no 31.... i'm trying. But you have obiuvsly reason – Danielix Apr 21 '16 at 21:04
  • The literal number 31 will be printed as an ascii character, and 31 in ascii is a non-printable control character. If you, for example, put 64 in, it'll print an @ sign. [Here is a complete ascii table.](http://ascii.cl/). – Leandros Apr 21 '16 at 21:16
  • YAH, BUT I'M TRYING TO ADD THAT damn $ to the end of the dx........**crying*** – Danielix Apr 21 '16 at 21:29
  • The `$` has to be at location 101H. – Leandros Apr 21 '16 at 21:34

1 Answers1

3

Invoking the 21H interrupt with AH set to 09H, will print the $ terminated string in register DX. In your case DX contains 31H, which will point (I assume) to garbage, that's why you're getting random symbols printed.

Create the string you want to print inside your data section, and make the DX register point to it, before invoking the print syscall.

Leandros
  • 16,612
  • 9
  • 69
  • 105