ECE 353 Introduction to Microprocessor Systems Michael J. Schulte Week 6.

Slides:



Advertisements
Similar presentations
Assembly Language for x86 Processors 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy this slide.
Advertisements

Introduction to Computer Engineering by Richard E. Haskell BCD Arithmetic Module M16.5 Section 10.4.
ECE 353 Introduction to Microprocessor Systems Michael G. Morrow, P.E. Week 6.
Assembly Programming Notes for Practical2 Munaf Sheikh
SOFTWARE ARCHITECTURE OF THE 8088 AND 8086 MICROPROCESSORS
Department of Computer Science and Software Engineering
ACOE2511 Assembly Language Arithmetic and Logic Instructions.
Procedures and Stacks. Outline Stack organization PUSH and POP instructions Defining and Calling procedures.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, MUL Instruction The MUL (unsigned multiply) instruction.
8086 Assembly Language Programming I
Gursharan Singh Tatla 21-Nov-20101www.eazynotes.com.
8086 : INSTRUCTION SET By, Pramod Sunagar Assistant Professor
Assembly Language for Intel-Based Computers Chapter 5: Procedures Kip R. Irvine.
© 2006 Pearson Education, Upper Saddle River, NJ All Rights Reserved.Brey: The Intel Microprocessors, 7e Chapter 5 Arithmetic and Logic Instructions.
9-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
ICS312 Set 11 Introduction to Subroutines. All the combinations in which a subroutine can be written 1. The subroutine may be: a. Internal or b. External.
Assembly Language – Lab 5
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
Introduction to Subroutines. All the combinations in which a subroutine can be written 1. The subroutine may be: a. Internal or b. External 2. The type.
Flag Control instructions CLC clear carry flag CF = 0 STC set carry flag CF= 1 CMC complement carry flag [CF] CF.
Debug and Assembler By, B.R.Chandavarkar Lect. COMP Department NITK, Surathkal.
Introduction to 8086 Assembly Language Assembly Language Programming University of Akron Dr. Tim Margush.
ASCII and BCD Arithmetic Chapter 11 S. Dandamudi.
Chapter four – The 80x86 Instruction Set Principles of Microcomputers 2015年10月19日 2015年10月19日 2015年10月19日 2015年10月19日 2015年10月19日 2015年10月19日 1 Chapter.
Multiplication and Division Instructions & the 0Ah function.
The x86 PC Assembly Language, Design, and Interfacing By Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey © 2010, 2003, 2000, 1998 Pearson.
Today’s topics Procedures Procedures Passing values to/from procedures Passing values to/from procedures Saving registers Saving registers Documenting.
Strings, Procedures and Macros
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 4 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Executing and Linking an assembly program. Lesson plan Review Program logic and control Practice exercise Assembling, Linking and Executing Programs Practice.
1 IKI10230 Pengantar Organisasi Komputer Kuliah no. 05.b: Arithmetic Operations Sumber: 1. Paul Carter, PC Assembly Language 2. Hamacher. Computer Organization,
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
Writing and using procedures
ECE 353 Introduction to Microprocessor Systems Michael G. Morrow, P.E. Week 6.
Assembly Language for Intel-Based Computers, 4 th Edition Unpacked and Packed Integers (c) Pearson Education, All rights reserved. You may modify.
ECE 353 Introduction to Microprocessor Systems Michael G. Morrow, P.E. Week 7.
Arithmetic and Logic Instructions
Review of Assembly language. Recalling main concepts.
Microprocessor & Assembly Language Arithmetic and logical Instructions.
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures.
SOFTWARE ARCHITECTURE OF THE 8088 AND 8086 MICROPROCESSORS
Assembly language programming
Format of Assembly language
Chapter Nov-2010
Data Transfers, Addressing, and Arithmetic
Assembly Language programming
16.317: Microprocessor System Design I
BYTE AND STRING MANIPULATON
8086 Microprocessor.
Chapter instruction description and assembler directives from Microprocessors and Interfacing by Douglas Hall.
Microprocessor and Assembly Language
Microprocessor and Assembly Language
EE3541 Introduction to Microprocessors
(The Stack and Procedures)
4.2 Arithmetic Instructions
X86’s instruction sets.
Introduction to Assembly Language
Chapter 4: Instructions
Programming 8086 – Part IV Stacks, Macros
ارايه دهنده : حسن عسكرزاده
Microprocessor and Assembly Language
(The Stack and Procedures)
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Chapter 5 Arithmetic and Logic Instructions
Assembler Directives end label end of program, label is entry point
(The Stack and Procedures)
Chapter 8: Instruction Set 8086 CPU Architecture
Introduction to 8086 Assembly Language
Computer Architecture and System Programming Laboratory
Procedures and Macros.
Presentation transcript:

ECE 353 Introduction to Microprocessor Systems Michael J. Schulte Week 6

Procedures Types Nesting Context Save/Restore Assembling/Linking Multiple Source Files Parameter Passing Register, Memory, Stack Pointers Arithmetic Operands Instructions Topics

Procedures Why? Syntax PROC / ENDP CALL / RET Operation CALL types Intrasegment  IP relative  Indirect Intersegment  Direct  Indirect RET types

Procedures Nesting and Single Module Programs Example and stack operation Context Save / Restore Protocols Course documentation requirements PUSH / POP balance and ordering  Keep it simple and uniform Testing & Debugging Procedures Software Interface Implementation Integration

Multiple File Assembly/Linking Each assembly source file is assembled independently – linker then joins together. How to make it all work… EXTRN directive PUBLIC directive GLOBAL directive Segment COMBINE types Addressability issues TASM/TLINK commandscommands Example source code good versionbetter version good versionbetter version

