Вы находитесь на странице: 1из 27

EE3323: Microprocessor and Computer

Architecture

Lecture 13: The Stack and 8086 Assembly Programs

Dr. M Faisal Iqbal

Lecture 13: The Stack and 8086 Assembly Programs EE3323: Microprocessor and Computer Architecture
Register Indirect Addressing

I Effective address resides in either base or an index register


e.g.,
Mov BX, [DI]
I Move 16-bit data from memory pointed to by DI in data
segment, into register BX
I Any of the base register BX, BP, or index registers SI, DI can
be used in effective address computation
I If effective address is computed using BP, data is loaded from
the stack segment in memory

Lecture 13: The Stack and 8086 Assembly Programs EE3323: Microprocessor and Computer Architecture
Register Indirect Addressing: Example

Figure: Mov AX, [SI] before execution

Lecture 13: The Stack and 8086 Assembly Programs EE3323: Microprocessor and Computer Architecture
Register Indirect Addressing: Example

Figure: Mov AX, [SI] after execution

Lecture 13: The Stack and 8086 Assembly Programs EE3323: Microprocessor and Computer Architecture
Based Addressing

I Effective address of the operand is computed by adding


immediate displacement into any of the base registers i.e., BX
or BP
I mov CX, [BX + 1212h]
I copy 16 bit contents from memory location pointed by BX +
1212h in data segment into CX register
I if base register is BX, DS will be used as segment register
I if base register is BP, SS will be used as segment register

Lecture 13: The Stack and 8086 Assembly Programs EE3323: Microprocessor and Computer Architecture
Based Addressing: Example

Figure: Mov [BX + 1234H], AL before execution

Lecture 13: The Stack and 8086 Assembly Programs EE3323: Microprocessor and Computer Architecture
Based Addressing: Example

Figure: Mov [BX + 1234H], AL after execution

Lecture 13: The Stack and 8086 Assembly Programs EE3323: Microprocessor and Computer Architecture
Based Addressing Usage
I Based addressing can be used to access elements of an array
in memory
I Base register will point to start of the array. By changing
value of displacement different elements of array can be
accessed

I mov AX, [BX + 0h]


I mov AX, [BX + 2h]

Lecture 13: The Stack and 8086 Assembly Programs EE3323: Microprocessor and Computer Architecture
Indexed Addressing
I Indexed addressing is similar to based addressing with only
difference that index registers are used in place of based
registers for EA computation
I Indexed addressing can also be used to access elements of a
data array
I Displacement points to start of array
I Different alements can be accessed by incrementing index
register

Lecture 13: The Stack and 8086 Assembly Programs EE3323: Microprocessor and Computer Architecture
Based Index Addressing Mode

I Combines based and indexed mode as the name suggests and


is used to access complex data structures such as
two-dimensional arrays
I Effective address is sum of contents of base register, index
register and a displacement
Mov AH, [BX+SI+1234h]
I This addressing mode is highly specific and very rarely used

Lecture 13: The Stack and 8086 Assembly Programs EE3323: Microprocessor and Computer Architecture
Based Indexed Addressing: Example

Figure: Mov AH, [BX+SI+1234h] before execution

Lecture 13: The Stack and 8086 Assembly Programs EE3323: Microprocessor and Computer Architecture
Based Indexed Addressing: Example

Figure: Mov AH, [BX+SI+1234h] after execution

Lecture 13: The Stack and 8086 Assembly Programs EE3323: Microprocessor and Computer Architecture
Addressing Modes Review

Identify addressing modes used for source and destination operands


in the following instructions
I MOV AL, BL
I MOV AX, 0FFH
I MOV [DI], AX
I MOV DI, [SI]
I MOV [BX] + 0400h, CX
I MOV [BX][DI]+0400h, AL

Lecture 13: The Stack and 8086 Assembly Programs EE3323: Microprocessor and Computer Architecture
Addressing Modes Review

Identify addressing modes used for source and destination operands


in the following instructions
I MOV AL, BL
I MOV AX, 0FFH
I MOV [DI], AX
I MOV DI, [SI]
I MOV [BX] + 0400h, CX
I MOV [BX][DI]+0400h, AL

Lecture 13: The Stack and 8086 Assembly Programs EE3323: Microprocessor and Computer Architecture
Addressing Modes Review

Identify addressing modes used for source and destination operands


in the following instructions
I MOV AL, BL
I MOV AX, 0FFH
I MOV [DI], AX
I MOV DI, [SI]
I MOV [BX] + 0400h, CX
I MOV [BX][DI]+0400h, AL

