Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.

Slides:



Advertisements
Similar presentations
Programming 8086 – Part IV Stacks, Macros
Advertisements

Machine/Assembler Language Putting It All Together Noah Mendelsohn Tufts University Web:
There are two types of addressing schemes:
Chapter 3 Addressing Modes
Using the Assembler Chapter 4 Operators and Expressions
Lect 3: Instruction Set and Addressing Modes. 386 Instruction Set (3.4) –Basic Instruction Set : 8086/8088 instruction set –Extended Instruction Set :
Data Movement Instructions
Assembly Language for Intel-Based Computers Chapter 5: Procedures Kip R. Irvine.
1 Lecture 5: Procedures Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
ICS312 Set 3 Pentium Registers. Intel 8086 Family of Microprocessors All of the Intel chips from the 8086 to the latest pentium, have similar architectures.
Microprocessor Systems Design I Instructor: Dr. Michael Geiger Spring 2014 Lecture 4: x86 memory.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Stack Operations Runtime Stack PUSH Operation POP.
© 2006 Pearson Education, Upper Saddle River, NJ All Rights Reserved.Brey: The Intel Microprocessors, 7e Chapter 2 The Microprocessor and its Architecture.
Chapter 3: Addressing Modes. Copyright ©2009 by Pearson Education, Inc. Upper Saddle River, New Jersey All rights reserved. The Intel Microprocessors:
Lect 4: Instruction Set and Addressing Modes. 386 Instruction Set (3.4)  Basic Instruction Set : 8086/8088 instruction set  Extended Instruction Set.
CSC 221 Computer Organization and Assembly Language
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
CDP ECE Spring 2000 ECE 291 Spring 2000 Lecture 7: More on Addressing Modes, Structures, and Stack Constantine D. Polychronopoulos Professor, ECE.
Dr. José M. Reyes Álamo 1.  The 80x86 memory addressing modes provide flexible access to memory, allowing you to easily access ◦ Variables ◦ Arrays ◦
Low Level Programming Lecturer: Duncan Smeed Overview of IA-32 Part 1.
Types of Registers (8086 Microprocessor Based)
INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
Faculty of Engineering, Electrical Department,
The x86 Architecture Lecture 15 Fri, Mar 4, 2005.
ECE291 Computer Engineering II Lecture 3 Josh Potts University of Illinois at Urbana- Champaign.
Sahar Mosleh California State University San MarcosPage 1 Stack operations, Applications and defining procedures.
Chapter 2 Parts of a Computer System. 2.1 PC Hardware: Memory.
ECE291 Computer Engineering II Lecture 3 Josh Potts University of Illinois at Urbana- Champaign.
1 The Stack and Procedures Chapter 5. 2 A Process in Virtual Memory  This is how a process is placed into its virtual addressable space  The code is.
ECE291 Computer Engineering II Lecture 3 Dr. Zbigniew Kalbarczyk University of Illinois at Urbana- Champaign.
Chapter 2 The Microprocessor Architecture Microprocessors prepared by Dr. Mohamed A. Shohla.
Addressing Modes. Addressing Mode The data is referred as operand. The operands may be contained in registers, memory or I/O ports, within the instruction.
MOV Instruction MOV destination,source  MOV AX,BX  MOV SUM,EAX  MOV EDX,ARRAY[EBX][ESI]  MOV CL,5  MOV DL,[BX]
Assembly Language Data Movement Instructions. MOV Instruction Move source operand to destination mov destination, source The source and destination are.
CSC 221 Computer Organization and Assembly Language Lecture 15: STACK Related Instructions.
Internal Programming Architecture or Model
Intel MP Organization. Registers - storage locations found inside the processor for temporary storage of data 1- Data Registers (16-bit) AX, BX, CX, DX.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
Data Movement Instructions A Course in Microprocessor Electrical Engineering Department Universitas 17 Agustus 1945 Jakarta.
Stack Operations Dr. Hadi AL Saadi.
Credits and Disclaimers
COURSE OUTCOMES OF MICROPROCESSOR AND PROGRAMMING
Instruksi Set Prosesor 8088
ADDRESSING MODES.
Microprocessor and Assembly Language
Microprocessor and Assembly Language
Chapter 4 Data Movement Instructions
Assembly IA-32.
ADDRESSING MODES.
(The Stack and Procedures)
Chapter 3 Addressing Modes
Symbolic Instruction and Addressing
Subject Name: Microprocesor Subject Code: 10CS45
Data Addressing Modes • MOV AX,BX; This instruction transfers the word contents of the source-register(BX) into the destination register(AX). • The source.
8086 Registers Module M14.2 Sections 9.2, 10.1.
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Symbolic Instruction and Addressing
Chapter 3: Addressing Modes
Practical Session 4.
(The Stack and Procedures)
The Microprocessor & Its Architecture
Morgan Kaufmann Publishers Computer Organization and Assembly Language
CNET 315 Microprocessor & Assembly Language
Computer Architecture CST 250
Chapter 6 –Symbolic Instruction and Addressing
(The Stack and Procedures)
CSC 497/583 Advanced Topics in Computer Security
Computer Organization and Assembly Language
Credits and Disclaimers
(The Stack and Procedures)
Presentation transcript:

Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University

