1
00:00:03,290 --> 00:00:03,740
Hello.

2
00:00:04,190 --> 00:00:06,960
So in this next lesson we quaint.

3
00:00:06,980 --> 00:00:07,750
Take a look.

4
00:00:08,090 --> 00:00:12,270
How to declare variables in assembly.

5
00:00:12,270 --> 00:00:13,240
Show us.

6
00:00:13,250 --> 00:00:14,330
We always do.

7
00:00:14,330 --> 00:00:18,860
I create a new photo on my end and call this one variable

8
00:00:22,550 --> 00:00:34,360
in sin and then I'll just name the project variable and then open and select our board t up for C 1

9
00:00:34,360 --> 00:00:37,180
2 3 0 h 6 p.m.

10
00:00:41,170 --> 00:00:49,830
okay and then under CMC is to call on a device to startup and then we come here.

11
00:00:49,840 --> 00:01:01,150
Targets options were set to the 16 mega heads and then debugger distilleries I C D I OK we're all set.

12
00:01:01,250 --> 00:01:05,210
So like our previous program we're going to have to follow us here.

13
00:01:05,210 --> 00:01:15,380
One assembly and then one C we do some of the work in assembly and cool it in C so I'll create a first

14
00:01:15,380 --> 00:01:24,230
for here and then I'll press control X to save this empty file and what's the name of the group on this

15
00:01:24,230 --> 00:01:30,380
one and I'll call it function Dot.

16
00:01:30,550 --> 00:01:38,340
S just like the first program we created and I would say this one too and pull this one main let's see

17
00:01:38,940 --> 00:01:45,090
after the double click here and then both files.

18
00:01:45,810 --> 00:01:54,020
Then we could and then we start by right now the content of our function not C.

19
00:01:54,300 --> 00:02:00,780
And over here we're going to introduce something new so far in our assembly code we've declared the

20
00:02:00,780 --> 00:02:06,530
directive area and we've specified that the area is the code area.

21
00:02:06,660 --> 00:02:12,280
And this lesson we're going to specify another area known as the data area.

22
00:02:12,340 --> 00:02:15,280
That is where we would store our data.

23
00:02:15,320 --> 00:02:18,070
So let's take a look at how this would go.

24
00:02:18,630 --> 00:02:20,790
This is going to have two areas.

25
00:02:20,940 --> 00:02:25,350
So there's the clear area.

26
00:02:25,350 --> 00:02:26,280
What area is it.

27
00:02:26,370 --> 00:02:28,730
It's the data area.

28
00:02:28,730 --> 00:02:40,510
And then there's a line and a line 2 and then to create a variable you give the name of the variable

29
00:02:40,510 --> 00:02:41,390
US label.

30
00:02:41,400 --> 00:02:43,200
Let's call this scramble amount.

31
00:02:43,530 --> 00:02:51,510
That's the name of our variable and we use the directive space and then we indicate the amount of space

32
00:02:51,780 --> 00:02:57,570
we require this number for each space as abides.

33
00:02:57,600 --> 00:03:05,620
So if we won here this would be one byte space which is equal to AIDS bits but we want 32 bit.

34
00:03:05,670 --> 00:03:10,170
We want our variable amount to be a new 32.

35
00:03:10,170 --> 00:03:14,850
So for here given this 32 bit.

36
00:03:14,850 --> 00:03:16,380
That being said.

37
00:03:17,310 --> 00:03:22,620
So what we have to do to make this variable callable outside this file.

38
00:03:22,680 --> 00:03:24,840
We have to export it.

39
00:03:24,840 --> 00:03:30,900
So we'll use the export keyword export amount.

40
00:03:32,460 --> 00:03:40,890
So we've declared the we've declared a data area in order to make this visually appealing.

41
00:03:41,310 --> 00:03:43,920
I usually do this for beginners.

42
00:03:43,920 --> 00:03:48,770
I declare one area and put a line and then declared a second area.

43
00:03:48,810 --> 00:03:49,670
So you can do this.

44
00:03:49,670 --> 00:03:56,690
This not necessary but I think this would help you understand it entirely a little way to the next area.

45
00:03:56,710 --> 00:04:00,710
Just normal area code area where we put a program code.

46
00:04:00,930 --> 00:04:11,340
So we start with the area directive and then we start with the text to make it callable in C.

47
00:04:11,970 --> 00:04:22,370
Then we make sure we tell them what area code and it's really only a line

48
00:04:25,120 --> 00:04:30,830
a line 2 and it's thumb.