Lecture 13: The Stack and 8086 Assembly Programs EE3323: Microprocessor and Computer Architecture
Addressing Modes Review

Identify addressing modes used for source and destination operands


in the following instructions
I MOV AL, BL
I MOV AX, 0FFH
I MOV [DI], AX
I MOV DI, [SI]
I MOV [BX] + 0400h, CX
I MOV [BX][DI]+0400h, AL

Lecture 13: The Stack and 8086 Assembly Programs EE3323: Microprocessor and Computer Architecture
Addressing Modes Review

Identify addressing modes used for source and destination operands


in the following instructions
I MOV AL, BL
I MOV AX, 0FFH
I MOV [DI], AX
I MOV DI, [SI]
I MOV [BX] + 0400h, CX
I MOV [BX][DI]+0400h, AL

Lecture 13: The Stack and 8086 Assembly Programs EE3323: Microprocessor and Computer Architecture
Addressing Modes Review

Identify addressing modes used for source and destination operands


in the following instructions
I MOV AL, BL
I MOV AX, 0FFH
I MOV [DI], AX
I MOV DI, [SI]
I MOV [BX] + 0400h, CX
I MOV [BX][DI]+0400h, AL

Lecture 13: The Stack and 8086 Assembly Programs EE3323: Microprocessor and Computer Architecture
Segment Override Prefix

I By default, 8086 addressing modes access data in data


segment or stack segment depending upon the base register
(BX, BP)
I With segment override prefix 8086 addressing modes can
access data from any of the 4 active segments in memory

Examples:
mov ES:[0123H], AL
mov CX, SS:[BX + DI + 0400H]
mov AX, CS:[SI]

Lecture 13: The Stack and 8086 Assembly Programs EE3323: Microprocessor and Computer Architecture
Stack Operations

Two Common operations performed on stack are


I PUSH: performed to place data at the top of the stack
I POP: performed to remove data from the top of the stack

Lecture 13: The Stack and 8086 Assembly Programs EE3323: Microprocessor and Computer Architecture
Stack Segment Organization
I Stack in 8086 grows in downward direction
I At startup, SP is initialized to FFFEH
I Address SS:FFFEH is called
bottom of the stack
I Address SS:0000H is called
End of stack
I On every push stack
automatically decrements by 2
I On every pop stack
automatically increments by 2

Lecture 13: The Stack and 8086 Assembly Programs EE3323: Microprocessor and Computer Architecture
Stack Addressing Mode

I Source and destination should be words (16bits)


I source and destination cannot be immediates
I CS or IP register cannot be used as destination

Examples:
PUSH AX ; Push contents of register AX on stack
; sp = sp - 2
; M[SP] = AX
POP AX ; Pop top of the stack and place contents in AX
; AX = M[SP];
; sp = sp + 2;

Lecture 13: The Stack and 8086 Assembly Programs EE3323: Microprocessor and Computer Architecture
Writing 8086 Assembly Programs

I Software package we’ll use is Emu8086


I available at
I Google classroom
I Course folder on Data server

Lecture 13: The Stack and 8086 Assembly Programs EE3323: Microprocessor and Computer Architecture
Assembly Language Statements

I Assembly instructions in a program must be written in syntax


understood by the assembler
I Generic format of the assembly instructions
LABEL: OPCODE OPERANDS; Comments
Examples:
START: mov CX, 10 ; move 10 into CX
ADD AX, BX ; AX = AX + BX
I Label field ends with a colon ’:’
I comment field starts with a semi colon ’;’
I Labels and comment fields are optional

Lecture 13: The Stack and 8086 Assembly Programs EE3323: Microprocessor and Computer Architecture
Labels and Comments
Labels (LABEL:)
I Lebel allow program to refer to a line of code by name
I Lebels in 8086 must start with a letter and cannot be more
than 31 characters
I Branch and jump instruction use labels to jump to specific
locations in the code
Comments(; COMMENT)
I Comments are for programmer’s reference
I comments are ignored by the assembler

Lecture 13: The Stack and 8086 Assembly Programs EE3323: Microprocessor and Computer Architecture
Assembler Directives

Lecture 13: The Stack and 8086 Assembly Programs EE3323: Microprocessor and Computer Architecture
Assembler Directives

I Assembler directives are part of assembly source code but are


only used by the assembler
I An assembler directive is a message to the assembler to help
the assembler in the assembly process. Once the assembler
handles the message, the pseudo-op is discarded.
I It does not refer to operations that will be performed by the
program during execution.

Lecture 13: The Stack and 8086 Assembly Programs EE3323: Microprocessor and Computer Architecture

Вам также может понравиться