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: 2

Answer

$\begin{array}{llll} {\text { }} & {\text {.BEGIN} } & {\text { } } & {\text { } }\\ {\text { }} & {\text {IN} } & {\text {NUMBER } } & {\text {--get first number } }\\ {\text {LOOP:}} & {\text {LOAD} } & {\text {ZERO} } & {\text { } }\\ {\text { }} & {\text {COMPARE} } & {\text {NUMBER} } & {\text {--see whether number < 0} }\\ {\text { }} & {\text {JUMPLT} } & {\text {DONE} } & {\text {--the number is negative so} }\\ {\text { }} & {\text { } } & {\text { } } & {\text {--go to DONE} }\\ {\text { }} & {\text {INCREMENT} } & {\text {COUNT} } & {\text {--it is nonnegative so} }\\ {\text { }} & {\text {} } & {\text { } } & {\text {--increment count} }\\ {\text { }} & {\text {IN} } & {\text {NUMBER} } & {\text {--get next number} }\\ {\text { }} & {\text {JUMP} } & {\text {LOOP} } & {\text {--and repeat the loop} }\\ {\text {DONE:}} & {\text {OUT} } & {\text {COUNT} } & {\text {--print out the final count} }\\ {\text { }} & {\text {HALT} } & {\text { } } & {\text { } }\\ {\text {COUNT:}} & {\text {.DATA} } & {\text {0} } & {\text {--count of number of} }\\ {\text { }} & {\text { } } & {\text { } } & {\text {--nonnegative values} }\\ {\text {ZERO:}} & {\text {.DATA} } & {\text {0} } & {\text {--the constant 0 used for} }\\ {\text { }} & {\text { } } & {\text { } } & {\text {--comparison} }\\ {\text {NUMBER:}} & {\text {.DATA} } & {\text {0} } & {\text {--place to store the input} }\\ {\text { }} & {\text { } } & {\text { } } & {\text {--value} }\\ {\text { }} & {\text {.END} } & {\text { } } & {\text { } }\\ \end{array}$

Work Step by Step

$\begin{array}{llll} {\text { }} & {\text {.BEGIN} } & {\text { } } & {\text { } }\\ {\text { }} & {\text {IN} } & {\text {NUMBER } } & {\text {--get first number } }\\ {\text {LOOP:}} & {\text {LOAD} } & {\text {ZERO} } & {\text { } }\\ {\text { }} & {\text {COMPARE} } & {\text {NUMBER} } & {\text {--see whether number < 0} }\\ {\text { }} & {\text {JUMPLT} } & {\text {DONE} } & {\text {--the number is negative so} }\\ {\text { }} & {\text { } } & {\text { } } & {\text {--go to DONE} }\\ {\text { }} & {\text {INCREMENT} } & {\text {COUNT} } & {\text {--it is nonnegative so} }\\ {\text { }} & {\text {} } & {\text { } } & {\text {--increment count} }\\ {\text { }} & {\text {IN} } & {\text {NUMBER} } & {\text {--get next number} }\\ {\text { }} & {\text {JUMP} } & {\text {LOOP} } & {\text {--and repeat the loop} }\\ {\text {DONE:}} & {\text {OUT} } & {\text {COUNT} } & {\text {--print out the final count} }\\ {\text { }} & {\text {HALT} } & {\text { } } & {\text { } }\\ {\text {COUNT:}} & {\text {.DATA} } & {\text {0} } & {\text {--count of number of} }\\ {\text { }} & {\text { } } & {\text { } } & {\text {--nonnegative values} }\\ {\text {ZERO:}} & {\text {.DATA} } & {\text {0} } & {\text {--the constant 0 used for} }\\ {\text { }} & {\text { } } & {\text { } } & {\text {--comparison} }\\ {\text {NUMBER:}} & {\text {.DATA} } & {\text {0} } & {\text {--place to store the input} }\\ {\text { }} & {\text { } } & {\text { } } & {\text {--value} }\\ {\text { }} & {\text {.END} } & {\text { } } & {\text { } }\\ \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.