简体   繁体   中英

Calculating the segment address range of an 8086 assembly programm

I have the following lines of programm (written for 8086 Microprocessor):

first SEGMENT BYTE
  a db 7 dup (?)
first ENDS      

second SEGMENT WORD
  b dw 200 dup (?)
second ENDS

third SEGMENT PARA
  c db 3 dup (?)
  d dw ?
third ENDS

And I need to find what is the address range of those three segments knowing that the first avaible address is 1000h.

For the first one since there are 7 x bytes defined in the segment the range will simply be: 1000h:1006h

For the second one there are 200 x 2 = 400 = 190h bytes (since 1 word=2bytes)

I know that now I have to add this to the initial address, but I don't know what exactly would be that.

I am guessing that it still would be 1007, so afterwards the range of the second segment would simply be: 1007h:(1007+190)h. Is this correct? Also the same reasoning would go for the third segment?

In MASM syntax the SEGMENT directive followed by BYTE/WORD/PARA indicates alignment. Alignment tells the assembler that prior to emitting the segment, the address has to be rounded up to the nearest BYTE/WORD/PARA boundary. Clearly BYTE alignment will force no adjustment because every memory address is on a byte boundary. A WORD is 2 bytes, and PARA is 16 bytes (the size of a PARAgraph)

Segments (by default) are output in the order they are encountered (this behavior can be overridden, but the code presented makes no such modification).

The starting program counter we are given is 1000h. Given the first section:

first SEGMENT BYTE
  a db 7 dup (?)
first ENDS 

Alignment of BYTE doesn't alter anything so the start address is still 1000h. We emit 7 bytes with db 7 dup (?) from 1000h to 1006h (inclusive). The program counter after this section is emitted is 1007h (right after the last byte emitted). We then encounter the next section:

second SEGMENT WORD
  b dw 200 dup (?)
second ENDS

WORD alignment means we have to round up to an address that is evenly divisible by 2 before emitting the section. 1007h rounded up to the next WORD boundary is 1008h. 1008h is evenly divisible by 2. We emit 200 16-bit words with dw 200 dup (?) for a total of 400 bytes. 400 decimal is 190h. This section will span the range 1008h to 1197h inclusive. The program counter will be at 1198h.

third SEGMENT PARA
  c db 3 dup (?)
  d dw ?
third ENDS

PARA means the program counter needs to be evenly divisible by 16 (decimal) before emitting the section. 1198h is not divisible by 16 (decimal) already so it needs adjustment. The next address that is divisible by 16 is 11A0h (any number ending in hex digit 0 is evenly divisible by 16). Our program counter is now 11A0h. 3 bytes are emitted with db 3 dup (?) and one word with dw ? for a total of 5 bytes. This data spans the address range 11A0h and 11A4h (inclusive). The program counter will be 11A5h after this section is emitted.

The address range of ALL the sections combined will be 1000h to 11A4h (inclusive).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM