The MASM Forum Archive 2004 to 2012

Miscellaneous Forums => 16 bit DOS Programming => Topic started by: serge on June 24, 2010, 12:34:50 PM

Title: writing at a memory address
Post by: serge on June 24, 2010, 12:34:50 PM
Hello,

I'm new to the assembler language and I wanted to understand how the "puts" function is working.

From the tutorial "The puts (put a string) routine prints the zero terminated string at which es:di points1.". Therefore I tried to write something at a precise address memory , to put a pointer in es:di and after to display it. Unfortunately I didn't managed. The code is executing but is displaying a "H" instead of the "Hello" I wanted to see

Can anyone help me ?

Thank you in advance

Serge

Here is the code

      mov bx, 48h
      mov ds:[100], bx
      mov bx, 65h
      mov ds:[101], bx
      mov bx, 6Ch
      mov ds:[102], bx
      mov bx, 6Ch
      mov ds:[103], bx      
                                mov bx, 6Fh
      mov ds:[104], bx

      mov al, ds:[100]
      mov es:[di], al

      puts
Title: Re: writing at a memory address
Post by: redskull on June 24, 2010, 01:35:33 PM
These two lines are problematic:

      mov al, ds:[100]  ; move the character from memory into al
      mov es:[di], al     ; what is value of DI?

change them to:

     mov ax,ds
     mov es,ax
     mov di,0100 ;es:di now points to ds:0100, as required

-r
Title: Re: writing at a memory address
Post by: serge on June 24, 2010, 02:03:13 PM
It's fine now

Thanks for you help

Serge
Title: Re: writing at a memory address
Post by: clive on June 24, 2010, 03:32:43 PM
You should probably just use bytes (BL) and not word (BX), and terminate the string with a ZERO/NUL. A side effect of using BX was the byte at 105 was being written as a 0.

; Bytes, DS: is infered

      mov bl, 48h ; H
      mov [100], bl
      mov bl, 65h ; e
      mov [101], bl
      mov bl, 6Ch ; l
      mov [102], bl
      mov bl, 6Ch ; l
      mov [103], bl
      mov bl, 6Fh ; o
      mov [104], bl

      mov bl, 0
      mov [105], bl ; Zero Terminate

      mov ax,ds
      mov es,ax
      lea di,100

      puts