1 00:00:00,310 --> 00:00:01,990 And now that's it. 2 00:00:02,110 --> 00:00:05,600 We have completed our program and it's running, as you can see. 3 00:00:05,650 --> 00:00:09,820 We just have some like, uh, three typos here. 4 00:00:10,210 --> 00:00:16,190 As you can see here in line 7109 and 135. 5 00:00:16,210 --> 00:00:21,120 So in order already fix that and just the regular typos here like a. 6 00:00:22,490 --> 00:00:28,730 Are as all Thai here, like the 1 or 2 keyword typos I fixed it with here. 7 00:00:28,730 --> 00:00:29,570 Now it's fixed. 8 00:00:29,570 --> 00:00:30,950 As you can see, it's running. 9 00:00:30,980 --> 00:00:33,230 I also, uh, the. 10 00:00:34,360 --> 00:00:36,070 Publish the fixed one here. 11 00:00:36,070 --> 00:00:37,410 That is not a big deal. 12 00:00:37,420 --> 00:00:44,650 Now, in this lecture, what you're going to learn is you will learn all of the registers and the. 13 00:00:45,650 --> 00:00:50,210 I will explain all of the things that we did in this code here. 14 00:00:50,210 --> 00:00:55,100 And as you can see, it's almost 150 lines of code. 15 00:00:55,280 --> 00:00:56,300 So. 16 00:00:57,580 --> 00:01:01,750 Now let's start from the assembly. 17 00:01:04,610 --> 00:01:10,790 The start from the increment here because we already explained the previously code. 18 00:01:10,820 --> 00:01:13,010 Here before the increment. 19 00:01:14,790 --> 00:01:16,710 So here we have increment, right? 20 00:01:16,710 --> 00:01:17,490 So. 21 00:01:18,680 --> 00:01:21,860 We are using the as a first assembly here. 22 00:01:21,860 --> 00:01:24,740 We are using the this instruction here. 23 00:01:24,740 --> 00:01:30,650 This instruction moves the value stored in the memory location referred as number one into the Rax register 24 00:01:30,650 --> 00:01:35,270 and it's loading the value of number one into the register for manipulation. 25 00:01:35,270 --> 00:01:41,150 And I see here this is the instruction here. 26 00:01:41,180 --> 00:01:48,380 This increments the value in the rax register by one, and in this case it's incrementing the value 27 00:01:48,380 --> 00:01:50,450 of number one by one. 28 00:01:50,450 --> 00:01:56,060 Here, as you can see here, it was 1 to 8 and now it's 129. 29 00:01:56,060 --> 00:01:56,630 Right. 30 00:01:56,720 --> 00:02:04,250 And here we also have move result i rax this is this instruction moves the value in the rax register 31 00:02:04,250 --> 00:02:11,690 which now holds the incremented value to the memory location pointed to by result i and it stores the 32 00:02:11,690 --> 00:02:13,940 result of increment operation. 33 00:02:14,120 --> 00:02:17,750 And here we are displaying the results in this case. 34 00:02:17,870 --> 00:02:18,720 So. 35 00:02:19,760 --> 00:02:26,330 The RDA register is loaded with the memory address of the format string fmt integer. 36 00:02:26,330 --> 00:02:32,510 So this string will be used in the printf function to format the output. 37 00:02:32,630 --> 00:02:38,090 And we also have the RSI and C here in C. 38 00:02:38,480 --> 00:02:43,940 So this RSI register is loaded with the memory address of the message string in C here. 39 00:02:43,940 --> 00:02:50,600 So this message will be used in the printf function to provide context for the displayed result. 40 00:02:50,600 --> 00:02:52,640 I want to also here. 41 00:03:00,510 --> 00:03:01,530 As you can see, it's tradition. 42 00:03:01,530 --> 00:03:02,700 Number one, incremented. 43 00:03:03,630 --> 00:03:08,840 And also we have move the result. 44 00:03:08,880 --> 00:03:14,970 I hear the RDX register is loaded with the value stored in the memory location pointed to by result 45 00:03:15,000 --> 00:03:15,180 I. 46 00:03:15,210 --> 00:03:22,140 So this value represents the result of the incremented operation increment operation and we have the 47 00:03:22,140 --> 00:03:31,440 move rax and this instruction sets the value of Rax register to zero and it prepares Rax to be used 48 00:03:31,440 --> 00:03:36,750 as the return value when the printf function call is complete. 49 00:03:36,750 --> 00:03:42,420 And this instruction calls the printf function to display the formatted message and the arguments for 50 00:03:42,420 --> 00:03:48,870 the printed functions are loaded into the RTI, RSI and RDX registers. 51 00:03:48,870 --> 00:03:52,710 And we also have the incrementing here. 52 00:03:52,710 --> 00:03:58,980 So similar to before, this instruction moves the value stored in memory location reference by number 53 00:03:58,980 --> 00:04:05,470 one into the Rax register and it's loading the value of number one into the register for manipulation. 54 00:04:05,470 --> 00:04:10,630 And we have the D a C here. 55 00:04:11,760 --> 00:04:18,390 So the the the instruction decrements the value in the rax register by one. 56 00:04:18,390 --> 00:04:23,220 And in this case it's decrementing the value of number one. 57 00:04:23,670 --> 00:04:30,510 And we lastly, we have the result i rax mov result i rax this instruction moves the value in the rax 58 00:04:30,510 --> 00:04:38,070 register register which now holds the decremented value to the memory location pointed to by result 59 00:04:38,100 --> 00:04:42,570 i and it stores the IT stores the result of the decrement operation. 60 00:04:42,570 --> 00:04:45,600 And now we have the displaying the result. 61 00:04:45,720 --> 00:04:46,410 So. 62 00:04:47,310 --> 00:04:55,260 This is basically almost the same as the previous incrementing operation here. 63 00:04:56,830 --> 00:05:01,300 And yeah, the code goes same and same here. 64 00:05:01,300 --> 00:05:06,460 Just changing three registers, instructions and variables. 65 00:05:06,460 --> 00:05:08,440 But the code structure is almost the same. 66 00:05:08,440 --> 00:05:13,330 But here we have the in the display result divide. 67 00:05:13,330 --> 00:05:23,380 And now here we in the shifting code side of the code, we have something interesting here which I will 68 00:05:23,380 --> 00:05:25,840 explain that here. 69 00:05:25,840 --> 00:05:33,070 But we have SA and as a register and sal, we should have somewhere here. 70 00:05:34,330 --> 00:05:35,080 Not division. 71 00:05:37,730 --> 00:05:38,320 Sal. 72 00:05:39,770 --> 00:05:40,550 So. 73 00:05:41,940 --> 00:05:50,640 This instruction moves the value stored in the memory location referenced by a number one into the Rax 74 00:05:50,640 --> 00:05:55,140 register, and it's loading the value of number one into the register for manipulation. 75 00:05:55,140 --> 00:05:58,440 And here we have Sal rax two. 76 00:05:58,470 --> 00:06:09,750 The Sal instruction, also known as c h l this which is meaning the show shift logical shift logical 77 00:06:09,750 --> 00:06:16,770 left shifts the bits of the rax register to the left by two positions, effectively multiplying the 78 00:06:16,770 --> 00:06:19,080 value by two. 79 00:06:19,500 --> 00:06:22,230 And we have the move here. 80 00:06:22,260 --> 00:06:28,890 This instruction moves the value in the tax register which now holds the shifted value to the memory 81 00:06:28,890 --> 00:06:35,610 location pointed to by result I and it stores the result of the left shift operation. 82 00:06:36,900 --> 00:06:41,930 And we us what we have here, we are displaying the result with as we always do. 83 00:06:41,940 --> 00:06:44,280 This is the opposite, opposite for this. 84 00:06:44,310 --> 00:06:44,940 Here we are. 85 00:06:44,940 --> 00:06:49,320 Instead of using Sal, we are using a here. 86 00:06:50,530 --> 00:06:51,280 And. 87 00:06:56,250 --> 00:06:59,880 Yeah, that's it with our program explanation here. 88 00:07:01,750 --> 00:07:05,830 And in next lecture, we will also run this program here. 89 00:07:06,340 --> 00:07:08,080 Explain it, uh, deeper. 90 00:07:08,080 --> 00:07:10,390 And we will analyze this program as well. 91 00:07:11,190 --> 00:07:17,430 And before the closing, stopping this lecture, I want to explain the. 92 00:07:18,510 --> 00:07:19,470 Registers as well. 93 00:07:19,470 --> 00:07:23,430 Again, because we need to repeat it until we. 94 00:07:24,710 --> 00:07:25,610 Know it better. 95 00:07:25,610 --> 00:07:29,090 And I will start with R.D. here. 96 00:07:29,090 --> 00:07:35,000 So this is a general purpose registers often used to hold the address of the format string to be used 97 00:07:35,000 --> 00:07:37,010 with the printf function. 98 00:07:37,010 --> 00:07:41,420 And it is one one of the arguments passed to the functions. 99 00:07:41,420 --> 00:07:42,980 And we also have RSI. 100 00:07:43,280 --> 00:07:47,420 This is a general purpose register also used for holding arguments to function. 101 00:07:47,420 --> 00:07:54,140 And in the code it's utilized to hold the values of numbers or messages that need to be displayed. 102 00:07:54,140 --> 00:07:55,900 And we also have RDX. 103 00:07:55,910 --> 00:08:01,700 This is the general purpose registers as well, often used to hold additional arguments to functions 104 00:08:01,700 --> 00:08:08,330 and in the code it is used to store values such as the result of arithmetic operations before they are 105 00:08:08,330 --> 00:08:09,080 displayed. 106 00:08:09,080 --> 00:08:12,240 And we also have the r BP. 107 00:08:12,260 --> 00:08:17,060 We use that somewhere here r BP here. 108 00:08:18,220 --> 00:08:18,920 Let me find. 109 00:08:18,940 --> 00:08:19,390 Yeah. 110 00:08:19,960 --> 00:08:20,740 RVP. 111 00:08:22,100 --> 00:08:24,450 This is a stack pointer register. 112 00:08:24,470 --> 00:08:31,100 This is points to the top of the stack and it is adjusted to allocate and deallocate memory for local 113 00:08:31,100 --> 00:08:32,960 variables and function calls. 114 00:08:33,880 --> 00:08:43,450 And we have the rags, RTI, RSI, RDX, Rbx and RSP are part of the x86 64 calling convention and are 115 00:08:43,450 --> 00:08:48,910 used to pass arguments and manage function calls between the caller and Callie. 116 00:08:49,330 --> 00:08:59,020 And we also have in C and D, a C Here we use the incrementing and decrementing operations. 117 00:09:01,890 --> 00:09:03,450 Uh, it should be somewhere here. 118 00:09:03,720 --> 00:09:04,240 I see. 119 00:09:04,280 --> 00:09:10,800 And I see here these instructions, uh, for incrementing and decrementing a register or memory location 120 00:09:10,800 --> 00:09:12,600 by one, respectively. 121 00:09:12,600 --> 00:09:16,680 So they are used to perform simple arithmetic operations quickly. 122 00:09:17,040 --> 00:09:22,380 We have the add and sub here. 123 00:09:23,440 --> 00:09:30,130 This instruction that adds a value to a register or memory location, and it is used for addition parents 124 00:09:30,130 --> 00:09:31,060 and for sub. 125 00:09:31,060 --> 00:09:37,270 Here is this instruction that subtracts a value from a register or memory location and it is used for 126 00:09:37,270 --> 00:09:49,180 subtraction operations and we also have s a L and s r a s a r here, which should be somewhere. 127 00:09:50,700 --> 00:09:54,360 Here's are s a are here and. 128 00:09:55,280 --> 00:09:55,850 Sal. 129 00:09:57,320 --> 00:10:03,350 So these are the shift arithmetic left and shift arithmetic right instructions are used for shifting 130 00:10:03,350 --> 00:10:08,720 the bits of registers or memory location to the left or right, and they can be used for multiplication 131 00:10:08,720 --> 00:10:12,050 and division by powers of two respectively. 132 00:10:12,050 --> 00:10:20,840 And we also have here I'm u l you should see somewhere here instruction use. 133 00:10:20,840 --> 00:10:24,440 This instruction is used for sine multiplication of two values. 134 00:10:24,440 --> 00:10:32,060 It is often used with two operands and the result is stored in the destination operand. 135 00:10:32,670 --> 00:10:34,190 And we have it here. 136 00:10:34,200 --> 00:10:39,660 This is this instruction used for sign division and it divides the contents of the accumulator by the 137 00:10:39,660 --> 00:10:46,980 specified operand and stores, the quotient in the accumulator and the remainder in the specified register. 138 00:10:46,980 --> 00:10:48,840 And we have the printf. 139 00:10:48,870 --> 00:10:52,710 This is a function from the C library used for formatted output. 140 00:10:52,710 --> 00:10:57,840 And in the code it's called with arguments stored in registers and displays the formatted message to 141 00:10:57,840 --> 00:10:58,680 the console.