Author Topic: Addressing mode  (Read 1657 times)

buli

  • Regular Member
  • *
  • Posts: 7
Addressing mode
« on: March 23, 2016, 03:29:24 AM »
<Base indexed addressing>
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
<Register indirect addressing>
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.

Adamanteus

  • Member
  • **
  • Posts: 180
Re: Addressing mode
« 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
Re: Addressing mode
« 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: 945
Re: Addressing mode
« Reply #3 on: March 24, 2016, 12:44:28 AM »
Hi,

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

   Without the T to specify the variable address, an address of
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: 1370
    • https://github.com/nidud/asmc
Re: Addressing mode
« 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-! ABCDEFGHIJ
00000050    4B 4C 4D 4E 4F 50 51 52 | 53 54 55 56 57 58 59 5A  KLMNOPQRSTUVWXYZ
00000060    24                                                 $

00000040    CD 21 41 42 43 44 45 46 | 47 48 49 4A 4B 4C 4D 4E  -!ABCDEFGHIJKLMN
00000050    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: 1370
    • https://github.com/nidud/asmc
Re: Addressing mode
« 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 ; CD
DATA:
21h ; 21
mov ah,4CH ; B4 4C
int 21h ; CD 21
db 0 ; 00 - align 2
T db 'ABCDEFGHIJKLMNOPQRSTUVWXYZ$'

Code: [Select]
CODE:
mov ah,4CH ; B4 4C
DATA:
int 21h ; CD 21
T db 'ABCDEFGHIJKLMNOPQRSTUVWXYZ$'

FORTRANS

  • Member
  • ****
  • Posts: 945
Re: Addressing mode
« 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: 1370
    • https://github.com/nidud/asmc
Re: Addressing mode
« 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
Re: Addressing mode
« Reply #8 on: March 25, 2016, 05:14:15 AM »
Thanks FORTRANS  and Nidud a lot :biggrin:
How patient you are!!
I think that i forgot a useful tool----"Debug"
Well,there some point i still can't understand(Occupy 30%). But i expected that as i finish the course,i will realize them.