STACK Dr. Jia Uddin, CSE, BRAC University

Topics STACK PUSH, POP Procedure CALL and RET Dr. Jia Uddin, CSE, BRAC University

STACK The STACK segment is used for temporary storing data and address. STACK is one dimensional data structure. Items are added and removed from one end of the structure. So it is a “Last In First Out [LIFO]” method. The most recent addition is called the top of stack 8086 allows 64KB segment of memory as STACK. SS contain the base address of the stack segment. SP contain the offset. The 8086 produce physical address for a STACK by adding the offset from SP to the segment base from SS. Dr. Jia Uddin, CSE, BRAC University

3–3 STACK MEMORY-ADDRESSING MODES The stack plays an important role in all microprocessors. – holds data temporarily and stores return addresses used by procedures Stack memory is LIFO (last-in, first-out) memory – describes the way data are stored and removed from the stack Dr. Jia Uddin, CSE, BRAC University

Data are placed on the stack with a PUSH instruction; removed with a POP instruction. Stack memory is maintained by two registers: – the stack pointer (SP or ESP) – the stack segment register (SS) Whenever a word of data is pushed onto the stack, the high-order 8 bits are placed in the location addressed by SP – 1. – low-order 8 bits are placed in the location addressed by SP – 2 Dr. Jia Uddin, CSE, BRAC University

The SP is decremented by 2 so the next word is stored in the next available stack location. – the SP/ESP register always points to an area of memory located within the stack segment. In protected mode operation, the SS register holds a selector that accesses a descriptor for the base address of the stack segment. When data are popped from the stack, the low- order 8 bits are removed from the location addressed by SP. – high-order 8 bits are removed; the SP register is incremented by 2 Dr. Jia Uddin, CSE, BRAC University

Figure 3 – 17 The PUSH and POP instructions: (a) PUSH BX places the contents of BX onto the stack; (b) POP CX removes data from the stack and places them into CX. Both instructions are shown after execution. PUSH AX SS:[SP-1]=AH SS:[SP-2]=AL and SP=SP-2 Dr. Jia Uddin, CSE, BRAC University

STACK SP is automatically decremented by 2 before a word is written to the stack. So, at the beginning SP is initialized to the top of the memory that is assigned for STACK. Initializing STACK: A block of memory is set aside for stack. It is declared by,.STACK 100H Stack pointer is initialized to 100H. Here 100H is the top of STACK. Why is STACK pointer decreased by 2 each time data is put into STACK ? Ans: Since we put Address or contents of Registers into the STACK and both of these two are word [16 bits], we need two consecutive memory locations in the STACK to keep it. So the pointer is changed by 2. Dr. Jia Uddin, CSE, BRAC University

PUSH /POP To add a new word to the STACK use PUSH command Syntax is: PUSH source. Source can be any 16 bit register or memory word For copying the values of FLAG register into the STACK use this command: PUSHF When a PUSH command is executed the following happen:  SP is decreased by 2.  A copy of the source content is moved to the address specified by SS:SP. The source is unchanged. Dr. Jia Uddin, CSE, BRAC University

POP/POPF To remove the top item from STACK we POP it. Syntax is : POP destination Where, destination is 16 bit register or memory word The instruction POPF pops the top of the STACK into the FLAG register. PUSH and POP are word operation [16 bits] So, PUSH DL ; is Illegal since DL is only 8 bits PUSH 2 ; is Illegal POP BL; illegal Dr. Jia Uddin, CSE, BRAC University

PUSH Example Example Empty StackAfter PUSH AX After PUSH BX Dr. Jia Uddin, CSE, BRAC University

POP Example Before POP After POP CXAfter POP DX Example of POP Dr. Jia Uddin, CSE, BRAC University

Procedure Assembly language can be structured as a collection of procedures. One of the procedure is main procedure. To carry out other tasks, main procedure can call one or more other procedures. When one procedure calls another, control is transferred to the called procedure and its instructions are executed. After the called procedure finishes it goes back to the procedure which called it. Syntax is: Name_proc PROC body_of_the_procedure RET Name_proc ENDP A procedure can be called in two ways: Direct Method: CALL name Indirect method: CALL address_expression Fig: Procedure CALL and return Dr. Jia Uddin, CSE, BRAC University

PUSH, POP during Procedure Call When a procedure is called, the return address to the calling program is saved on the stack. This is the offset of the next instruction after the CALL statement. Now, the Instruction Pointer (IP) gets the offset address of the first instruction of the procedure. By this transfer is controlled to the procedure. To return from procedure RET is executed. This restores the IP of the calling procedure from STACK Dr. Jia Uddin, CSE, BRAC University

Example of Procedure CALL and RET Dr. Jia Uddin, CSE, BRAC University

Note that PUSH and POP store or retrieve words of data—never bytes—in and above allow words or doublewords to be transferred to and from the stack. Data may be pushed onto the stack from any 16- bit register or segment register. – in and above, from any 32-bit extended register Data may be popped off the stack into any register or any segment register except CS. Dr. Jia Uddin, CSE, BRAC University

