1 / 22

ECE 353 Introduction to Microprocessor Systems

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

irisa
Download Presentation

ECE 353 Introduction to Microprocessor Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

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

  4. 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

  5. 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 commands • Example source code • good versionbetter version

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

  7. 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

  8. Unsigned Arithmetic Operations • Most also used for signed arithmetic

  9. 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…

  10. BCD Arithmetic Operations • Unpacked BCD • Packed BCD

  11. 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

  12. 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.

  13. Wrapping Up • Reading for next week • Chapter 10, 10.1-10.6

  14. ;need file header! .186 assume cs:code, ss:stck stck segment db 256 dup (?) ;256 byte stack tos label word stck ends code segment ;need procedure header! procedure1 proc call procedure2 ret procedure1 endp ;need procedure header! procedure2 proc ret procedure2 endp start: mov ax, stck ;SS addressability mov ss, ax mov sp, offset tos ;initialize sp main_loop: call procedure1 jmp main_loop code ends end start wk6ex1.asm

  15. .186 assume cs:code, ss:stck, ds:data extrn MyProc:PROC public gVar stck segment db 256 dup (?) ;256 byte stack tos label word ;top of stack stck ends data segment public gVar db 0 ;define variable data ends code segment 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 code ends end main ;code entry point wk6main.asm

  16. wk6proc.asm .186 assume cs:code, ds:data global MyProc:PROC global gVar:BYTE data segment public ;empty segment for assume directive data ends code segment public ;need procedure comment header! MyProc proc inc gVar ret MyProc endp code ends end ;don't define another code entry point! wk6proc.asm

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

  18. .186 assume cs:code, ss:stck, ds:data include globals.inc stck segment db 256 dup (?) ;256 byte stack tos label word ;top of stack stck ends data segment public gVar db 0 ;define variable data ends code segment 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 code ends end main ;code entry point wk6main1.asm

  19. .186 assume cs:code, ds:data include globals.inc data segment public ;empty segment for assume directive data ends code segment public ;need procedure comment header! MyProc proc inc gVar ret MyProc endp code ends end ;don't define another code entry point! wk6proc1.asm

  20. 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)

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

  22. 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.

More Related