Parameter Passing Register Passing Memory Passing Using Pointer Parameters Exercise Stack Passing Reentrant procedures Using a stack frame Parameters Local variables Example ENTER / LEAVE

Arithmetic Operands Unsigned Binary Integers  Byte  Word  Double-word Signed Binary Integers  Byte  Word  Double-word Unpacked BCD Packed BCD Arithmetic Overflow Multi-precision Operations

Unsigned Arithmetic Operations Most also used for signed arithmetic MnemonicOperandsFunction OSZAPC ADD dst, srcAddition  ADC dst, srcAdd with carry  INC dstIncrement by 1  - SUB dst, srcSubtraction  SBB dst, srcSubtract with borrow  DEC dstDecrement by 1  - CMP dst,srcCompare  MUL srcUnsigned multiplication  ????  DIV srcUnsigned division??????

Signed Arithmetic Operations All signed numbers represented in 2’s- complement format Can use the general math operations discussed for unsigned numbers, plus some specific signed arithmetic instructions… MnemonicOperandsFunction OSZAPC NEG dstNegate CBW noneConvert byte to word???  ?  CWD noneConvert word to double word IMUL srcInteger multiplication  ????  IDIV srcInteger division??????

BCD Arithmetic Operations Unpacked BCD Packed BCD Mnemonic Use Inherent Operands Function OSZAPC AAA ASCII adjust for addition???  ?  AAS ASCII adjust for subtraction???  ?  AAM ASCII adjust for multiplication?  ?  ? AAD ASCII adjust for division?  ?  ? DAA Decimal adjust for addition  DAS Decimal adjust for subtraction 

Numeric Conversions BCD to Binary Conversion Convenient relationship between bit groupings and digits Hexadecimal to binary conversion is similar, but now have to account for all digits 0-9 and A-F (a-f) Binary to Decimal Conversion No convenient relationship between bit groupings and digits Repeated subtraction Division/modulus

Exercise Write a procedure mul32 to do a 32-bit multiplication with a 32-bit result. Operands are to be passed using a standard stack frame, ensuring that they are in little-endian form in memory when they are on the stack. Any temporary storage must be allocated on the stack. Return the result in DX:AX.

Wrapping Up Reading for next week Chapter 10,

;need file header!.186 assume cs:code, ss:stck stcksegment db 256 dup (?);256 byte stack toslabel word stck ends codesegment ;need procedure header! procedure1proc callprocedure2 ret procedure1endp ;need procedure header! procedure2proc ret procedure2endp start:movax, stck;SS addressability movss, ax movsp, offset tos;initialize sp main_loop: callprocedure1 jmp main_loop codeends endstart wk6ex1.asmwk6ex1.asm

.186 assume cs:code, ss:stck, ds:data extrn MyProc:PROC public gVar stcksegment db 256 dup (?);256 byte stack toslabel word;top of stack stck ends datasegment public gVardb 0;define variable dataends codesegment public main:mov ax, data;DS addressability mov ds, ax mov ax, stck;SS addressability mov ss, ax mov sp, offset tos;initialize sp main_loop: call MyProc;call external proc jmp main_loop codeends endmain;code entry point wk6main.asmwk6main.asm

wk6proc.asmwk6proc.asm.186 assume cs:code, ds:data global MyProc:PROC global gVar:BYTE datasegment public ;empty segment for assume directive dataends codesegment public ;need procedure comment header! MyProcproc inc gVar ret MyProcendp codeends end ;don't define another code entry point! wk6proc.asmwk6proc.asm

globals.inc ; Filename: globals.inc ; Author: ECE 353 Staff ; Description: Week 6 example of include file global MyProc:PROC global gVar:BYTE

.186 assume cs:code, ss:stck, ds:data include globals.inc stcksegment db 256 dup (?);256 byte stack toslabel word;top of stack stck ends datasegment public gVardb 0;define variable dataends codesegment public main:mov ax, data;DS addressability mov ds, ax mov ax, stck;SS addressability mov ss, ax mov sp, offset tos;initialize sp main_loop: call MyProc;call external proc jmp main_loop codeends endmain;code entry point wk6main1.asmwk6main1.asm

wk6proc1.asmwk6proc1.asm.186 assume cs:code, ds:data include globals.inc datasegment public ;empty segment for assume directive dataends codesegment public ;need procedure comment header! MyProcproc inc gVar ret MyProcendp codeends end ;don't define another code entry point!

TASM/TLINK Commands tasm /l /zi wk6main tasm /l /zi wk6proc tlink /v wk6main wk6proc (the executable file will have the same name as the first object file, so in this case the linker will create wk6main.exe) OR tlink /v wk6main wk6proc, wk6 (the executable file will be named wk6.exe)

Pointer Parameter Exercise i. Define a variable length data structure where the first word is the number of words of data that follow. ii. Write a procedure that finds the maximum value in the array, assuming that the data is unsigned. iii. Assume that the starting address of the data structure is passed in BX. iv. Return the result in AX. Assume addressability and stack initialization have been correctly handled.

Stack Frame Example Write code for a main program that uses a stack frame to call a procedure Update - parameter words X,Y, data are to be pushed in that order. Draw a word-wide stack, indicating the objects placed on it by the caller. Write a stub Update procedure - assume the procedure must use 2 words of local variables Set up the stack frame, Show how you would access the 3 passed parameters, Show how you would access the 2 local variable words, Clean up the stack frame, and Return. Update the stack diagram, indicating how it is used/allocated by the procedure.