Stack, Procedures and Macros Computer Structure and Organization Graduated in We so few registers the i8086 has, it's needed to save used registers
Previous PDF | Next PDF |
[PDF] Macros and Procedures
Overview A macro is a named block of assembly language statements The CALL instruction calls a procedure by directing the processor to begin execution
[PDF] Chapter 5 - Strings, Procedures and Macros from Microprocessors
The PUSH register/memory instruction decrements the stack pointer by 2 and copies he contents of the specified 16-bit register or memory location to memory at
[PDF] Procedure and Macro (16 marks) - SNJB
2) Far call or Inter Segment call Operation for Near Call : When 8086 executes a near CALL instruction, it decrements the stack pointer by 2 and copies the IP
[PDF] UNIT-2 8086 ASSEMBLY LANGUAGE PROGRAMMING
MICROPROCESSORS AND MICROCONTROLLERS Procedures and macros 8086 The 8086 instructions are categorized into the following main types (i)
[PDF] 8086 Assembler Manual - Ceibo
MACRO PROCESSOR LANGUAGE CHAPTER 8 RECOMMENDATIONS FOR GETTING STARTED (TASK4 ) Figure 0-1 Structure of This Manual 8086
[PDF] Procedure and Macro in Assembly Language - WordPresscom
Topic 6: Procedure and Macro in Assembly Language Program(16 Marks) This option uses the processor registers to hold the data that will be used by the procedure, it emu8086 inc is a good example of how macros can be used, this file
[PDF] UNIT-1 THE 8086 MICROPROCESSOR - Shree Sathyam College of
memory locations or stack which calls macro 7 What is the purpose of segment registers in 8086? [April/May2017, April/May2008, Nov/Dec 2006, 2011]
[PDF] Lesson 4 Stack, Procedures and Macros
Stack, Procedures and Macros Computer Structure and Organization Graduated in We so few registers the i8086 has, it's needed to save used registers
[PDF] SRI VENKATESWARA COLLEGE OF ENGINEERING AND
UNIT I THE 8086 MICROPROCESSOR The two independent functional parts of the 8086 CPU are: i Macros are defined by MACRO ENDM directives
[PDF] MAHALAKSHMI ENGINEERING COLLEGE TIRUCHIRAPALLI
What do you mean by pipelining in an 8086 processor?[NOV/DEC 2006] Creating macro is similar to creating new opcodes that can be used in the program
[PDF] macy's billing
[PDF] macy's card discount exclusions
[PDF] macy's credit card application status
[PDF] macy's credit card grace period
[PDF] macy's credit card late payment
[PDF] macy's credit card minimum payment
[PDF] macy's credit card over limit fee
[PDF] macy's credit card phone number
[PDF] macy's employee discount 2019
[PDF] macy's employee discount exclusions
[PDF] macy's employee prepaid card
[PDF] macy's friends and family 2020
[PDF] macy's friends and family coupon
[PDF] macy's friends and family fragrance
Curso 2010-2011
Lesson 4. Stack, Procedures and Macros
Computer Structure and Organization
Graduated in Computer Sciences /
Graduated in Computer Engineering
Computer Structure and Organization Graduated in Computer Sciences / Graduated in Computer Engineering Automatic Department
Lesson 4: Stack, Procedures and Macros
Slide.:
2 / 25
Computer Structure and Organization Graduated in Computer Sciences / Graduated in Computer Engineering Automatic Department
Contents
Bit instructions The stack How to define procedures Type of procedures: NEAR y FAR How to pass parameters to a procedure:
- Registers - The Stack Structures and parameters passing Macros Procedures vs. MacrosLesson 4: Stack, Procedures and Macros
Slide.:
3 / 25
Computer Structure and Organization Graduated in Computer Sciences / Graduated in Computer Engineering Automatic Department
Bit instructions (I)
Mnemonic: TEST Format: TEST target, source Description: This funtion is a logical AND over source and target. The differences
is that the result is not stored in anywhere. This instruction only modifies flags register bits. Example: ; AX = 1234, BX = 0000 TEST AX, BX ; AX =1234, BX = 0000, Result = 0000 JZ Es_Cero ; IF Zero jumps to Es_Cero label
Lesson 4: Stack, Procedures and Macros
Slide.:
4 / 25
Computer Structure and Organization Graduated in Computer Sciences / Graduated in Computer Engineering Automatic Department
Bit instructions (II)
Mnemonic: CLI Format: CLI Description: Disable masked interrupts handling. Unmasked interrupt can not be disabled Example: - CLI
Lesson 4: Stack, Procedures and Macros
Slide.:
5 / 25
Computer Structure and Organization Graduated in Computer Sciences / Graduated in Computer Engineering Automatic Department
Bit instructions (III)
Mnemonic: STI Format: STI Description: Enable interrupts handling Example: - STILesson 4: Stack, Procedures and Macros
Slide.:
6 / 25
Computer Structure and Organization Graduated in Computer Sciences / Graduated in Computer Engineering Automatic Department
Bit instructions (IV)
Mnemonic: CLC Format: CLC Description: Carry flag is set to zero Example: - CLCLesson 4: Stack, Procedures and Macros
Slide.:
7 / 25
Computer Structure and Organization Graduated in Computer Sciences / Graduated in Computer Engineering Automatic Department
Bit instructions (V)
Mnemonic: STC Format: STC Description: Carry flag is set to one Example: - STCLesson 4: Stack, Procedures and Macros
Slide.:
8 / 25
Computer Structure and Organization Graduated in Computer Sciences / Graduated in Computer Engineering Automatic Department
Bit instructions (VI)
Mnemonic: CLD Format: CLD Description: Direction flag is set to zero (used by string instructions) Example: - CLD
Lesson 4: Stack, Procedures and Macros
Slide.:
9 / 25
Computer Structure and Organization Graduated in Computer Sciences / Graduated in Computer Engineering Automatic Department
Bit instructions (and VII)
Mnemonic: STD Format: STD Description: Direction flag is set to one (used by string instructions) Example: - STD
Lesson 4: Stack, Procedures and Macros
Slide.:
10 / 25
Computer Structure and Organization Graduated in Computer Sciences / Graduated in Computer Engineering Automatic Department
The Stack
Portion of memory that handles return addresses of procedures and interrupt services LIFO structure (Last In First Out) SS and SP are dedicate registers to point to the top of the stack Each stack position is 16 bits length The stack increases to lower memory positions addresses with PUSH The stack decreases to upper memory positions addresses with POP STACKLesson 4: Stack, Procedures and Macros
Slide.:
11 / 25
Computer Structure and Organization Graduated in Computer Sciences / Graduated in Computer Engineering Automatic Department
Definición de procedimientos Procedures group instructions and allow to call them from different parts of the program without need to repeat them
To call a procedure: CALL Last instruciton of a procedure: RET Return address of the procedure is stored on the stacl. Segment
address the procedure belongs to is also stored on the stack if the type of the procedure is FAR To define a procedure folloing directives are used: PROC (begin of the procedure) y ENDP (end of the procedure)Lesson 4: Stack, Procedures and Macros
Slide.:
12 / 25
Computer Structure and Organization Graduated in Computer Sciences / Graduated in Computer Engineering Automatic Department
Types of procedures Procedures have the following attributes: FAR (if it will be called from a different segment it belongs to) or NEAR (call is within the same segment)
Main Procedure is always FAR (implícit) PrintString PROC FAR ; this procedure calls to 9h DOS MOV AH, 09h ; services to display a character string on the INT 21h ; string whose address is stored on DS:DX RET ; return of the procedure PrintString ENDP Ejemplo de definición de un procedimiento
Lesson 4: Stack, Procedures and Macros
Slide.:
13 / 25
Computer Structure and Organization Graduated in Computer Sciences / Graduated in Computer Engineering Automatic Department
How to pass parameters to a procedure by using registers General purpose registers are used to pass and to recieve paramenters and results from a procedure
We so few registers the i8086 has, it's needed to save used registers by the procedure before calling it First set of instructions in a procedure must store on the stack all the registers that will be used in it. Before returning from procedure save registers must be restored. All of them except those in which results will be returnedLesson 4: Stack, Procedures and Macros
Slide.:
14 / 25
Computer Structure and Organization Graduated in Computer Sciences / Graduated in Computer Engineering Automatic Department
How to pass parameters to a NEAR PROCEDURE. The stack (I)Actions performed by CALLER procedure
Parameters offset or variables themselves are in the same segment so it will be stored on the stackStack Structure
Caller Procedure: MOV AX, VARIABLE1 PUSH AX LEA AX, VARIABLE2 PUSH AXCALL Nombre_Proc
IP (returning address) Offset VARIABLEn Offset Variable2 Offset Variable1Lesson 4: Stack, Procedures and Macros
Slide.:
15 / 25
Computer Structure and Organization Graduated in Computer Sciences / Graduated in Computer Engineering Automatic Department
How to pass parameters to a NEAR PROCEDURE. The stack (II)Actions performed by CALLED procedure
1. BP register is stored on the stack (PUSH BP) BP will be used to
access parameters.2. BP must point to SP (MOV BP, SP) 3. Parameters are recovered from the stack by using BP. The i
parameter offset will be: [BP] + 4 + 2 · (n - i)Estructura de la pila CALLER procedure: Name_Proc PROC PUSH BP MOV BP,SP PUSH [used registers] MOV AX,[BP+4] ;VARIABLEn ... MOV BX,[BP+4+2 · (n-i)] BP register IP (returning address) Offset VARIABLEn
Offset Variable2
Offset Variable1
Lesson 4: Stack, Procedures and Macros
Slide.:
16 / 25
Computer Structure and Organization Graduated in Computer Sciences / Graduated in Computer Engineering Automatic Department
How to pass parameters to a NEAR PROCEDURE. The stack (and III)Actions performed by CALLED procedure
RET parameter indicates the stack positions to be removed when returning from CALLED procedure. This number will be 2xnumber of passed parameters. E.g. RET 8 if four parameters have been passed
CALLED proceure: POP [used registers] POP BP RET 2·n Name_Proc ENDP Stack structure BP register IP (returning address) Offset VARIABLEnOffset Variable2
Offset Variable1
Lesson 4: Stack, Procedures and Macros
Slide.:
17 / 25
Computer Structure and Organization Graduated in Computer Sciences / Graduated in Computer Engineering Automatic Department
How to pass parameters to a FAR PROCEDURE. The stack (I)Actions to be performed by CALLER procedure
Variables offset and segment must be stored on the stack because CALLER and CALLED procedures belongs to different memory segmentesCALLER procedure: LEA AX, VARIABLE1 PUSH DS PUSH AX LEA AX, VARIABLE2 PUSH DS PUSH AX ... CALL PROCEDIMIENTO
Lesson 4: Stack, Procedures and Macros
Slide.:
18 / 25
Computer Structure and Organization Graduated in Computer Sciences / Graduated in Computer Engineering Automatic Department
How to pass parameters to a FAR PROCEDURE. The stack (and II)Actions performed by CALLED procedure
• BP register is stored on the stack (PUSH BP) BP will be used to access parameters.• BP must point to SP (MOV BP, SP) • Parameters are recovered from the stack by using BP. The i
parameter offset will be: [BP] + 4 + 2 (n - i) and the segment whose belongs to: [BP] + 8 + 4 · (n - i)RET parameter of the CALLED procedure: RET parameter indicates the stack positions to be removed when
returning from CALLED procedure. This number will be 4xnumber of passed parameters. E.g. RET 16 if four parameters have been passed
Lesson 4: Stack, Procedures and Macros
Slide.:
19 / 25
Computer Structure and Organization Graduated in Computer Sciences / Graduated in Computer Engineering Automatic Department
Structs and parameters passing (I) Structures
Structures will be defined with followin directives: STRUC (start of structure) and ENDS (ends of structure) Group different type and size data with a single name StructureName.Field will be uses to access to structure records RET argument and parameter passing can be easy by using
structuresDNI STRUC Name_and_Surname DB 50 DUP ('0') Address DB 60 DUP ('0') Age DB 0 Profession DB 15 DUP ('0') DNI ENDS
Lesson 4: Stack, Procedures and Macros
Slide.:
20 / 25
Computer Structure and Organization Graduated in Computer Sciences / Graduated in Computer Engineering Automatic Department
Structs and parameters passing (II) Structure code and records for parameters passign to a NEAR procedure:
Estructura STRUC bp0 DW ? ; 2 bytes for storing BP return DW ? ; It's equivalent to a +2 bytes offset from the bebining of the ; structure (first DW named bp0) p2 DW ? ; It's equivalent to a +4 bytes offset from the beginning of the ; structure (DW + return) P1 DW ? ; It's equivalent to a +6 bytes offset from the beginning of the ; structure (DW + return + p2) Estructura ENDS NRET EQU OFFSET p1 - OFFSET retorn
Lesson 4: Stack, Procedures and Macros
Slide.:
21 / 25
Computer Structure and Organization Graduated in Computer Sciences / Graduated in Computer Engineering Automatic Department
Structs and parameters passing (and III) Actions performed by NEAR CALLED procedure1. BP register is stored on the stack (PUSH BP) BP will be used to
access parameters.2. BP must point to SP (MOV BP, SP) 3. Accessing to parameters with BP and the structure 4. RET argument will be NRET
CALLED procedure Prueba PROC NEAR PUSH BP MOV BP, SP PUSH AX MOV AX, [BP].p1 ADD [BP].p2, AX POP AX POP BP RET NRET Prueba ENDP Example of previous defined structure
Estructura struc bp0 DW ? retorno DW ? p2 DW ? p1 DW ? Estructura ends NRET EQU OFFSET p1 - OFFSET retorno
Lesson 4: Stack, Procedures and Macros
Slide.:
22 / 25
Computer Structure and Organization Graduated in Computer Sciences / Graduated in Computer Engineering Automatic Department
MACROS
MACROS are names given to some pieces of code Code expansion instead of jumping is done Extra parameters will be ignored if passed. So have
instructions that likely use them Mind the labels inside a macro Labels must be local inside the macro codeLesson 4: Stack, Procedures and Macros
Slide.:
23 / 25
Computer Structure and Organization Graduated in Computer Sciences / Graduated in Computer Engineering Automatic Department
Las macros (II)
Mnemonic: MACRO Format: macro_name MACRO parameter_list Description: name and parameters to be passed to the macro
are defined. Parameter names are separated by commas. The end of a macro definition is specified using ENDM directive without writing macro name
Nombre y Format: ENDM Description: to establish the end of a macro definition Example: Add_three MACRO operand1, operand2, result ;macro body ENDM
Lesson 4: Stack, Procedures and Macros
Slide.:
24 / 25
Computer Structure and Organization Graduated in Computer Sciences / Graduated in Computer Engineering Automatic Department
Las macros (III)
Mnemonic: LOCAL Format: LOCAL label,[label,...] Description: indicate label names to be changed whenexpending a macro. This method solves duplicate label names. Must be used after macro definition line and only use it on macros
Example: Delay MACRO number local go_on mov cx, number go_on: loop go_on ENDMLesson 4: Stack, Procedures and Macros
Slide.:
25 / 25
Computer Structure and Organization Graduated in Computer Sciences / Graduated in Computer Engineering Automatic Department