Let's discuss, compare and jump instructions in this video.
So far, we have written our programs in assembly language to demonstrate compassion and jump instructions.
I have written a very simple SI program named Jump Si.
So let's take a look at the program.
I have saved this file inside the direct card siempre Dasht Jambi.
Inside this I have a file called Jump Dart.
See, it's a very simple SI program.
If you observe the program, it's a simple program with if ands condition.
Let's go from the beginning.
First we have initialized to variables.
Variable error is initialized with value tool and the variable B is initialized with value.
Three if is equal to be, the statement will be executed and the string is equal to be will be printed.
If these two are not equal, the jump will be taken to this block and the string is not equal to be
will be executed.
This is all fine and easy to understand in C language.
Let's see what is happening behind the scenes by going through the assembly version of this program
using Jilib.
Let's first compile this program and using GTC jump dot c bargepole jump.
We should now have the binary jump, we can check that using less there you go.
Now let's open it up using GDB and I'm going to set up a breakpoint at the entry point of this program.
And the entry point of this program is going to be the main function.
So type Jalabi dot slash jump.
And let's set up a breakpoint at Main.
There you go.
Now let us run the program and let us go through the disassembly.
I'm typing right here it is.
This is the disassembly that we are going to execute now.
Currently, we are inside the main function.
Now, let's quickly do our business men to see the full view of the disassembly.
Here it is.
This is the complete main function here.
Let's execute this program until we reach this instruction.
We can either set up a breakpoint here or we can type site multiple times.
Let me die type ASI.
All right, so we have reached this instruction.
We are currently at Maine plus 12, if you closely observe the next instruction to be executed, it
is placing the value to onto the stack.
We can spot that by looking at the register are B in the instruction.
So let's step aside and observe the stack.
If you examine the stack before executing this instruction, the value to doesn't exist on the stack.
So let's step aside and look at that.
The value of two is currently placed on the stack.
Now once again, the next instruction to be executed is placing the value tree on the stack.
So I'm typing aside once again and let's observe what happens on the stack after executing this instruction.
Look at that, the value tree is actually placed on the stack as well.
Look at that, the value tree is now placed on the stack as well.
OK, next instruction.
If you observe the next instruction to be executed, once again, it is referencing a value that's available
on the stack, if you notice the value that it is looking for is are B, B minus zero X eight, which
is essentially this, which means the value to.
So it is moving the value to into the register X..
So let's first check the value of our X.
Currently, this is the value of Addicks, if you say it should contain the value to let's say let's
go back and check X.
Dirigo Artex register now contains the value to now let's move on to the next instruction, the next
instruction is comparing the value available in extra stir with some value that's available on the stack.
If you notice this R, B, B, minus zero X four.
Here it is, which means 063 is what it is comparing it against.
So the X is currently holding two and the value of three is currently available on the stack.
And this assembly program is basically checking if these two values are equal or not.
And this instruction is comparing those two values.
In the C program we were doing a comparison by doing if A equals to be in assembly, the instruction
CMB is used for comparisons.
So essentially two is being compared with three.
And based on the result of this instruction, the control will be transferred into some location using
the next instruction, which is Jayanthi.
We will come to this Jaynie instruction in a bit.
Let's first step aside and hit enter.
Now if you look at the zero flag, it is not set when sampi instruction gets executed.
It essentially makes a subtraction of these two values.
When you do two minus three, the result is non-zero.
If there isn't, a zero zero flag will be set.
If the flag is set, you should see this word zero in uppercase.
Since the flag is not that you are seeing it in the lowercase, but if you look at the same flag, this
is set because two minus three is going to produce a negative sign.
Now, what we are interested in is the next instruction, which is Jayanthi.
Since these are not equal, we are going to take a jump to some location.
Obviously that is the case.
We will come here and execute this conditional jump.
Instructions are usually followed by a comparison instruction because this takes a jump based on a specific
condition and that's usually set by Campi instruction.
So simply instruction in this case did a comparison between the value to entry.
And since the result was not zero, it did not set zero flag.
And you can see this here as well.
And the reason it shows here is this jump is taken because zero flag is not set.
Now let's check with this jump is taken to let us take this jump by typing assign.
And if you notice, there is a call to Prenter function soon after executing two more instructions,
but before that, but before that, there is an instruction which is LTA idea and some address.
LTA instruction is Lord effective address.
When this instruction gets executed, the contents of the memory location are not loaded, only the
effective addresses is computer and placed into the register.
In this case, a clear instruction moves that effective address into audio register.
So let's first check what we have at this address.
So I'm just copying this slash piece and I'm just pasting it here.
Look at that.
We have the string is not equal to be at this address.
So this address is pointing to the string that's about to be printed.
So why is it being moved to RBI?
That's because in 1964, with architecture, the arguments are loaded into to register.
This printer function that is about to be executed contains one argument, and the first argument always
gets loaded into the RBA register.
And that's exactly why this is getting loaded into this idea register before we execute this printer
function.
So let's say and if you check the RBA register, it contains an address that's pointing to this string
right now.
Let's say there is a call instruction, which is basically going to execute the printf function.
So if we type Essi, it is going to get into the print definition.
And if you type C to continue with the execution, it is going to print is not equal to B after completing
the execution of print function.
Now we have briefly discussed how arguments are past when a function is executed in this video.
But in the next video, we are going to discuss more details about how arguments are managed when a
function call is made.
The idea behind this video is to show you the CMB and conditional jump instructions.
That's all for this video.
See you in the next one.