24-Example - Example Suppose that R0 contains the base...

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

View Full Document Right Arrow Icon
Example Suppose that R0 contains the base address of an array of an array of n bytes Translate this code into assembly int sum = 0; for (int i = 0; i < n; i++) sum += A[i]; 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
Example int R3 = 0; for (R5 = 0; R5 < n; R5++) R3 += A[R5]; 2 int sum = 0; for (int i = 0; i < n; i++) sum += A[i];
Background image of page 2
Example int R3 = 0; for (R5 = 0; R5 < n; R5++) R3 += A[R5]; 3 LD R3, #0 LD R5, #0 LD R6, #n loop: SUB R7, R6, R5 BZ R7, end ADD R1, R0, R5 LD R2, (R1) ADD R3, R3, R2 ADD R5, R5, #1 JMP loop end: HALT int sum = 0; for (int i = 0; i < n; i++) sum += A[i];
Background image of page 3

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

View Full DocumentRight Arrow Icon
Example int R3 = 0; for (R5 = 0; R5 < n; R5++) R3 += A[R5]; 4 LD R3, #0 LD R5, #0 LD R6, #n loop: SUB R7, R6, R5 BZ R7, end ADD R1, R0, R5 LD R2, (R1) ADD R3, R3, R2 ADD R5, R5, #1 JMP loop end: HALT int R3 = 0; for (R5 = 0; R5 < n; R5++) { if (A[R5] > 0) R3 += A[R5]; }
Background image of page 4
Example int R3 = 0; for (R5 = 0; R5 < n; R5++) R3 += A[R5]; 5 LD R3, #0 LD R5, #0 LD R6, #n loop: SUB R7, R6, R5 BZ R7, end ADD R1, R0, R5 LD R2, (R1) ADD R3, R3, R2 ADD R5, R5, #1
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/19/2011 for the course CS 231 taught by Professor - during the Spring '08 term at University of Illinois at Urbana–Champaign.

Page1 / 12

24-Example - Example Suppose that R0 contains the base...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online