ARCHITECTURE AND INSTRUCTIONS

Ordinarily, it doesn't matter where in mem- ory segments are located, so we let the translator make that choice. However, we might want to give the translator some con- straints such as "don't overlap this segment with any other segment," "make sure the first byte used by this segment is at an even address" or "start this segment at the follow- ing address." We can write these constraints into the source program:

1)Don't overlap. First usable byte in seg- ment is on a 16-byte boundary and has an offset of 0000.

MY_SEG SEGMENT

;this is the normal case

2)Overlap if you must, but first usable byte must be on a word boundary.

MY_SEG SEGMENT WORD ;word aligned

3)Overlap if you must, and place first usable byte anywhere you like.

MY_SEG SEGMENT BYTE

;byte aligned

4)Start segment at specified l6-byte boun- dary. First usable byte is at specified offset.

MY_SEG SEGMENT AT 1A2BH ;address 1A2BO

ORG

0003H

;address 1A2B3

The last example introduced another state- ment, ORG (for origin). It specifies the next offset to be used in the segment.

Procedure-Definition Statements

Procedures are sections of code that are called into execution from various places in the program. Each time a procedure is called upon, the. instructions that make up the procedure are executed, then control is returned to the place from which the proce- dure was originally called.

The 8088 instructions to call and return from a procedure are CALL and RET. These instructions come in two flavors - intraseg- ment and intersegment.

The intersegment instructions push (CALL) and pop (RET) both the segment and the offset of the place where the procedure should return.

The intrasegment ones push and pop only the offset.

Near and Far

Procedures called with intrasegment CALLs must return with intrasegment RETurns. Such procedures are known as NEAR procedures. Similarly, procedures that are called with intersegment CALLs must return with intersegment RETurns and are known as FAR procedures.

The procedure-definition statements, PROC and ENDP (end procedure), delimit a proce- dure and indicate whether it is a NEAR or FAR procedure. This helps the assembler in two ways. First, when assembling CALLs to that procedure, the assembler will know which kind of CALL to assemble. Secondly, when assembling RETs from that procedure, the assembler will know which kind of RET to assemble: (see table on next page)

Since UP_COUNT is declared to be NEAR procedure, all CALLs to it are assembled as intrasegment CALLs, and all RETurns with- in it are assembled as intrasegment returns.

This example points out some similarities between the RET instructions and the HLT instruction. There may be more than one

2-36

Page 71
Image 71
Intel 210200-002 manual Near and Far