# computer engineering.

Alkhawaa

1. (30 points total, 5 points each) We have learned in the class (see lecture 18) that using the barrel shifter, we can implement

multiplication/division of a number for some special cases with addition, subtraction, and reversed subtraction. Write the assembly code to perform the following calculations using this approach assuming signed integers A and B are saved in r0 and r1, respectively.

a. A=16*B b. A=17*B c. A=15*B d. A=B/16 e. A=17*B/16 f. A=15*B/16

2. (70 points) We have learned the following in the class:

1. LDR with immediate offset: 2. LDR with pre-indexed offset: 3. LDR with post-indexed offset: 4. LDR with register offset:

LDR Rt, [Rn, #offset] LDR Rt, [Rn, #offset]! LDR Rt, [Rn], #offset LDR Rt, [Rn, Rm, shift]

Now, we practice these instructions here with the given program snippets below: Part A: C code:

// Functions defined in a .s file extern void task1(uint8_t *pIpt, uint32_t *pOup); extern void task2(uint8_t *pIpt, uint32_t *pOup); extern void task3(uint8_t *pIpt, uint32_t *pOup); extern void task4(uint8_t *pIpt, uint32_t *pOup, int i);

// Global variable uint8_t ipt[16]; // Input data uint32_t opt[4]; // Output data

int main(void) { for (int i = 0; i < 16; i++) {

ipt[i] = i<<4; }

// Task 1. task1(ipt, opt); printf("Out1 = 0x%X, Out2 = 0x%X\n", opt[0], opt[1]);

// Task 2. task2(ipt, opt); printf("Out1 = 0x%X, Out2 = 0x%X\n", opt[0], opt[1]);

// Task 3. task3(ipt, opt); printf("Out1 = 0x%X, Out2 = 0x%X\n", opt[0], opt[1]);

// Task 4. task4(ipt, opt, 1); printf("Out1 = 0x%X, Out2 = 0x%X\n", opt[0], opt[1]);

while (1);

}

Part B: asm code

EXPORT task1 EXPORT task2 EXPORT task3 EXPORT task4

ALIGN ; Align the data in the boundary of 4 bytes.

task1 PROC LDR r2, [r0, #4] STR r2, [r1, #0] LDR r2, [r0, #0xC] STR r2, [r1, #4] BX lr ENDP

task2 PROC LDR r2, [r0, #4]! STR r2, [r1, #0] LDR r2, [r0, #4]! STR r2, [r1, #4] BX lr ENDP

task3 PROC LDR r2, [r0], #4 STR r2, [r1, #0] LDR r2, [r0], #4 STR r2, [r1, #4] BX lr ENDP

task4 PROC LDR r3, [r0, r2, LSL #2] STR r3, [r1, #0] ADD r2, #1 LDR r3, [r0, r2, LSL #2] STR r3, [r1, #4] ADD r2, #1 BX lr ENDP

Answer the following questions (without running the program first):

a. (10 points) What will be the print out after Task 1? b. (15 points) What will be the print out after Task 2 and what will be the values in r0 and r1 in hexadecimal after running

Task 2 assuming their values are 0x20001010 and 0x20001040, respectively when the function is called? c. (15 points) What will be the print out after Task 3 and what will be the values in r0 and r1 in hexadecimal after

running Task 3 assuming their values are 0x20001010 and 0x20001040, respectively when the function is called? d. (15 points) What will be the print out after Task 4 and what will be the values in r2 and r3 in hexadecimal after running

Task 4? e. (15 points) What will be the corresponding C code for each task?

3. (20 points) We have learned in the class that for signed numbers, we have the following mapping between the relationship testing and condition flags (page 5 in lecture notes for lctr160) :

Determine the mapping between the relationship testing and condition flags for unsigned numbers.