1 00:00:00,470 --> 00:00:01,580 Hello, my name is Stefan. 2 00:00:01,580 --> 00:00:07,780 And in this lecture we are going to develop our project calculator project further here. 3 00:00:07,790 --> 00:00:14,270 Now, as I always do, we will I will explain the code while I'm writing it. 4 00:00:14,270 --> 00:00:17,570 And also, uh, when I'm done. 5 00:00:17,570 --> 00:00:27,290 So now we will need to develop our BBS section here, uh, which we will just uh, define two variables. 6 00:00:27,290 --> 00:00:35,720 So section BBS, result result I rescue here. 7 00:00:35,720 --> 00:00:42,860 One result or modulo here is rescue one as well. 8 00:00:43,040 --> 00:00:49,520 And here we will define text section where we will our code will be written. 9 00:00:49,520 --> 00:00:54,710 We will define global main define the main function. 10 00:00:54,890 --> 00:00:59,300 We will here write push RVP move. 11 00:01:01,540 --> 00:01:03,640 RWP rsp. 12 00:01:03,670 --> 00:01:04,930 You already know what that means. 13 00:01:04,930 --> 00:01:06,130 But I will also. 14 00:01:06,340 --> 00:01:08,080 I will explain it again. 15 00:01:08,500 --> 00:01:17,290 And what we're going to do is we will display the numbers here and we will write five instructions, 16 00:01:17,290 --> 00:01:20,830 move the i fmt. 17 00:01:22,340 --> 00:01:24,110 We need this tabs. 18 00:01:24,990 --> 00:01:30,300 So basically we are loading the address of format string to RDR. 19 00:01:30,330 --> 00:01:33,180 Remember this format string is the number here. 20 00:01:34,420 --> 00:01:37,090 Fmt move here. 21 00:01:37,480 --> 00:01:38,290 RSI. 22 00:01:40,100 --> 00:01:42,350 This is number one. 23 00:01:42,380 --> 00:01:49,510 This is the this is for loading the value of number one into RSI. 24 00:01:50,670 --> 00:01:50,850 Here. 25 00:01:50,880 --> 00:01:56,190 Number one is 128 and number two is 19. 26 00:01:57,520 --> 00:02:01,450 And here we will do the same for number. 27 00:02:03,230 --> 00:02:03,950 To. 28 00:02:03,980 --> 00:02:05,360 So move. 29 00:02:06,380 --> 00:02:07,550 Are the eggs. 30 00:02:10,280 --> 00:02:14,390 Number two and move. 31 00:02:15,250 --> 00:02:16,000 Racks. 32 00:02:20,410 --> 00:02:21,040 Zero. 33 00:02:21,610 --> 00:02:26,170 And after that we will call a printf to display the formatted message call. 34 00:02:26,290 --> 00:02:27,370 Printf. 35 00:02:28,570 --> 00:02:32,470 And after that we will need to write the adding here. 36 00:02:33,250 --> 00:02:36,280 So move racks. 37 00:02:40,220 --> 00:02:41,310 Number of. 38 00:02:44,400 --> 00:02:45,510 Number one. 39 00:02:47,590 --> 00:02:48,190 At. 40 00:02:48,920 --> 00:02:49,820 Racks. 41 00:02:51,710 --> 00:02:52,910 Number two. 42 00:02:54,040 --> 00:03:00,100 Here in this here we are loading the value of number one into racks and. 43 00:03:01,380 --> 00:03:06,360 We are doing the same for adding the value of number two to racks. 44 00:03:06,360 --> 00:03:14,250 But here we are loading and here in this here we are adding here, which you will see the difference 45 00:03:14,250 --> 00:03:16,710 right now and result. 46 00:03:16,740 --> 00:03:24,090 We will store the result in this result I reserve so. 47 00:03:26,640 --> 00:03:27,270 Result. 48 00:03:27,310 --> 00:03:28,950 I hear. 49 00:03:30,290 --> 00:03:31,040 Tracks. 50 00:03:33,980 --> 00:03:36,380 And after that, we need to. 51 00:03:37,910 --> 00:03:40,610 We need to display the result as well again. 52 00:03:41,180 --> 00:03:44,880 So display the result. 53 00:03:44,900 --> 00:03:46,220 So move. 54 00:03:46,260 --> 00:03:46,990 Ready? 55 00:03:48,940 --> 00:03:54,790 Fmt fmt integer, which we define somewhere here. 56 00:03:57,510 --> 00:03:57,870 So. 57 00:03:59,910 --> 00:04:01,200 Empty end. 58 00:04:02,220 --> 00:04:08,220 Now what we're going to what we are doing here is we are loading and loading the address of format string 59 00:04:08,250 --> 00:04:12,120 to RTI and MOV RSI. 60 00:04:13,390 --> 00:04:13,960 Some. 61 00:04:14,890 --> 00:04:15,940 Am I here? 62 00:04:16,150 --> 00:04:16,840 This is the. 63 00:04:16,840 --> 00:04:19,660 This is for loading the address of message to RSI. 64 00:04:20,200 --> 00:04:22,690 MOV rdx. 65 00:04:26,540 --> 00:04:29,060 And with this we will. 66 00:04:31,410 --> 00:04:32,250 Actually, yeah. 67 00:04:32,760 --> 00:04:42,540 Uh, uh, with RDX, we will need to load the value of result I result here uh, two, which is. 68 00:04:43,110 --> 00:04:45,450 Or we define it as a reserve. 69 00:04:47,130 --> 00:04:48,420 Who are the. 70 00:04:52,720 --> 00:04:54,130 And after that move. 71 00:04:55,060 --> 00:04:56,100 RDX. 72 00:04:57,420 --> 00:04:58,900 Or racks. 73 00:04:58,920 --> 00:04:59,700 Racks. 74 00:05:01,170 --> 00:05:01,770 Zero. 75 00:05:01,800 --> 00:05:08,490 With this, we are clearing the racks register, which is basically returning the value and after that 76 00:05:08,490 --> 00:05:11,030 we will call them printf. 77 00:05:12,200 --> 00:05:14,900 Which is calling primitive to display the formatted message. 78 00:05:21,530 --> 00:05:22,030 Printf? 79 00:05:22,340 --> 00:05:23,000 Yeah. 80 00:05:23,360 --> 00:05:28,490 And after that, we will need to create our subtracting here. 81 00:05:28,820 --> 00:05:33,220 And after that I will begin to explain these codes. 82 00:05:33,230 --> 00:05:33,700 So. 83 00:05:39,580 --> 00:05:44,560 Acting and move racks. 84 00:05:48,170 --> 00:05:49,240 Number one. 85 00:05:49,250 --> 00:05:53,810 Here we are loading the value of number one into racks sub. 86 00:05:55,500 --> 00:05:56,220 Racks. 87 00:05:58,800 --> 00:06:00,180 Number two. 88 00:06:01,470 --> 00:06:02,160 Move. 89 00:06:05,510 --> 00:06:06,830 Of result. 90 00:06:10,270 --> 00:06:10,860 Rags. 91 00:06:10,930 --> 00:06:12,460 Here we are, storing the value. 92 00:06:12,490 --> 00:06:15,320 Storing the result in a result. 93 00:06:15,340 --> 00:06:16,320 Result I. 94 00:06:16,330 --> 00:06:17,410 And here we are. 95 00:06:17,410 --> 00:06:18,060 Subtracting. 96 00:06:18,160 --> 00:06:22,270 Subtracting the value of number two from rags. 97 00:06:23,020 --> 00:06:27,700 And now we will need to display the result. 98 00:06:27,910 --> 00:06:30,820 Displaying the result. 99 00:06:32,240 --> 00:06:33,650 And here. 100 00:06:34,980 --> 00:06:35,220 That's. 101 00:06:36,590 --> 00:06:42,860 So here what we're going to do is we will load the address of, uh, format string to RTI. 102 00:06:43,720 --> 00:06:44,900 RTI. 103 00:06:49,640 --> 00:06:53,960 And FM to integer move. 104 00:06:54,700 --> 00:06:55,770 RSI. 105 00:06:57,820 --> 00:07:00,690 If you are here we are loading address of message to RSI. 106 00:07:01,290 --> 00:07:02,080 Move. 107 00:07:02,910 --> 00:07:03,450 Are the. 108 00:07:04,880 --> 00:07:07,400 This is fall result I. 109 00:07:09,240 --> 00:07:18,240 They are loading the value of result I to RDX and now we will move our r r a x. 110 00:07:18,600 --> 00:07:25,140 Here we are clearing the x register, returning the value again, and we will call the print. 111 00:07:25,590 --> 00:07:27,360 Our code is not yet done. 112 00:07:27,360 --> 00:07:31,560 We need to add another mathematical arithmetics as well. 113 00:07:31,560 --> 00:07:35,100 But here for this lecture, I will explain this. 114 00:07:35,130 --> 00:07:38,400 So, uh, here. 115 00:07:39,990 --> 00:07:44,520 At first you remember we had this push and move. 116 00:07:44,520 --> 00:07:45,480 RWP rsp. 117 00:07:46,650 --> 00:07:49,230 But we will start from here firstly. 118 00:07:49,230 --> 00:07:57,210 So with this here move ah, the I fmt we are moving the memory address of the format string fmt into 119 00:07:57,210 --> 00:08:02,940 RDA register and RDA will be used as the first argument for this printf function. 120 00:08:02,940 --> 00:08:08,400 And here we are moving the. 121 00:08:09,550 --> 00:08:15,640 Value stored at the memory location pointed to by number one into the RSI register. 122 00:08:15,640 --> 00:08:20,740 And this loads the value of the first number for displaying. 123 00:08:20,770 --> 00:08:27,880 And here we are moving the value stored at the memory location pointed to by number two into the RDX 124 00:08:27,880 --> 00:08:32,770 register, and this loads the value of second number for displaying as well. 125 00:08:32,770 --> 00:08:35,800 And here we are calling the um. 126 00:08:38,720 --> 00:08:40,820 And here we are calling the. 127 00:08:42,370 --> 00:08:50,470 Printf, which calls the string function to display the formatted message using the provided, um, 128 00:08:50,470 --> 00:08:57,070 argument like RTI, RSI and RDX here. 129 00:08:59,200 --> 00:09:02,750 And after that we have moved racks number one. 130 00:09:02,770 --> 00:09:04,180 This is for moved moves. 131 00:09:04,180 --> 00:09:09,580 The value stored at the memory location pointed to by number one into the racks register. 132 00:09:09,580 --> 00:09:10,740 And this. 133 00:09:10,750 --> 00:09:14,290 This loads the value of the first number for arithmetic operations. 134 00:09:14,290 --> 00:09:17,560 And here we are with this. 135 00:09:19,040 --> 00:09:20,130 Here we are telling. 136 00:09:20,180 --> 00:09:26,720 Telling the assembler to add the value stored at the memory location pointed to by number two to the 137 00:09:26,720 --> 00:09:28,340 value in rax register. 138 00:09:28,340 --> 00:09:34,160 So this result the result is stored in Rax representing the sum of two numbers. 139 00:09:34,220 --> 00:09:39,680 And here we are storing the value in the rax register which is sum of the numbers. 140 00:09:40,070 --> 00:09:41,840 Sum of the numbers. 141 00:09:42,170 --> 00:09:48,830 Summary of the numbers into the memory location pointed to by result I here. 142 00:09:48,920 --> 00:09:49,960 And we are. 143 00:09:51,360 --> 00:09:53,040 In display here. 144 00:09:53,070 --> 00:10:02,790 I move Fmt and RDL will be used as the first argument for the printf function and here RSI will be used 145 00:10:02,790 --> 00:10:05,580 as the second argument for the printf function here. 146 00:10:05,580 --> 00:10:07,800 And this loads the. 147 00:10:08,370 --> 00:10:14,040 This loads the result of the addition operation for displaying. 148 00:10:14,790 --> 00:10:22,200 So this clears the rax register, preparing it to be used as the return value for the printf function. 149 00:10:22,350 --> 00:10:28,950 And here we are calling the printf function to display the formatted message using the provided arguments, 150 00:10:28,950 --> 00:10:32,040 which is RDA, RSI and RDX. 151 00:10:32,040 --> 00:10:39,660 So this subsequent subtracting section follows a similar pattern with the sub instruction to subtract 152 00:10:39,660 --> 00:10:45,540 the second number from the first number and the same process for displaying the difference. 153 00:10:45,540 --> 00:10:46,830 And please. 154 00:10:50,770 --> 00:10:51,220 Here. 155 00:10:51,220 --> 00:10:57,280 Keep in mind that this printf is callable function from an external library. 156 00:10:58,270 --> 00:10:59,020 And. 157 00:11:00,110 --> 00:11:04,040 As you can see here, it's being used for output purposes. 158 00:11:05,170 --> 00:11:14,050 And as you can see here, we almost all fully completed we completed 50% of our program, which we will 159 00:11:14,050 --> 00:11:19,390 continue that in our lecture in in our next next lecture.