MGMT 1000 Lecture Notes - Lecture 18: Mnemonic
MGMT 1000 Tutorial 18 Notes – Branches and Loops
Introduction
• Instructions of this type are used to perform branches and loops.
• As an example, consider the following WHILE-DO loop, common to many programming
languages: WHILE Value = 0 DO Task
• Next Statement
• This loop could be implemented using the Little Man BRANCH instruction as follows.
• Assume that these instructions are located starting at mailbox number 45 (comments
are provided to the right of each line)
• 45 LDA 90 590 90 is assumed to contain value 46 BRZ 48 748
• Branch if the value is zero 47 BR 60 660 Exit loop
• Jump to Next Statement 48
• This is where the task is located 59 BR 45 645 End to Task
• Loop to test again 60
• EXAMPLE
• Here is an example of a Little Man program that uses the BRANCH instructions to alter
the flow of the program.
• This program finds the positive difference between two numbers (sometimes known as
the absolute magnitude of the difference).
• For convenience, we are introducing a set of abbreviations for each instruction.
• These areiatios are ko as eois the first is silet. Oe you lear to
read these eois, youll fid that progras ritte ith eois are geerally
easy to read.
• It is more common to write programs this way.
• For a while, we will continue to print both the mnemonic and the code.
• Eventually, we will stop printing the code.
• Most programs are also written with comments, which help to clarify the code.
• The mnemonic instructions that we will use are shown
find more resources at oneclass.com
find more resources at oneclass.com