lecture27 - LOOP ABA INCB MPB TWENTY CMPB BLE LOOP CMPT 150...

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

View Full Document Right Arrow Icon
CMPT 150 Assembly Language Page 1 Loop Example Let’s convert the following C program into assembly: // declare and initialize static variables int i, sum = 0; // compute sum of the integers 1 to 20 main() { for (i=1; i <= 20); i++) sum += i; } CMPT 150 Assembly Language Page 2 General Form for Loops prepare for first iteration initialize loop induction variable LOOP execute inner-block of loop prepare for next iteration increment induction variable, check loop condition branch to beginning of loop first statement following loop CMPT 150 Assembly Language Page 3 Loop Example ; Example 2, Sum the first 20 integers and ; store the result in an area in memory ORG $0000 SUM DS.B 1 ; reserve space for final answer ZERO DC.B 0 ; area in memory holding value 0 TWENTY DC.B 20 ; value decimal 20 ORG $0800 ENTRY LDAA ZERO LDAB #1 CMPT 150 Assembly Language Page 4 Loop Example - cont’d… LOOP
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: LOOP ABA INCB MPB TWENTY CMPB BLE LOOP CMPT 150 Assembly Language Page 5 Loop Example - cont’d… STAA SUM STOP ORG $FFFE DC.B ENTRY ; reset vector - bytes FFFE and ; FFFF to address of first ; instruction to be executed CMPT 150 Assembly Language Page 6 Assembly Example Let’s convert the following C program into assembly: int x=3, y=2, z; main() { if (x < y) z = 1; else z = 0; } CMPT 150 Assembly Language Page 7 General Form of If-Then-Else perform test and store result branch to ELSE if condition is false THEN “ then ” sequence of instructions … JMP EIF ELSE “ else ” sequence of instructions … EIF remainder of program … CMPT 150 Assembly Language Page 8 Program in Assembly CMPT 150 Assembly Language Page 9 Program in Assembly - cont’d…...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern