The largest and smallest segment of assembly language

Source: Internet
Author: User

From the "Assembly Language" forum

What is the meaning of the argument here, do an experimental test on it, the largest 64K should be no one against it is the smallest, some say 0 byte, some say 16Bytes, some say other, that is how much, we see this program

Assume Cs:code, Ds:data

Data segment

Data ends

Code segment

Start

MOV ax, data

MOV ds, ax

MOV bx, CS

Sub ax, BX code ends

End Start

Here, I first define an empty data segment, and then define a short code, we look at the starting address of the data segment and the beginning of the code snippet does not know the minimum number of bytes of a segment?

This is the result of debug:

-U

144b:0000 b84b14 MOV ax,144b

144b:0003 8ed8 MOV Ds,ax

144b:0005 8CCB MOV Bx,cs

144b:0007 2BC3 SUB AX,BX

-T

ax=144b bx=0000 cx=0009 dx=0000 sp=0000 bp=0000 si=0000 di=0000 ds=143b es=143b ss=144b CS=144B IP= 0003 NV up EI PL NZ NA PO NC 144b:0003 8ed8

MOV Ds,ax

-T

ax=144b bx=0000 cx=0009 dx=0000 sp=0000 bp=0000 si=0000 di=0000 ds=144b es=143b ss=144b CS=144B IP= 0005 NV up EI PL NZ NA PO NC 144b:0005 8CCB

MOV Bx,cs

-T

ax=144b bx=144b cx=0009 dx=0000 sp=0000 bp=0000 si=0000 di=0000 ds=144b es=143b ss=144b CS=144B IP= 0007 NV up EI PL NZ NA PO NC 144b:0007 2BC3

SUB AX,BX

-T

ax=0000 bx=144b cx=0009 dx=0000 sp=0000 bp=0000 si=0000 di=0000 ds=144b es=143b ss=144b CS=144B IP= 0009 NV up EI PL ZR NA PE NC 144b:0009 007511

ADD [Di+11],dh ds:0011=08-

You see the first disassembly command: 144b:0000 b84b14 MOV ax,144b The first instruction is to send the segment address of the data segment to AX, and here it is clear that the data segment address of the disassembly and the segment address of the code snippet are 144B, and we know that the offset address is From 0, see the offset address of the first instruction is also 0, that is, the code snippet although we define, but not occupy space, this also shows that the minimum space for a segment is 0, when it has no data, but when it has data, the minimum space is 16 bytes, why say that, I'll modify the above program a little bit:

Assume Cs:code, Ds:data

Data segment

DB 0

Data ends

Code segment

Start

MOV ax, data

MOV ds, ax

MOV bx, CS

Sub ax, BX code ends

End Start

Look at the disassembly result:-U

144c:0000 b84b14 MOV ax,144b

144c:0003 8ed8 MOV Ds,ax

144c:0005 8CCB MOV Bx,cs

144c:0007 2BC3 SUB AX,BX

144c:0009 1d0875 SBB ax,7508

144c:000c 1b8b5efe SBB cx,[bp+di+fe5e]

144c:0010 F6471008 TEST BYTE PTR [bx+10],08

144c:0014 7403 JZ 0019

144c:0016 e9fe00 JMP 0117

144c:0019 837f0c00 CMP WORD PTR [bx+0c],+00

144c:001d 7403 JZ 0022

144c:001f e9f500 JMP 0117

Just look at the 1th directive: 144c:0000 b84b14 MOV ax,144b This instruction sends the segment address of the data segment to AX and it is clear that the address of the first instruction of the program is 144c:0000 that is, the segment address of the snippet is 144C, 144C, and 144B The difference between 1H, and the physical address is the difference 10h,10h with 1 decimal means is not 16, that is, 16 bytes, we look at the following results:

-D 144b:0

144b:0000 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 .......

144b:0010 B8 4 b 8E D8 8C CB 2b-c3 1D 1 b 8B 5E FE. K.....+...u. ^.

144b:0020 F6, E9 FE-00 7F 0C, E9. G.. t........t.

144b:0030 F5 B8 2D E9 9E 00-e8 2B All-in-8B 5C ...-..... +. D.. \

144b:0040 8A 8B 5C 88-47, 8B FB C7 8B. G.. \.. G.......

144b:0050 5E FE C4 5F, 8B 47-16, 0C FF E8 ^. _.&. G.. E.. T..

144b:0060 9C 0E 8B 02-c7-----... D.. D.. d....~.

144b:0070 2B FF E9 B2 8B 5C 02-f6. E9 A6 +.....\ G.. T...

Let's take a look at the contents of this memory, from 144b:0000 to 144b:000f is exactly the content of the data segment and from the beginning of the 144b:0010 is the content of the code snippet, that is, 144c:0000, and then look at the front 3 bytes of content 144b:0010 B8 4 B 14

B8 4 B 14 Control disassembly of the first instruction 144c:0000 b84b14 MOV ax,144b Identical, this means that the code snippet and data segment 16 bytes apart. This also explains the assertion that the starting address of the code snippet must be a multiple of 16.

To summarize, if there is content in a segment, then this segment takes up a minimum of 16 bytes of space, and if there is no content, the space is 0 bytes. Of course, the largest segment is 64K bytes.

=====================================

If less than 16 bytes, to 16, more than 16 and not multiples, to a multiple, such as 19 to its 32

The largest and smallest segment of assembly language

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.