49
00:04:31,110 --> 00:04:38,950
We write and inform instructions and we're going to create a function that function to contain our variable.

50
00:04:38,960 --> 00:04:41,150
So we might as well export the function.

51
00:04:41,570 --> 00:04:43,580
Otherwise we wouldn't be able to find it.

52
00:04:43,580 --> 00:04:50,290
Let's call this function and march function for that amount.

53
00:04:50,880 --> 00:04:53,200
Func OK let's just call it this.

54
00:04:53,450 --> 00:04:55,020
So you can see the difference.

55
00:04:55,070 --> 00:05:05,070
These two things these two items we export to this first one is variable code amount and this is a function.

56
00:05:05,180 --> 00:05:09,460
So we want to use them outside this file hence export.

57
00:05:10,580 --> 00:05:19,010
So we come here to write the contents of the function start with the function name and label to amount

58
00:05:19,250 --> 00:05:20,780
on the school C

59
00:05:23,690 --> 00:05:31,240
and we come here and basically what we're going to do here is load the variable here and put a value

60
00:05:31,270 --> 00:05:40,160
in the variable so we're going to do by do that by pointing to the variable and then swap in swap into

61
00:05:40,160 --> 00:05:48,770
value from one register to the variable you can think of this as how we manipulate the bids in our GC

62
00:05:48,800 --> 00:05:58,360
GPI registers yeah our RC GC GPI and then a standard GPA it will registers registers festive for we

63
00:05:58,360 --> 00:06:07,630
used to use the Delta are two point to point to these registers and remember the registers where the

64
00:06:07,630 --> 00:06:16,030
registers with names like GPI both data underscore ah they were just place holders there were names

65
00:06:16,030 --> 00:06:22,340
with give into the address to the address of that particular registers.

66
00:06:22,360 --> 00:06:30,910
So you can think of the word amount as such a name such a name would place and a location in memory

67
00:06:30,970 --> 00:06:39,940
which would be served here a space for two just like we did just like we did before by writing system

68
00:06:39,960 --> 00:06:49,600
c c l I received GC keeping on a score Ah it's just an example of this what we did before yeah we pointed

69
00:06:49,600 --> 00:07:02,290
first and then we toward add value later by using L2 R and then by doing this as you are one to get

70
00:07:02,290 --> 00:07:04,620
the funding into our one two.

71
00:07:04,660 --> 00:07:13,180
So after these two lines we end up with whatever value comes here in this register.

72
00:07:13,180 --> 00:07:19,670
So this time we point to our variable amount.

73
00:07:21,700 --> 00:07:31,210
And then let's move the value to another register let's say we want to store the number 89 in our variable.

74
00:07:31,270 --> 00:07:33,520
So we have 89 nine here.

75
00:07:33,520 --> 00:07:43,540
So to store we just SDR is a shorthand 0 0 and then I 1 remember as the r source the source is the number

76
00:07:43,580 --> 00:07:44,340
eighty nine.

77
00:07:44,560 --> 00:07:51,730
And then we store in what are is pointing to which is the memory location of all of our variable to

78
00:07:51,730 --> 00:08:00,700
at this point we've stored 89 in the variable amount and then we returned from the function x r and

79
00:08:00,700 --> 00:08:03,840
then we line and we.

80
00:08:03,970 --> 00:08:12,970
And so we've created a variable here and you can create as many variables as you want.

81
00:08:13,750 --> 00:08:14,250
Yeah.

82
00:08:14,320 --> 00:08:22,810
So this what it looks like a new addition to this side would be declaring the data area and declaring

83
00:08:22,810 --> 00:08:24,810
this you've not seen this before.

84
00:08:24,850 --> 00:08:26,950
So pay closer attention to it.

85
00:08:27,550 --> 00:08:35,980
So now that we've finished with this and we've exported this and this we can go to the seaside to to

86
00:08:35,980 --> 00:08:45,050
right out the C code and let's let's conclude it as to the end so that we can be able to use you into

87
00:08:45,070 --> 00:08:50,110
theta to include best and that's h.

88
00:08:50,150 --> 00:08:56,960
Sorry we have to use the keyword external to call our variable cos it's external.

89
00:08:57,640 --> 00:08:59,440
Yeah it's literally external

90
00:09:01,960 --> 00:09:12,280
and the name of the variable is amount plus we gave it and we have our function which is a int to return

91
00:09:12,500 --> 00:09:20,080
a good amount on this call in C and tennis and forward

92
00:09:22,820 --> 00:09:25,350
shall we have this in this too.

