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 Problems - Page 307: 1

Answer

$\begin{array}{llll} {\text { }} & {\text {.BEGIN} } & {\text { } } & {\text { } }\\ {\text { }} & {\text {CLEAR} } & {\text {NEGCOUNT} } & {\text {--Step 1. Not really necessary} }\\ {\text { }} & {\text { } } & {\text { } } & {\text {--because} }\\ {\text { }} & {\text { } } & {\text { } } & {\text {--negcount is already set to 0} }\\ {\text { }} & {\text {LOAD} } & {\text {ONE} } & {\text {--Step 2. Set i to 1. Also not} }\\ {\text { }} & {\text { } } & {\text { } } & {\text {--really} }\\ {\text { }} & {\text {STORE} } & {\text {T} } & {\text {--necessary because i is} }\\ {\text { }} & {\text { } } & {\text { } } & {\text {--initialized to 1} }\\ {\text {LOOP:}} & {\text {LOAD} } & {\text {FIFTY} } & {\text {--Step 3. Check whether i . 50} }\\ {\text { }} & {\text { } } & {\text { } } & {\text {--and if so} }\\ {\text { }} & {\text { } } & {\text { } } & {\text {--terminate the loop} }\\ {\text { }} & {\text {COMPARE} } & {\text {I} } & {\text { } }\\ {\text { }} & {\text {JUMPGT} } & {\text {ENDLOOP} } & {\text { } }\\ {\text { }} & {\text {IN} } & {\text {N} } & {\text {--Step 4. Read a value} }\\ {\text { }} & {\text {LOAD} } & {\text {ZERO} } & {\text {--Step 5. Increment} }\\ {\text { }} & {\text { } } & {\text {FIFTY} } & {\text {--negcount if} }\\ {\text { }} & {\text {COMPARE} } & {\text {N} } & {\text {--N is less than zero} }\\ {\text { }} & {\text {JUMPGE} } & {\text {SKIP} } & {\text { } }\\ {\text { }} & {\text {INCREMENT} } & {\text {NEGCOUNT} } & {\text { } }\\ {\text {SKIP:}} & {\text {INCREMENT} } & {\text {I} } & {\text {--Step 6. Count one more} }\\ {\text { }} & {\text { } } & {\text { } } & {\text {--loop iteration} }\\ {\text { }} & {\text {JUMP} } & {\text {LOOP} } & {\text {--Step 7. and start the loop} }\\ {\text { }} & {\text { } } & {\text { } } & {\text {--over} }\\ {\text {ENDLOOP:}} & {\text {OUT} } & {\text {NEGCOUNT} } & {\text {--Step 8. Produce the final} }\\ {\text { }} & {\text { } } & {\text { } } & {\text {--answer} }\\ {\text { }} & {\text {HALT} } & {\text { } } & {\text {--Step 9. and halt} }\\ {\text {NEGCOUNT:}} & {\text {.DATA} } & {\text {0} } & {\text { } }\\ {\text {I:}} & {\text {.DATA} } & {\text {1} } & {\text { } }\\ {\text {N:}} & {\text {.DATA} } & {\text {0} } & {\text { } }\\ {\text {ONE:}} & {\text {.DATA} } & {\text {1} } & {\text { } }\\ {\text {FIFTY:}} & {\text {.DATA} } & {\text {50} } & {\text { } }\\ {\text {ZERO:}} & {\text {.DATA} } & {\text {0} } & {\text { } }\\ {\text {}} & {\text {.END} } & {\text { } } & {\text { } }\\ \end{array}$

Work Step by Step

$\begin{array}{llll} {\text { }} & {\text {.BEGIN} } & {\text { } } & {\text { } }\\ {\text { }} & {\text {CLEAR} } & {\text {NEGCOUNT} } & {\text {--Step 1. Not really necessary} }\\ {\text { }} & {\text { } } & {\text { } } & {\text {--because} }\\ {\text { }} & {\text { } } & {\text { } } & {\text {--negcount is already set to 0} }\\ {\text { }} & {\text {LOAD} } & {\text {ONE} } & {\text {--Step 2. Set i to 1. Also not} }\\ {\text { }} & {\text { } } & {\text { } } & {\text {--really} }\\ {\text { }} & {\text {STORE} } & {\text {T} } & {\text {--necessary because i is} }\\ {\text { }} & {\text { } } & {\text { } } & {\text {--initialized to 1} }\\ {\text {LOOP:}} & {\text {LOAD} } & {\text {FIFTY} } & {\text {--Step 3. Check whether i . 50} }\\ {\text { }} & {\text { } } & {\text { } } & {\text {--and if so} }\\ {\text { }} & {\text { } } & {\text { } } & {\text {--terminate the loop} }\\ {\text { }} & {\text {COMPARE} } & {\text {I} } & {\text { } }\\ {\text { }} & {\text {JUMPGT} } & {\text {ENDLOOP} } & {\text { } }\\ {\text { }} & {\text {IN} } & {\text {N} } & {\text {--Step 4. Read a value} }\\ {\text { }} & {\text {LOAD} } & {\text {ZERO} } & {\text {--Step 5. Increment} }\\ {\text { }} & {\text { } } & {\text {FIFTY} } & {\text {--negcount if} }\\ {\text { }} & {\text {COMPARE} } & {\text {N} } & {\text {--N is less than zero} }\\ {\text { }} & {\text {JUMPGE} } & {\text {SKIP} } & {\text { } }\\ {\text { }} & {\text {INCREMENT} } & {\text {NEGCOUNT} } & {\text { } }\\ {\text {SKIP:}} & {\text {INCREMENT} } & {\text {I} } & {\text {--Step 6. Count one more} }\\ {\text { }} & {\text { } } & {\text { } } & {\text {--loop iteration} }\\ {\text { }} & {\text {JUMP} } & {\text {LOOP} } & {\text {--Step 7. and start the loop} }\\ {\text { }} & {\text { } } & {\text { } } & {\text {--over} }\\ {\text {ENDLOOP:}} & {\text {OUT} } & {\text {NEGCOUNT} } & {\text {--Step 8. Produce the final} }\\ {\text { }} & {\text { } } & {\text { } } & {\text {--answer} }\\ {\text { }} & {\text {HALT} } & {\text { } } & {\text {--Step 9. and halt} }\\ {\text {NEGCOUNT:}} & {\text {.DATA} } & {\text {0} } & {\text { } }\\ {\text {I:}} & {\text {.DATA} } & {\text {1} } & {\text { } }\\ {\text {N:}} & {\text {.DATA} } & {\text {0} } & {\text { } }\\ {\text {ONE:}} & {\text {.DATA} } & {\text {1} } & {\text { } }\\ {\text {FIFTY:}} & {\text {.DATA} } & {\text {50} } & {\text { } }\\ {\text {ZERO:}} & {\text {.DATA} } & {\text {0} } & {\text { } }\\ {\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.