Lecture 5 microporcessor
Lecture 5 microporcessor
Lecture 5
LECTURE OUTLINE
Data-addressing modes
PROGRAM MEMORY-ADDRESSING MODES
STACK MEMORY-ADDRESSING MODES
EXAMPLE 3-2
Example 3–2 shows various immediate instructions in a short assembly
language program.
The .MODEL TINY statement directs the assembler to assemble the
program into a single code segment.
The .CODE statement or directive indicates the start of the code
segment;
The .STARTUP statement indicates the starting instruction in
the program.
The .EXIT statement causes the program to exit to DOS.
The END statement indicates the end of the program file.
Example 3–4 shows a function in a
Visual C++ program that includes
some code written with the inline
assembler.
This function adds 20H to the
number returned by the function.
EXAMPLE 3-6
Example 3–6 shows a short program using models that address
information in the data segment.
Note that the data segment begins with a .DATA statement to inform
the assembler where the data segment begins.
The SMALL model allows one data segment and one code segment.
Notice how this example allocates memory locations in the data
segment by using the DB and DW directives.
Here the .STARTUP statement not only indicates the start of the code,
but it also loads the data segment register with the segment address of
the data segment.
EXAMPLE 3-7
The sequence shown in Example 3–7 loads register BX with the
starting address of the table
it initializes the count, located in register CX, to 50.
The OFFSET directive tells the assembler to load BX with the offset
address of memory location TABLE, not the contents of TABLE.
For example, the MOV BX,DATAS instruction copies the contents of
memory location DATAS into BX, while the MOV BX,OFFSET DATAS
instruction copies the offset address DATAS into BX.
When the OFFSET directive is used with the MOV instruction, the
assembler calculates the offset address and then uses a MOV
immediate instruction to load the address in the specified 16-bit
register.
EXAMPLE 3-7
Once the counter and pointer are initialized, a repeat-until CX = 0 loop
executes.
Here data are read from extra segment memory location 46CH with the MOV
AX,ES:[046CH] instruction and stored in memory that is indirectly addressed by
the offset address located in register BX.
Next, BX is incremented (1 is added to BX) twice to address the next word in
the table.
Finally, the LOOP instruction repeats the LOOP 50 times. The LOOP instruction
decrements (subtracts 1 from) the counter (CX); if CX is not zero, LOOP causes a
jump to memory location AGAIN.
If CX becomes zero, no jump occurs and this sequence of instructions ends.
This example copies the most recent 50 values from the clock into the memory
array DATAS.
EXAMPLE 3-9
Example 3–9 shows how this new addressing mode can transfer the
contents of array element10H into array element 20H.
Notice the similarity between this example and Example 3–8.
The main difference is that, in Example 3–9, register BX is not used to
address memory ARRAY; instead, ARRAY is used as a displacement to
accomplish the same task.
EXAMPLE 3-11
Example 3–11 shows a sequence of instructions that uses scaled-index
addressing to access a word-sized array of data called LIST.
Note that the offset address of LIST is loaded into register EBX with the
MOV EBX,OFFSET LIST instruction.
Once EBX addresses array LIST, the elements (located in ECX) of 2, 4,
and 7 of this word-wide array are added, using a scaling factor of 2 to
access the elements.
This program stores the 2 at element 2 into elements 4 and 7.
Also notice the .386 directive to select the 80386 microprocessor. This
directive must follow the .MODEL statement for the assembler to process
80386 instructions for DOS.
If the 80486 is in use, the .486 directive appears after the .MODEL
statement.
3-2 PROGRAM MEMORY-ADDRESSING
MODES