Presentation is loading. Please wait.

Presentation is loading. Please wait.

ECE 353 Introduction to Microprocessor Systems Discussion 3.

Similar presentations


Presentation on theme: "ECE 353 Introduction to Microprocessor Systems Discussion 3."— Presentation transcript:

1 ECE 353 Introduction to Microprocessor Systems Discussion 3

2 Topics Subroutines/Stack Frames/Multi- Precision Arithmetic Q & A

3 Problem Write a procedure that multiplies two 64-bit unsigned numbers and returns a 64-bit result in R1:R0. R1 – upper order bits R0 – lower order bits

4 Problem (0). Draw a diagram showing the complete execution of a 64-bit multiplication using 32-bit multiplies and generating a 128-bit result. (Note: We will only use 64- bits of the result.) A B X C D ------------------------------------------------------------------------------------------------------------------------ (B*D)H(B*D)L (A*D)H(A*D)L (B*C)H(B*C)L (A*C)H(A*C)L XX XX R1 R0

5 Problem (1). Write a main code fragment that calls the subroutine (mul64). Use a standard stack frame to pass two double-word parameters to the subroutine. Place them on the stack so that they are in little endian format. Put operand 1 on first. Clean up the stack after the subroutine returns.

6 Problem (1). ; Filename: main5.s ; Author: ECE 353 Staff ; Description: main program file for discussion 6 ARM;use ARM instruction set EXTERN mul64 EXPORT __main AREA FLASH, CODE, READONLY __main ;mul64 exercise MOVR0, #0x00000055;operand1 MSW PUSH{R0} MOVR0, #0xC0000005;operand1 LSW PUSH{R0} MOVR0, #0x000000FF;operand2 MSW PUSH{R0} MOVR0, #0x30000009;operand2 LSW PUSH{R0} BLmul64 ADDSP, #16;cleanup stack B __main END

7 Problem (2). Draw a diagram of the stack at the point when the call is made to mul64. (Note: the stack is drawn as 32-bits in width.)

8 Answer SP -> OP1 MSW OP1 LSW OP2 MSW OP2 LSW

9 Problem (3). Write the complete subroutine that performs 64-bit unsigned multiplication, returning a 64-bit result.64-bit unsigned multiplication Use a standard stack frame to retrieve the source operands. Place the 64-bit result in R1:R0 Allocate space for any temporary storage on the stack frame (do not use registers)(three words needed).

10 Problem (2). ; Filename: mul64.s ; Author: ECE 353 Staff ; Description: Implementation of 64-bit multiply function ARM;use ARM instruction set EXPORT mul64 AREA FLASH, CODE, READONLY ; Name: mul64 ; Description: 64 x 64 unsigned multiply ; Assumes: Arguments pushed on stack in little-endian form ; first pushed - 64-bit operand1 ; second pushed - 64-bit operand2 ; Returns: R1:R0 - 64-bit product (truncated) ; Modifies: None mul64 END

11 (2). mul64 PUSH{R11,LR};context save MOVR11, R13;get frame pointer SUBR13, R13, #12;allocate local variable space ;B*D LDRR0, [R11, #16];get operand1 LSW (B) LDRR1, [R11, #8];get operand2 LSW (D) UMULLR0, R1, R0, R1;BDH:BDL in R1:R0 STRR1, [R11, #-4];BDH to temp1 (local) STRR0, [R11, #-8];BDL to temp2 (local) ;A*D LDRR0, [R11, #8];get operand2 LSW (D) LDRR1, [R11, #20];get operand1 MSW (A) MULR0, R0, R1;R0 = ADL STRR0, [R11, #-12];ADL to temp3 (local) ;B*C LDRR0, [R11, #16];get operand1 LSW (B) LDRR1, [R11, #12];get operand2 MSW (C) MULR1, R0, R1;R1 = BCL ;add up MSW of result LDRR0, [R11, #-12];get temp3 (ADL) ADDR1, R1, R0;R1 = BCL + ADL LDRR0, [R11, #-4];get temp1 (BDH) ADDR1, R1, R0;R1 = BCL + ADL + BDH LDRR0, [R11, #-8];get temp2 (BDL) ;cleanup and exit ADDR13, R13, #12;deallocate local variable space mul64_exit POP{R11,PC};restore context and return END

12 Problem (4). Update the drawing in part (2) to reflect the total stack frame used by the subroutine.

13 Answer SP -> OP1 MSW OP1 LSW OP2 MSW OP2 LSW SP -> FP -> [FP + 20] [FP + 16] [FP + 12] [FP + 8] [FP - 4] [FP - 8] [FP - 12] R14 R11 temp1 temp2 temp3

14 Questions?

15


Download ppt "ECE 353 Introduction to Microprocessor Systems Discussion 3."

Similar presentations


Ads by Google