ECE 353 Introduction to Microprocessor Systems Week 6

  • Slides: 15
Download presentation
ECE 353 Introduction to Microprocessor Systems Week 6 Michael G. Morrow, P. E.

ECE 353 Introduction to Microprocessor Systems Week 6 Michael G. Morrow, P. E.

Objectives Procedures n n n Types Nesting Context Save/Restore Assembling/Linking Multiple Source Files Parameter

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

Procedures Why? Syntax n PROC / ENDP CALL / RET Operation CALL types n

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

Procedures Nesting and Single Module Programs n Example and stack operation Context Save /

Procedures Nesting and Single Module Programs n Example and stack operation Context Save / Restore n n n Caller vs. procedure Course documentation requirements PUSH / POP balance and order Testing & Debugging Procedures n n n Interface Implementation Integration

Multiple File Assembly/Linking Each assembly source file is assembled independently – linker then joins

Multiple File Assembly/Linking Each assembly source file is assembled independently – linker then joins together. How to make it all work… n n n EXTRN directive PUBLIC directive GLOBAL directive Segment COMBINE types Addressability issues TASM/TLINK commands Example source code n wk 6 main. asm wk 6 proc. asm

Parameter Passing Register Passing Memory Passing Using Pointer Parameters n Example Stack Passing n

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

Arithmetic Operands Unsigned Binary Integers w Byte w Word w Double-word Signed Binary Integers

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

Unsigned Arithmetic Operations Most also used for signed arithmetic Mnemonic Operands Function O S

Unsigned Arithmetic Operations Most also used for signed arithmetic Mnemonic Operands Function O S Z A P C ADD dst, src Addition ADC INC dst, src Add with carry dst Increment by 1 - SUB SBB DEC CMP MUL DIV dst, src Subtraction dst, src Subtract with borrow dst Decrement by 1 - dst, src Compare src Unsigned multiplication ? ? src Unsigned division ? ? ?

Signed Arithmetic Operations All signed numbers represented in 2’scomplement format Can use the general

Signed Arithmetic Operations All signed numbers represented in 2’scomplement format Can use the general math operations discussed for unsigned numbers, plus some specific signed arithmetic instructions… Mnemonic Operands Function O S Z A P C NEG dst Negate - - - CBW CWD none Convert byte to word ? ? ? ? none Convert word to double word - - - IMUL IDIV src Integer multiplication ? ? src Integer division ? ? ?

BCD Arithmetic Operations Unpacked BCD Packed BCD AAA AAS AAM AAD DAA DAS Use

BCD Arithmetic Operations Unpacked BCD Packed BCD AAA AAS AAM AAD DAA DAS Use Inherent Operands Mnemonic Function O S Z A P C ASCII adjust for addition ? ? ? ? ASCII adjust for subtraction ? ? ? ? ASCII adjust for multiplication ? ? ? ASCII adjust for division ? ? ? Decimal adjust for addition Decimal adjust for subtraction

Numeric Conversions BCD Binary n n Convenient relationship between bit groups and digits Hexadecimal

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

Wrapping Up Exam 1 will be held on Thursday, October 18, 2001 from 7:

Wrapping Up Exam 1 will be held on Thursday, October 18, 2001 from 7: 15 to 8: 45 PM in 132 Noland

w k 6 m a i n. a s m . 186 assume cs:

w k 6 m a i n. a s m . 186 assume cs: code, ss: stck, ds: data extrn My. Proc: PROC public g. Var stck tos stck segment db 256 dup (? ) label word ends ; 256 byte stack ; top of stack data g. Var data segment public db 0 ends ; define variable code segment public main: mov ax, data mov ds, ax mov ax, stck mov ss, ax mov sp, offset tos main_loop: call My. Proc jmp main_loop code ends end main ; DS addressability ; SS addressability ; initialize sp ; call external proc ; code entry point

w w kk 66 pp rr oo c. c. aa ss m m .

w w kk 66 pp rr oo c. c. aa ss m m . 186 assume cs: code, ds: data global My. Proc: PROC global g. Var: BYTE data segment public ; empty segment for assume directive data ends code segment public ; need procedure comment header! My. Proc proc inc g. Var ret My. Proc endp code ends end ; don't define another code entry point!

TASM/TLINK Commands tasm /l /zi wk 6 main tasm /l /zi wk 6 proc

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