#### buli

• Regular Member
• Posts: 7
« on: March 23, 2016, 03:29:24 AM »
Code: [Select]
` .MODEL SMALL .STACK .DATA   T  BYTE ' ABCDEFGHIJKLMNOPQRSTUVWXYZ\$'  .CODE MAIN:      MOV AX,@DATA     MOV DS,AX     MOV BX,01H            MOV SI,01H            MOV DL,[BX][SI]            MOV AH,02H     INT 21H     MOV AH,4CH     INT 21H    END main`Result==> L
Code: [Select]
` .MODEL SMALL .STACK .DATA         T  BYTE 'ABCDEFGHIJKLMNOPQRSTUVWXYZ\$' .CODE MAIN:      MOV AX,@DATA     MOV DS,AX     MOV BX,02H                      MOV DL,[BX]              MOV AH,02H     INT 21H     MOV AH,4CH     INT 21H    END main`Result==> A
WHY they get different results ?
In my point,i think that both results are same because they addressing same address.

• Member
• Posts: 189
« Reply #1 on: March 23, 2016, 04:10:32 AM »
Address of variable is missed :
Code: [Select]
`MOV DL, T[BX][SI]MOV DL, T[BX]`

#### buli

• Regular Member
• Posts: 7
« Reply #2 on: March 23, 2016, 11:03:38 AM »
Thanks sir
But  if i don't interpose T,Are their address different!?

#### FORTRANS

• Member
• Posts: 958
« Reply #3 on: March 24, 2016, 12:44:28 AM »
Hi,

But  if i don't interpose T,Are their address different!?

zero will be used.  If the T variable is the first variable declared
in the data segment, it will have an address of zero.  If anything
is specified before T, T will not have an address of zero.  The
variable's address is its offset from the beginning of the segment.

HTH,

Steve N.

#### nidud

• Member
• Posts: 1424
« Reply #4 on: March 24, 2016, 01:49:37 AM »
The segments are calculated at a 16-byte boundary so T may not be the same as DATA. There is also a SPACE in front of A in the first sample but not the second.

In the first sample ([BX][SI]) T is equal to DATA[6], and in the second T is equal to DATA[2]. Removing the space:
Code: [Select]
`00000040    21 B4 4C CD 21 00 41 42 | 43 44 45 46 47 48 49 4A  ! L-! ABCDEFGHIJ00000050    4B 4C 4D 4E 4F 50 51 52 | 53 54 55 56 57 58 59 5A  KLMNOPQRSTUVWXYZ00000060    24                                                 \$00000040    CD 21 41 42 43 44 45 46 | 47 48 49 4A 4B 4C 4D 4E  -!ABCDEFGHIJKLMN00000050    4F 50 51 52 53 54 55 56 | 57 58 59 5A 24        OPQRSTUVWXYZ\$`
Result is then L A

Using T the result is C C

#### nidud

• Member
• Posts: 1424
« Reply #5 on: March 24, 2016, 02:38:42 AM »
When you look at the binary output you will also see that the CODE segment overlap the DATA segment. The last code is INT 21H (CD 21) and DATA (in this case T) is aligned WORD (2).

Code: [Select]
` _DATA segment WORD  PUBLIC 'DATA'        _DATA ends`
Code: [Select]
`CODE: int ; CDDATA: 21h ; 21 mov ah,4CH ; B4 4C int 21h ; CD 21 db 0 ; 00 - align 2T db 'ABCDEFGHIJKLMNOPQRSTUVWXYZ\$'`
Code: [Select]
`CODE: mov ah,4CH ; B4 4CDATA: int 21h ; CD 21T db 'ABCDEFGHIJKLMNOPQRSTUVWXYZ\$'`

#### FORTRANS

• Member
• Posts: 958
« Reply #6 on: March 24, 2016, 02:59:17 AM »
Hi,

The segments are calculated at a 16-byte boundary so T may not be the same as DATA. There is also a SPACE in front of A in the first sample but not the second.

Good catch, thanks.   The DATA area is called a segment (using
the SEGMENT directive) but it can be byte-aligned.  The segment
registers are limited to a 16 byte resolution.  According to a
textbook, the default alignment of DATA is a paragraph (16 bytes)
for earlier processors, and DWORD (8 bytes) when using a  .80386
directive.  And presumably then, for all of the 32-bit processors.
Old textbook.  And other alignment types can be specified.

So an address of a variable is its offset from the start of the DATA
area, plus the DATA area's offset from a 16-byte alignment.

Regards,

Steve

P.S.  While I was typing, you added a WORD aligned example.  It
is not that the CODE and DATA areas overlap as such, but that the
DATA area is not on a 16-byte boundary.  The addressing of the
segment registers "overlap".

P.P.S.  My code is usually set up to have the DATA area on a 16-byte
boundary.  So I forgot that it need not be aligned.

SRN
SRN

#### nidud

• Member
• Posts: 1424
« Reply #7 on: March 24, 2016, 03:54:50 AM »
Well, that is sort of correct, but keep in mind that in 16-bit code the DATA segment is an actual SEGMENT as oppose to a 32-bit offset.

Code: [Select]
` mov DS,AX add BX,16 mov DL,[BX]`
Same as:
Code: [Select]
` add AX,1 mov DS,AX mov DL,[BX]`
Given size is an issue in 16-bit code, aligning PARA each time you add a BYTE will add additional 15 bytes so the default alignment for the .data section is 2 and 4 if 386.

#### buli

• Regular Member
• Posts: 7