News:

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

Problem with arrays

Started by ERNI, September 18, 2005, 02:59:45 PM

Previous topic - Next topic

ERNI

Hey
I use masm613 and
i have a problem with arrays in my code :

This is my code :


.MODEL small
.stack 100h

.data
array1 dw 10h,80h
array2 dw 30h,40h
.code
main proc
  mov ax,array1
  inc ax
  add ah,1
  sub ax,array1

main endp
end main



on logic ...,I thought that  :
in first line my code AX=10h
in second line AX=11h
but when i disasemble my code i have seen ,but AX in the first line in my code is AX=06d9,
but not 10h WHY ?


I was thought that in AX is a adres my array1 and I have seen memory on the adress DS:06d9
and i cant seen there  10h why ?

Can You tell my WHY
PLEASE :eek


MichaelW

When you access data memory the processor, by default, uses the contents of DS for the segment address. The program loader leaves DS set to the segment address of the Program Segment Prefix, which would be correct only for a COM file. For an EXE file, to access data you must set DS to the segment address of the data segment. You could do so with the sequence:

movĀ  ax,@data
movĀ  ds,ax


Or by including a .STARTUP directive at the intended start address.

See 'Starting and Ending Code with .STARTUP and .EXIT' here:

http://webster.cs.ucr.edu/Page_TechDocs/MASMDoc/ProgrammersGuide/Chap_02.htm

And 'Predefined Symbols' here:

http://webster.cs.ucr.edu/Page_TechDocs/MASMDoc/ProgrammersGuide/Chap_01.htm


eschew obfuscation

ERNI

OK
I corect my code and i copy da ta to DS segment

this is my code:

.MODEL small
.stack 100h

.data
array1 dw 10h,80h
array2 dw 30h,40h
.code
main proc
  mov ax,array1
  inc ax
  add ah,1
  sub ax,array1

main endp
end main


And when i debug my program
np :
      debug myprogram.exe
It looks so  :
0CCF:0000 B8D00C        MOV     AX,0CD0
0CCF:0003 8ED8           MOV     DS,AX
0CCF:0005 A10000        MOV     AX,[0000] ; I think that in AX=10h but AX=0CD0 !!!!
0CCF:0008 40               INC     AX
0CCF:0009 80C401        ADD     AH,01
0CCF:000C 2B060000    SUB     AX,[0000]
0CCF:0010 800080        ADD     BYTE PTR [BX+SI],80
0CCF:0013 0030           ADD     [BX+SI],DH
0CCF:0015 004000        ADD     [BX+SI+00],AL
0CCF:0018 61               DB      61
0CCF:0019 206479        AND     [SI+79],AH
0CCF:001C 736B          JNB     0089
0CCF:001E 750D          JNZ     002D
data segment DS  looks so
-d ds:0000
0CBF:0000  CD 20 FF 9F 00 9A F0 FE-1D F0 4F 03 D9 06 8A 03   . ........O.....
0CBF:0010  D9 06 17 03 D9 06 C8 06-01 01 01 00 02 FF FF FF   ................
0CBF:0020  FF FF FF FF FF FF FF FF-FF FF FF FF 8A 0C 4C 01   ..............L.
0CBF:0030  9D 0B 14 00 18 00 BF 0C-FF FF FF FF 00 00 00 00   ................
0CBF:0040  05 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00   ................
0CBF:0050  CD 21 CB 00 00 00 00 00-00 00 00 00 00 20 20 20   .!...........
0CBF:0060  20 20 20 20 20 20 20 20-00 00 00 00 00 20 20 20           .....
0CBF:0070  20 20 20 20 20 20 20 20-00 00 00 00 00 00 00 00           ........

WHERE is  my array1 ?
Please tel my wher is my array1 ? ::)
THANKS

MichaelW

The code you posted does not match the disassembly. The dump of the data segment is the Program Segment Prefix, so DS has not been loaded with the segment address of the data segment. The end directive specifies that the program entry point is at the start of main. If the instructions that load DS are placed in the code segment above the entry point, they will not be executed.

eschew obfuscation

ERNI

OK
Now I understand
THANKS MichaelW  :U