Program execution might be likened to reading a book. While a person will normally read each word and line in sequence, they may at times jump back to an earlier place in the text or skip sections that are not of interest. Similarly, a computer may sometimes go back and repeat the instructions in some section of the program over and over again until some internal condition is met. This is called the flow of control within the program and it is what allows the computer to perform tasks repeatedly without human intervention.
Comparatively, a person using a pocket calculator can perform a basic arithmetic operation such as adding two numbers with just a few button presses. But to add together all of the numbers from 1 to 1,000 would take thousands of button presses and a lot of time, with a near certainty of making a mistake. On the other hand, a computer may be programmed to do this with just a few simple instructions. For example:
mov #0, sum ; set sum to 0 mov #1, num ; set num to 1 loop: add num, sum ; add num to sum add #1, num ; add 1 to num cmp num, #1000 ; compare num to 1000 ble loop ; if num <= 1000, go back to 'loop
halt ; end of program. stop running
Once told to run this program, the computer will perform the repetitive addition task without further human intervention. It will almost never make a mistake and a modern PC can complete the task in about a millionth of a second.
Posting Komentar
Pembaca yang baik selalu meninggalkan jejak . Terima kasih karena telah menggunakan bahasa yang sopan pada form komentar