93
00:09:25,750 --> 00:09:28,860
That's great on Main function in Spain.

94
00:09:30,890 --> 00:09:32,840
And we have me here.

95
00:09:33,080 --> 00:09:41,560
So let's call our function our function from the assembly scored amount amounts func.

96
00:09:41,700 --> 00:09:43,490
Yeah okay.

97
00:09:45,490 --> 00:09:51,520
So let's go back and take a look at the function again of our voice here it's empty.

98
00:09:51,520 --> 00:09:55,660
It is through this function that we add something to the variable.

99
00:09:55,690 --> 00:09:59,120
That is why we have to call this function here.

100
00:09:59,140 --> 00:10:05,600
This just for this experiment to see that actually we've stored something in the variable.

101
00:10:06,100 --> 00:10:10,990
So in order to do that remember this is the global variable here.

102
00:10:11,140 --> 00:10:13,090
There's this fair amount.

103
00:10:13,090 --> 00:10:14,800
We have it in C here.

104
00:10:15,010 --> 00:10:23,680
So we can just read this and see whether indeed its value is eighty nine after the function has finished

105
00:10:23,680 --> 00:10:24,130
running.

106
00:10:24,130 --> 00:10:29,330
So all we have to do is call the amount here.

107
00:10:29,980 --> 00:10:33,940
You can just call amount we assign it to another variable.

108
00:10:33,970 --> 00:10:43,890
So let's create a global variable here call you in 32 weeks to end and let's call it C amount we just

109
00:10:44,000 --> 00:10:49,180
create this global variable and then we assign C amount

110
00:10:52,000 --> 00:10:53,690
to the the amount value.

111
00:10:53,980 --> 00:11:02,110
So remember this amount is this amount is the same thing if we are to change to name to something else

112
00:11:02,140 --> 00:11:04,320
the code wouldn't work.

113
00:11:04,450 --> 00:11:13,160
So we just want to read the value of this file variable in assembly and displayed in this new variable.

114
00:11:13,180 --> 00:11:14,820
This is just for display sake.

115
00:11:14,920 --> 00:11:22,570
If we wanted to do a computation we wouldn't need this redundancy of writing one other global variable

116
00:11:22,570 --> 00:11:25,950
to display this in a way I wouldn't confuse you.

117
00:11:25,960 --> 00:11:26,590
Let's check.

118
00:11:27,130 --> 00:11:33,520
And please remember to put what I do not understand in the comments line you would receive a prompt

119
00:11:33,610 --> 00:11:35,080
reply.

120
00:11:35,110 --> 00:11:41,470
So what we have to do now is to compile and we have zero errors with download onto our board

121
00:11:44,690 --> 00:11:48,710
and we reset our board when we are done with that.

122
00:11:48,710 --> 00:11:50,840
We just opened the door for you

123
00:11:55,400 --> 00:12:03,490
and this time what we interested in is this is this global variable here amount we can just add it to

124
00:12:03,490 --> 00:12:09,190
the watch window to see what happens in it.

125
00:12:09,190 --> 00:12:16,950
Come on do this highlight right click and then up to 21

126
00:12:20,750 --> 00:12:29,240
and once that is done we can just step through the code you can check this to display in decimal form

127
00:12:30,200 --> 00:12:40,300
so once we done we can just pick over and see the changes that occur in the code so we can see we have

128
00:12:40,300 --> 00:12:45,060
the value 89 89 is stored in our variable here.

129
00:12:45,220 --> 00:12:49,360
This extend or variable and we've read in it from our new global variable.

130
00:12:49,360 --> 00:12:54,410
So indeed our variable is working from assembly to see.

131
00:12:54,760 --> 00:13:01,140
So show you more.

132
00:13:01,160 --> 00:13:06,970
Let's say we were just closed as we cleaned this.

133
00:13:07,010 --> 00:13:12,140
We don't run this C function or the code runs all right.

134
00:13:13,880 --> 00:13:23,270
A variable wouldn't work cause it was the function that was doing the assignment for us so yeah

135
00:13:26,550 --> 00:13:27,060
let's see

136
00:13:34,730 --> 00:13:37,200
if she can see nothing happened.

137
00:13:37,250 --> 00:13:37,720
Yes.

138
00:13:38,450 --> 00:13:44,590
So yeah this is how to write a variable in assembly.

139
00:13:44,600 --> 00:13:51,500
I hope you get to so in the next lesson it would take a look at how to import functions from C and use

140
00:13:51,500 --> 00:13:52,710
them in assembly.

141
00:13:52,790 --> 00:13:53,420
C You.