PUSHA and POPA instructions push or pop all except segment registers, on the stack. Not available on early 8086/8088 processors and above allow extended registers to be pushed or popped. – 64-bit mode for Pentium and Core2 does not contain a PUSHA or POPA instruction Dr. Jia Uddin, CSE, BRAC University

SUMMARY The MOV instruction copies the contents of the source operand into the destination operand. The source never changes for any instruction. Register addressing specifies any 8-bit register (AH, AL, BH, BL, CH, CL, DH, or DL) or any 16-bit register (AX, BX, CX, DX, SP, BP, SI, or DI). Dr. Jia Uddin, CSE, BRAC University

SUMMARY The segment registers (CS, DS, ES, or SS) are also addressable for moving data between a segment register and a 16-bit register/memory location or for PUSH and POP. In the through the Core2 microprocessors, the extended registers also are used for register addressing; they consist of EAX, EBX, ECX, EDX, ESP, EBP, EDI, and ESI. (cont.) Dr. Jia Uddin, CSE, BRAC University

SUMMARY In the 64-bit mode, the registers are RAX, RBX, RCX, RDX, RSP, RBP, RDI, RSI, and R8 through R15. The MOV immediate instruction transfers the byte or word that immediately follows the opcode into a register or a memory location. Immediate addressing manipulates constant data in a program. (cont.) Dr. Jia Uddin, CSE, BRAC University

SUMMARY In the and above, doubleword immediate data may also be loaded into a 32-bit register or memory location. The.MODEL statement is used with assembly language to identify the start of a file and the type of memory model used with the file. If the size is TINY, the program exists in the code segment, and assembled as a command (.COM) program. (cont.) Dr. Jia Uddin, CSE, BRAC University

SUMMARY If the SMALL model is used, the program uses a code and data segment and assembles as an execute (.EXE) program. Direct addressing occurs in two forms in the microprocessor: direct addressing and displacement addressing. (cont.) Dr. Jia Uddin, CSE, BRAC University

SUMMARY Both forms of addressing are identical except that direct addressing is used to transfer data between EAX, AX, or AL and memory; displacement addressing is used with any register-memory transfer. Direct addressing requires 3 bytes of memory, whereas displacement addressing requires 4 bytes. (cont.) Dr. Jia Uddin, CSE, BRAC University

SUMMARY Register indirect addressing allows data to be addressed at the memory loca-tion pointed to by either a base (BP and BX) or index register (DI and SI). In the and above, extended registers EAX, EBX, ECX, EDX, EBP, EDI, and ESI are used to address memory data. (cont.) Dr. Jia Uddin, CSE, BRAC University

SUMMARY Base-plus-index addressing often addresses data in an array. The memory address for this mode is formed by adding a base register, index register, and the contents of a segment register times 10H. In the and above, the base and index registers may be any 32-bit register except EIP and ESP. (cont.) Dr. Jia Uddin, CSE, BRAC University

SUMMARY Register relative addressing uses a base or index register, plus a displacement to access memory data. Base relative-plus-index addressing is useful for addressing a two-dimensional memory array. The address is formed by adding a base register, an index register, displacement, and the contents of a segment register times 10H. (cont.) Dr. Jia Uddin, CSE, BRAC University

SUMMARY Scaled-index addressing is unique to the through the Core2. The second of two registers (index) is scaled by a factor of to access words, doublewords, or quadwords in memory arrays. The MOV AX,[ EBX + 2*ECX] and the MOV [4 * ECX ],EDX are examples of scaled-index instructions. (cont.) Dr. Jia Uddin, CSE, BRAC University

SUMMARY Data structures are templates for storing arrays of data and are addressed by array name and field. Direct program memory addressing is allowed with the JMP and CALL instructions to any location in the memory system. With this addressing mode, the off-set address and segment address are stored with the instruction. (cont.) Dr. Jia Uddin, CSE, BRAC University

SUMMARY Relative program addressing allows a JMP or CALL instruction to branch for-ward or backward in the current code segment by bytes. In the and above, the 32-bit displacement allows a branch to any location in the cur-rent code segment by using a displacement value of bytes. The 32-bit displacement can be used only in protected mode. (cont.) Dr. Jia Uddin, CSE, BRAC University

SUMMARY Indirect program addressing allows the JMP or CALL instructions to address another portion of the program or subroutine indirectly through a register or memory location. The PUSH and POP instructions transfer a word between the stack and a register or memory location. A PUSH immediate instruction is available to place immediate data on the stack. (cont.) Dr. Jia Uddin, CSE, BRAC University

SUMMARY The PUSHA and POPA instructions transfer AX, CX, DX, BX, BP, SP, SI, and DI between the stack and these registers. In and above, the extended register and extended flags can also be transferred between registers and the stack. A PUSHFD stores the EFLAGS, whereas a PUSHF stores the FLAGS. POPA and PUSHA are not available in 64-bit mode. Dr. Jia Uddin, CSE, BRAC University