{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

hw4_D06_sol - ECE 3803 Microprocessor System Design D Term...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
ECE 3803: Microprocessor System Design D Term 2005 Homework 4 -- Solutions 1. In signal processing applications, one often needs to multiple complex quantities. Write a C function to perform multiplication of the form E + jF = (A + jB)(C + jD) where A,B,C and D are 16 bit signed integers and in the result E and F are 32-bit signed integers. Your functions should accepts values for A,B,C&D and return E and F. ( Hint : There is no need to represent imaginary number, j in your code just calculate E and F). You may ignore overflow. Also write a simple main program that calls your function and displays the results. Use a 16 bit compiler (i.e. MS DOS compatible compiler) such as Turbo C (tcc), Pacific C or even MS Windows Driver Development Kit (CL.EXE and LINK.EXE) to compile and run the program. Show a listing of the assembler code produced for the C function and fully describe how the parameters are passed the function (i.e. in registers and/or on the stack) and how the result is returned . To assemble with tcc use the -S command option. In Pacific C, choose the assemble option from the compile menu [20 pts] Using Turbo C 3.0 ifndef ??version ?debug macro endm $comm macro name,dist,size,count comm dist name:BYTE:count*size endm else $comm macro name,dist,size,count comm dist name[size]:BYTE:count endm endif ?debug S "hw4_tc.c" ?debug C E939689B34086877345F74632E63 _TEXT segment byte public 'CODE' _TEXT ends DGROUP group _DATA,_BSS assume cs:_TEXT,ds:DGROUP _DATA segment word public 'DATA' [email protected] label byte [email protected] label word _DATA ends _BSS segment word public 'BSS' [email protected] label byte [email protected] label word _BSS ends _TEXT segment byte public 'CODE' ; ; int cplxmul(int re1, int im1, int re2, int im2, long *re, long *im) ; assume cs:_TEXT _cplxmul proc near push bp mov bp,sp
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
push si push di ; arguments passed to cplxmul on stack mov si,word ptr [bp+4] ; a = re1 mov di,word ptr [bp+6] ; b = im1 mov cx,word ptr [bp+8] ; c = re2 ; ; { ; ; (*re) = re1*re2 - im1*im2; // Real part of product ; mov ax,si ; ax = a imul cx ; ax * cx = a*c push ax mov ax,di imul word ptr [bp+10] ; b*d mov dx,ax pop ax sub ax,dx cwd mov bx,word ptr [bp+12] mov word ptr [bx+2],dx ; Push double word e = a*c - b*d mov word ptr [bx],ax ; ; (*im) = re1*im2 + im1*re2; // Imaginary part ; mov ax,si imul word ptr [bp+10] push ax mov ax,di imul cx mov dx,ax pop ax add ax,dx cwd mov bx,word ptr [bp+14] mov word ptr [bx+2],dx ; Push double word f = a*d + b*c mov word ptr [bx],ax ; ; ; return 0; ; xor ax,ax ; set return values stat = 0 (in ax) jmp short @[email protected] @[email protected]: ; ; } ;
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}