Pl COURS.DOC
Jump to navigation
Jump to search
... continuation on addressing modes 7) PC RELATIVE ADDRESSING WITH DISPLACEMENT: (schematized as d(pc) ) -------------------------------------------------------- It is written as follows: ---------------- +-----------------------------------------+ | Instruction d(pc),destination | +-----------------------------------------+ And is read as: --------------- We add the value of the signed displacement 'd' coded on a WORD to the PC (of the considered instruction!), we take the data thus pointed to and place it in (at) the destination operand. d(pc)= d+pc Example: I use the 'JMP destination' instruction, which causes a jump -------- in the program to the 'destination' address by loading the value of PC with the value of 'destination'. (JMP as in JuMP=jump in English) if I write: JMP 10(pc) Before the execution of the JMP instruction, the PC points to the address of this instruction (JMP 10(pc) ) Writing JMP 10(pc) causes a jump of 10 Bytes after the address pointed to by the PC which points to this instruction (i.e., JMP 10(pc)), if at address PC+10 there is a Label ('A') for example, the instruction JMP 10(pc) causes a jump (by adding 10 to PC) to this Label. (Of course, there could be other instructions or something else, it all depends on your listing...) Example: -------- Labels program instructions . . here, PC=$AF00 X JMP 10(pc) , there's a jump to PC+10 . . . here, PC=$AF10 A ............ , we continue at $AF10 . . Therefore, the size of the JMP d(pc) instruction must be taken into account for the displacement because the preceding PC of the considered instruction plays a role. Indeed, the size of the instructions in memory varies according to the addressing mode used. At the end of this chapter on addressing modes, I will provide the size and representation of addressing modes in memory. So, the real displacement is the actual displacement + the size of the instruction and its operands. 8) PC RELATIVE ADDRESSING WITH INDEX AND DISPLACEMENT: (d(pc,rn)) -------------------------------------------------------------- It is written as follows: ---------------- +-----------------------------------------+ | Instruction d(pc,rn),destination | +-----------------------------------------+ And is read as: --------------- We add the value of the signed displacement 'd' coded on a WORD and that of the 'rn' register to the PC (of the considered instruction!), we take the data thus pointed to and place it in (at) the destination operand. d(pc,rn)= d+an+pc OR d(pc,rn)= d+dn,pc This addressing mode is therefore identical to the previous one, except that here we add the displacement and the content of the 'rn' register to the preceding PC of the considered instruction. If 'rn' is a WORD (.W), the lower WORD of the 'rn' register is used during the operation. If 'rn' is a LONG (.L), the 'rn' index register is entirely used. 9) LONG ABSOLUTE ADDRESSING: (schematized as BBBB ) ------------------------------------------------ It is written as follows: ---------------- +-----------------------------------+ | Instruction source,Address | +-----------------------------------+ OR -- +-----------------------------------+ | Instruction Address,destination | +-----------------------------------+ And is read as: --------------- The source operand is placed in (at) the address specified by the destination operand. OR -- The data pointed to by the 'Address' operand is taken and placed in (at) the destination operand. Example: MOVE labas,d0 -------- . . . DATA labas DC.W 12 at 'labas', there's a WORD=12 The data register d0 will contain 12. Another example: MOVE D0,$AFFB48 if $AFFB48 is in a DATA -------------- segment (details soon) The low WORD of d0 is placed at address $AFFB48 10) SHORT ABSOLUTE ADDRESSING: (schematized as BB ) ------------------------------------------------ It is written as follows: ---------------- +-----------------------------------+ | Instruction source,Address | +-----------------------------------+ OR -- +-----------------------------------+ | Instruction Address,destination | +-----------------------------------+ And is read as: --------------- The source operand is placed in (at) the address specified by the destination operand. OR -- The data pointed to by the 'Address' operand is taken and placed in (at) the destination operand. Addressing mode identical to the previous mode, but here the value of the address must be able to be contained within a WORD. INTERNAL REPRESENTATION OF ADDRESSING MODES AND EXTENSION WORDS: ----------------------------------------------------------------- Each addressing mode is associated with 0,1 or 2 EXTENSION WORDS, this can be important for the representation (size) of the different addressing modes in memory: (refer to the mode d(pc) or d(pc,rn) ) +-------------------------+---------------------+ | MODES | NUMBER OF WORDS | | ADDRESSING | EXTENSION | +-------------------------+---------------------+ | BBBB | 2 | +-------------------------+---------------------+ | BB | 1 | +-------------------------+---------------------+ | #... | 1 if .B or .W | | | 2 if .L | +-------------------------+---------------------+ | (an) | 0 | +-------------------------+---------------------+ | (an)+ | 0 | +-------------------------+---------------------+ | -(an) | 0 | +-------------------------+---------------------+ | d(an) | 1 | +-------------------------+---------------------+ | d(an,rn) | 1 | +-------------------------+---------------------+ | d(pc) | 1 | +-------------------------+---------------------+ | d(pc,rn) | 1 | +-------------------------+---------------------+ - Please note that the size of the operands (if any) also plays a role in the memory representation of the instructions. In general, it is 1 WORD for the instruction + extension words and the size of the operands. Examples: --------- Thus: MOVE.W #14,D0 will be represented by 1 word (instruction) + 1 word (for the number 14) + 1 word (for the low WORD of d0) + 1 word (for immediate addressing with .W size which admits one extension word) = 4 words in memory. Another example: JMP $AFFA02 will be represented by 3 Words in memory (long absolute addressing mode that admits 2 extension words + 1 word for JMP) - This covers the addressing modes, but before moving on to the exercises, let me explain the different assembly directives you will find in the listings. *** ASSEMBLY DIRECTIVES *** ---------------------------- You already know: - TEXT : Resets the PC, placed at the beginning of the listing. - EQU : Associates a numerical value with an address. (A Label) Here are some other directives: - END : Indicates to the assembler that what follows this directive should no longer be assembled (thus ignored). Attention, it does not trigger the 'end' of the program. - DATA : This directive delimits a DATA SEGMENT, the PC is reset in the same way as with 'text'. In the DATA SEGMENT, data (or datas) is defined. Then, the directives DC.B, DC.W or DC.L can be used: DC.B : Allows placing constants (data) in memory as bytes. For example, a constant can be associated with an address, the data must be separated by commas. Example: LABEL DC.B 0,1,6,3,11,46,$4F,%10110010 ---- Here, at the LABEL address, there is a BYTE (.B) that equals 0, at LABEL+1 there is a BYTE (.B) that equals 1... at LABEL+6 there is a BYTE (.B) that equals $4F, etc... DC.W : Similar to DC.B except that here, Words are stored in memory. DC.L : Similar to DC.W or DC.B except that here, Long Words are stored in memory. - BSS : This directive also resets the PC. It delimits a BSS SEGMENT. In a BSS segment, space is reserved in memory in the form of BYTES, WORDS or LONG WORDS. Indeed, one cannot place data in memory if one does not reserve that portion of the memory!!! (except for specific cases that we will study) Then, the 'DS.suffix quantity' directive is used to reserve space in memory without initializing it. DS.B : Reserves a certain quantity of Bytes in memory. Example: LABEL DS.B 120 : at the LABEL address, there ---- is a sequence of 120 Bytes reserved. One can then place data in it. DS.W : Reserves a certain quantity of Words in memory. DS.L : Reserves a certain quantity of Long Words in memory. - That's all, go do the exercises (file EXOS_1.DOC), there are loads of them, but after that, I hope there will no more problems (hopefully!!) with the addressing modes. - Then you'll come back to continue the lessons in the file: INSTRUC.DOC ----------- ------------------
Back to ASM_Tutorial