Unformatted text preview: CSE/EE 5/7385 Microprocessor Architecture and Interfacing Laboratory 3: Arithmetic and Logic instructions This lab covers arithmetic and logic instructions. Feel free to use the reference sheet on the last page for more details. AREA LOGIC, CODE, READONLY ;name the block ENTRY ;mark first instruction ; Registers used in this program ; r0 holds the value of the first operand ; r1 holds the value of the second operand ; r2, r3, r4 hold the results SETR ldr r0, =0x40021018 ldr r1, =0x40011000 ldr r2, =0x00000000 ldr r3, =0x00000000 ldr r4, =0x00000000 ARTMFCT add r2, r0, r1 sub r3, r1, r0 mul r4, r0, r1 add r4, r2, r3 stop B stop END PART 1: Simple programming example Note: You can refer to lab1 and lab2 for steps on how to create a project, a new file, build, debug etc. a-‐ Comment the above program by describing what each instruction does b-‐ Create a new project named logic and a new file logic.s Enter manually the program above with your comments. (Do not just copy and paste) Assemble the program and single-‐step through it. Monitor the content of the registers: r0, r1, r2, r3, r4. Demonstrate your program to the lab instructor PART 2: Arithmetic, Boolean instructions Write the instructions corresponding to the following operations. Use registers r1 and r2 as source registers Use register r3 as destination register Operation 1: 10 + 23 Operation 2: 25 -‐ 10 Operation 3: 10 x 23 Operation 4: r1 Exclusive-‐OR r2 Operation 5: r1 OR r2 1 PART 3: Shifts and rotates Perform the following operations without using the multiply instruction r0 = r1 * 16 (Hint: This is a multiplication by an even number, 16 = 24) r2 = r3 * 9 (Hint: This is a multiplication by an odd number, 9 = 23 + 1) Assemble the program and single-‐step through it. Demonstrate your program to the lab instructor 2 Reference sheet Logical instructions Perform the Boolean operation on the pair of operands, and are useful for bit masking purposes. MOVN: copy value and negate AND: logical AND operation (bit-‐by-‐bit) ORR: logical (inclusive) OR operation (bit-‐by-‐bit) EOR: logical (exclusive) OR operation (bit-‐by-‐bit) BIC: bit clear operation Addition and subtraction ADD: Addition ADC: Addition with Carry – Useful for Multiword Arith (need S flag) SUB: Subtract SBC: Subtract with Carry – Useful for Multiword Arith (need S flag) RSB: Reverse Subtract – Useful for Arithmetic RSC: Reverse Subtract with Carry Shifts and rotates LSL Logical shift left by n bits -‐> Multiplication by 2n LSR Logical shift right by n bits -‐> Unsigned division by 2n ASR Arithmetic shift right by n bits -‐> Signed division by 2n ROR Rotate right by n bits -‐> 32-‐bit rotate RRX Rotate right extended by one bit -‐> 33-‐bit rotate. 33rd bit is Carry Flag Program Status Registers Condition code flags N = Negative result from ALU This flag checks for a negative result Z = Zero result from ALU This flag checks for a zero C = ALU operation Carried out This flag checks for an arithmetic carry or a borrow V = ALU operation overflowed This flag checks for a signed overflow 3 ...
View Full Document
- Fall '08