Invitation to Computer Science 8th Edition

Published by Cengage Learning
ISBN 10: 1337561916
ISBN 13: 978-1-33756-191-4

Chapter 6 - 6.3 - Assemblers and Assembly Language - Practice Problem - Page 299: 1e

Answer

\begin{array}{llll} & LOAD & ZERO & --Put\ 0\ in\ R \\ & STORE & SUM & --Initialize\ SUM\ to\ 0 \\ & STORE & I & --Initialize\ loop\ counter\ to 0 \\ LOOP: & LOAD & FIFTY & --Put\ 50\ in\ R \\ & COMPARE & I & \\ & JUMPEQ & DONE & --I\ equals\ 50,\ exit\ loop \\ & LOAD & SUM & --Put\ SUM\ in\ R \\ & ADD & I & --R\ now\ holds\ (SUM + I) \\ & STORE & SUM & --Store\ result\ in\ SUM \\ & INCREMENT & I & --Add\ 1\ to\ I \\ & JUMP & LOOP & --end\ of\ loop\ body \\ DONE: & & & --the\ next\ statement\ goes\ here \\ & . & & \\ & . & & \\ & . & & \\ I: & DATA & 0 & \\ SUM: & .DATA & 0 & \\ ZERO: & .DATA & 0 & \\ FIFTY: & .DATA & 50 & \end{array}

Work Step by Step

\begin{array}{llll} & LOAD & ZERO & --Put\ 0\ in\ R \\ & STORE & SUM & --Initialize\ SUM\ to\ 0 \\ & STORE & I & --Initialize\ loop\ counter\ to 0 \\ LOOP: & LOAD & FIFTY & --Put\ 50\ in\ R \\ & COMPARE & I & \\ & JUMPEQ & DONE & --I\ equals\ 50,\ exit\ loop \\ & LOAD & SUM & --Put\ SUM\ in\ R \\ & ADD & I & --R\ now\ holds\ (SUM + I) \\ & STORE & SUM & --Store\ result\ in\ SUM \\ & INCREMENT & I & --Add\ 1\ to\ I \\ & JUMP & LOOP & --end\ of\ loop\ body \\ DONE: & & & --the\ next\ statement\ goes\ here \\ & . & & \\ & . & & \\ & . & & \\ I: & DATA & 0 & \\ SUM: & .DATA & 0 & \\ ZERO: & .DATA & 0 & \\ FIFTY: & .DATA & 50 & \end{array}
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.