what can I do?

what does the word 'branch' mean in computer language?

I am studying C/C++ from a book and the book wants me to make a program which is called 'build your own computer' it gives me some clues to achieve the task.

here operation codes that the book wants me to use(the book gives me as a clue)
I did all write this on my code and created their functions(for their own tasks).
However doesn't matter how I tried, because of that I didn't understand the word 'branch' I couldn't create its function. So can anyone help me??
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  /* Input-Output operations*/

#define READ 10     //  Read a word from the terminal into a specific location in memory.
#define WRITE 11    //  Write a word from a specific location in memory to the terminal.

/* Load-Store operations*/

#define LOAD 20     //  Load a word from a specific location in memory into the accumulator.
#define STORE 21    //  Store a word from the accumulator into a specific location in memory.

/* Arithmetic operations*/

#define ADD 30         //  Add a word from a specific location in memory to the word in the accumulator (leave result in accumulator).
#define SUBTRACT 31    //  Subtract a word from a specific location in memory from the word in the accumulator (leave result in accumulator).
#define DIVIDE 32      //  Divide a word from a specific location in memory into the word in the accumulator (leave result in accumulator).
#define MULTIPLY 33    //  Multiply a word from a specific location in memory by the word in the accumulator (leave result in accumulator).

/* Transfer of control operations*/

#define BRANCH 40       //  Branch to a specific location in memory.
#define BRANCHNEG 41    //  Branch to a specific location in memory if the accumulator is negative.
#define BRANCHZERO 42   //  Branch to a specific location in memory if the accumulator is zero.
#define HALT 43         //  Halt—i.e., the program has completed its task. 
Last edited on
branch in english means several things, one of them, the limb of a tree.
So you have a shape like a Y on its side, sort of, if you see what I mean. This visual will help a little below.

In a computer program (or the hardware), a branch is a block of code that runs after a condition, or the condition itself.
1
2
3
4
5
6
7
8
9
if (something)
{
   code
}

else
{
  other code
}


the "if (something)" statement creates a branch.. or a 'fork in the road' scenario where the code can go 'left' or 'right'.

1
2
3
4
                     
                     / true: do 'code'
something____________
                     \false: do 'other code 


and that is all they are saying. So in usage, "the code branches at line 20" would indicate the condition itself, and "you can see in the 'true' branch that there is a bug here..." would indicate the code inside the condition. So it can mean either the junction where the code chooses a path or one of the paths, depending on the context of the rest of the words around it.

#define of constants is avoided in modern C++. If that is what the teacher provided, its fine, or how you were told to do it, fine, but be aware that it is bad practice because the value loses its strong typing in a macro.

If you want a lot more words than I used try
https://press.rebus.community/programmingfundamentals/chapter/branching-statements/#:~:text=A%20branch%20is%20an%20instruction,continue%20%2C%20return%20%2C%20and%20goto%20.

or do your own search on 'what is branch in computer science'
Last edited on
In the terms of your operation codes, consider branch as 'goto'. You change the value of the pc (program counter - the address of the operation in memory that is currently being executed) either unconditionally to the new specified value or if an expected condition is fulfilled to a new location otherwise don't.
What is a branch in computer science (wikipedia):

https://en.wikipedia.org/wiki/Branch_(computer_science)
thank you guys
Topic archived. No new replies allowed.