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

Info iconThis 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…
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
Background 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

This note was uploaded on 04/27/2011 for the course CMPT 150 taught by Professor Dr.anthonydixon during the Spring '08 term at Simon Fraser.

Page1 / 3

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

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

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