News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

writing at a memory address

Started by serge, June 24, 2010, 12:34:50 PM

Previous topic - Next topic

serge

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

redskull

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
Strange women, lying in ponds, distributing swords, is no basis for a system of government

serge

It's fine now

Thanks for you help

Serge

clive

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
It could be a random act of randomness. Those happen a lot as well.