Transcript of RSM Episode 2

RSM project page

00:00:02 okay um video number two day number two um
00:00:09 so uh yesterday uh evening
00:00:15 i um after spending a lot of time trying to get the video just uploaded it's amazing actually i spent at this point i spent a lot more
00:00:23 time i was trying to get the video shared on the interwebs than actually
00:00:27 building and working on this project which is kind of ridiculous
00:00:37 technology is hard anyhow um so yesterday evening i started
00:00:47 um with the little like formatting thing uh
00:00:51 so the formatting thing i mentioned yesterday
00:00:55 it is not a lot of code this is it
00:01:02 it um let me run it here so what it does is that it allows us to see
00:01:07 um what we actually ended up encoding into
00:01:13 this little um you know homemade bytecode thingy right
00:01:20 uh these instructions um
00:01:24 so it's really straightforward uh what i'm doing here is take the ip thing here which is the array of instructions we've gathered up and there are
00:01:36 seven of them um and
00:01:41 then i yes that'll get a little bit of a little bit of a buffer here yes on the stack for um it creates this output maybe i should
00:01:48 make a little bigger um and then i pass that buffer and this
00:01:56 the you know the limit of it to a function that i've named form with
00:02:02 program uh along with the list of instructions and pc here is just the the number of
00:02:08 instructions since since we're increasing pc here at
00:02:14 the at the end it's it's going to be um the count the number of instructions
00:02:19 could use a better name but yeah yolo
00:02:23 okay so so this one
00:02:26 um is a um it's a very simple little
00:02:30 function what it does is that it uses this uh little pen buff we can jump around and look at what that is it's very straightforward um
00:02:41 there's a little bit of uh structure that has a pointer to where we are currently like the
00:02:47 the current byte that we're writing to which is also um
00:02:52 the the zero terminator null byte this is kind of for c c strings
00:02:55 um and then this thing is just something that the the init function here sets up
00:03:02 to be the the last byte that we can write to
00:03:06 um and that's sort of like the the capacity of the the input buffer that the this
00:03:13 pen buffer is writing to and and length here is a separate member rather than you know subtracting
00:03:18 these two simply so that we can get this um
00:03:25 uh s and printf behavior if you're familiar with that lib c function
00:03:29 essentially what what what um not create print enough we can just look it up in the manual um [Applause] okay
00:03:49 so um let's say here so the
00:03:55 the sm printout function on similar functions will write at most size
00:04:00 and less than one of the characters printed into the output stream
00:04:06 if the return value is greater than on this kind of the key or equal to the size argument the string was too short and some of the
00:04:14 printed characters were discarded the output is always not terminated unless the size is zero yeah um so what's kind of neat about this type of interface is that you can um
00:04:24 uh you can do something akin to like dynamic memory allocation
00:04:32 without involving any um heap allocators you get back the number of bytes that it
00:04:41 would have written if the buffer was infinitely large so that means that for any function that
00:04:46 you know that implements this this type of behavior what you can do is
00:04:50 jumping back to us actually let me just like with this and restart this build thingy
00:04:55 so what you can do with these types of functions is uh when we're making use of
00:05:01 uh a form pro here right so uh if this was like a real program and i
00:05:07 guess eventually this this might be more robust we can do u size and uh and let's say that this is you know
00:05:15 60 i don't know 64 maybe that would be too small
00:05:19 um i think yeah so so n is going to say 250 over here we
00:05:33 can say it says 250 and that's how many bytes would have been written if um buffer here was
00:05:40 inverted large and now we know so we could do this like we could do if you know if m is the you know the size of
00:05:47 our buffer then we have to retry
00:05:52 then we have to you know do um i guess we would do something like this buff is malloc i'm not gonna actually write this
00:05:59 for real but if we had malloc we would do malloc and we would do n
00:06:04 um plus one for the null terminating byte and now we can put this in and we do plus one and uh would be good right
00:06:15 or we can use alert if we have you know a couple of these like pre-allocated buffers we can use a larger one anyhow it allows you to do a best guess and uh if you're wrong you can correct
00:06:26 it in one go without having to sort of like incrementally like is this a good
00:06:30 size is this a good size this is a good um and yeah
00:06:37 that is sort of beyond the the scope of what i'm doing here but oh
00:06:43 um but i thought it would be worthwhile to explain what that uh what this
00:06:48 what this sort of what this sort of buffer thing is doing so uh that's why it has a len counter and and length here this is just incremented every time anything is um
00:06:59 is changed in this buffer uh but p is only advanced and written to
00:07:04 as long as there's still space in it and that allows us to use um uh ts7 if you let me just jump back here
00:07:13 so that allows me to just do this like append just depend the pen and then have
00:07:19 to do checks and see if like if if we reach the capacity of the buffer
00:07:22 and at the end uh terminate it's just a helper function
00:07:26 that uh let's see
00:07:32 is it just sets the the current position to now so like the terminating now and
00:07:37 then it returns the the length as it would have been would pv infinitely
00:07:41 large and then he is just a min operation while it's actually like writing things to make sure that it's not writing beyond the uh the valid memory region of the the buffer pass then it's uh it's
00:07:54 it's pretty neat straightforward way to do this at least i think so
00:07:58 um so jumping back so we've set up this um
00:08:10 this buffer and the next we do is loop through the
00:08:13 instructions and uh
00:08:21 we print it out i started out with something like this i'm just printing out the the name of it
00:08:31 and get up here is like a macro we looked at that yesterday um that just
00:08:36 extracts the it just kind of extracts the bits um the most significant bits i
00:08:41 like that um of the instruction which is the
00:08:45 op code and then it calls this
00:08:49 up name function where gs returns a sort of compile time
00:08:56 like you know string of the of the operation just makes the output
00:09:00 here on the on the right side makes a little easier to to see move load i and
00:09:06 so on rather than a um just you know an enumeration kind of
00:09:11 offset um anyhow
00:09:15 uh but i ended up adding this uh this offset as
00:09:21 well since when there are instructions like
00:09:25 the branch instruction that jumps forward three it's going to be useful
00:09:30 and i found it useful looking at this yesterday to to see is this actually
00:09:35 correct you know it's it's six you know uh is is that six minus three is that gonna
00:09:42 end up in the right place um and the next thing is just it's just a
00:09:47 switch it's just generating a switch condition here with the all the um the up codes that
00:09:57 and i made a change to this yesterday um and uh i think this is something maybe i've done in the past but anyhow it ended up being pretty neat so in the uh in the definition here of
00:10:09 uh can you scroll down a little bit let's see where's my
00:10:13 um so in the definition of instructions
00:10:17 here um i've added another field maybe i had
00:10:22 this in yesterday anyway i wasn't using it if i had this yesterday but
00:10:25 this uh declares like what this uh operation
00:10:31 this instruction which arguments it's using and it's
00:10:34 encoding and so a b i
00:10:38 i mean i just made this up there's there's no it doesn't have any any
00:10:44 meaning beyond my name here so a b i means it uses the argument a and the
00:10:48 argument b and the argument b is an immediate value
00:10:53 it's not it doesn't name a register so contrast that to this one this one a
00:10:58 b without the i means that a and b both name registers and a be a bi i guess we
00:11:04 can read like this a and then bi names an immediate value in inside a b
00:11:12 slot rather than a register number and similarly another thing is k and k
00:11:17 would name a uh constant i haven't implemented constants yet but you know assuming that there's a uh as
00:11:23 your token by yesterday there is really just these two concepts there are there's global constant data you can you
00:11:30 bake into your program it's kind of you know just read on memory um
00:11:35 and then you have uh mutable locals right so input arguments
00:11:42 output results and any sort of like temporary aka variables that you might
00:11:47 need inside a function um yeah so that's it so the so the constant a numerical value of a constant in the
00:11:57 program right so if you have constant one constant two constant three uh this
00:12:01 would name a particular constant now i haven't gotten around to this and i just tossed this in here to play around with things and this might not actually be like the right thing it might be better to either to have a you know indirection
00:12:13 table of um here's like a number of addresses to
00:12:18 constant data along with like their alignment and since you know a constant might be of
00:12:28 any size right it could be a five byte string or it could be you know a 64 bit
00:12:34 or a eight byte integer right or it can be sort of like really anything you can imagine and some constants will want to
00:12:40 have a certain alignment and memory and stuff like that so they will have you know you it's they're not kind of like you just have a fixed size in memory so there's got there's there's got to be some need for
00:12:51 um memory addresses when it comes to the
00:12:55 constants at least at some point but you know i'm not bothered by that yet don't need that to um to move along
00:13:02 so that's what that means so i ended up here you can see a couple more eyes here
00:13:07 so branch and i changed the branch ops too from from the ones we looked at yesterday so this one is branch if zero
00:13:13 um so if instruction uh why did i write that
00:13:21 how long um oh yes this is an absolute brush
00:13:25 that's that's why um so yum to instruction number
00:13:32 load register that is the register c right so
00:13:38 grab the c argument let's say it's four then load the value in register four uh
00:13:43 and that value is going to be the um the absolute instruction offset in the
00:13:49 program to jump to if the value of register a register given
00:13:55 in argument a is zero and similarly there's a there's sort of like a sibling instruction here that is not
00:14:03 zero right so i think that sometimes what you do is like you have a instruction called compare um
00:14:10 you'll still need that i think in this case but you sort of like end up doing something like this uh so you say uh
00:14:18 you know compare uh register one to register two right
00:14:24 you store that in register three or whatever and then you do sort of like
00:14:32 a branch on your easter three um to you know some label
00:14:37 um i think this is super common right so you end up with this this is essentially a a single bit like integral really you
00:14:44 just care about one bit it's like a boolean right um rd is equal let's say
00:14:49 it's very cool are these equal or not it's gonna be one and zero uh super
00:14:53 common thing to do right like any if case in in a programming language right
00:14:58 is at least in almost all programming languages will be
00:15:04 a boolean condition right if true then do this else do that right or just
00:15:08 password um so in the spirit of just keeping it kind of
00:15:15 simple and straightforward there's just an instruction called you know that combines those two things that's just you know if um
00:15:23 this thing is zero you just do the young i'll stop studio okay so that's what
00:15:34 also i put up my maybe i'll post a photo of my
00:15:39 amazing sort of duct tape it's literally the octave or electric type setup of
00:15:43 this camera here um i hope it's a little bit better on this camera that's built into my display that i was using yesterday um
00:15:55 so with having the instruction encoding added to this definition of operations
00:16:00 here that uh allows us to
00:16:05 to write this formatting code like really compactly and really small as therefore so this is like all the code
00:16:13 this is all the good needed um to you know manage the buffering stuff and all of that and to to produce this
00:16:19 formatting that was on the right side here the little colors that is just you know i'm just picking the
00:16:27 um the uh the six colors the ansi colors there we
00:16:33 go i wrote it out there the ansi codes for just the um the four bit colors that
00:16:38 pretty much every terminal supports this one i just wanted some colors i thought is useful since like if we
00:16:47 okay so we're gonna say is let's write the register
00:16:53 number so fmtr is being used here
00:16:58 to write out the registered number right so
00:17:08 now it gets in since most most or many redistricting numbers will be like uh you know one digit long like eight and
00:17:14 zero at least i find it kind of hard to add a glance just spot if like is this a
00:17:18 different register than this or are these the same and so adding the volume too far so adding the little
00:17:26 colors here like just i found it really helpful to uh to see that like oh this
00:17:30 is the same as this uh and this is different um
00:17:36 it's kind of neat so it's a small little hack i kind of like that um so we have just three macros and maybe i'm using or maybe you're watching this here like oh my god like here like preprocessor like weirdo you know what the hell are you
00:17:55 doing i don't know i think if the code can get easier to read i'm
00:18:00 not like all for macros i think it's awesome um obviously it can be really
00:18:05 useful like for things like generators like this um but also in this case
00:18:11 what's happening here and why this is kind of like small is that there's a
00:18:16 macro down here so one when i generate the switch case right with all the switch statement
00:18:21 all those cases um which happens so this this line here
00:18:28 that we see this line here is um executed expanded applied for each of the instructions that uh we
00:18:40 specify here so for move and then for low enough load k and so on
00:18:45 and along with that comes the name right i wish bring these next to but i'm trying to keep my my recording really small so the texas is
00:18:54 is large enough for you to see um so we get the name and now we got this
00:19:00 instruction encoding we're going to use that a second and this is just a description i'm not
00:19:05 using it for anything now rather than just referencing them myself
00:19:10 so we get the name and then we get the instruction encoding here you just call it args and then this delta dot means you know
00:19:24 and we glue this together so it's prefix string which you can find up here like all these functions here have the prefix string right and then i glue yes the arcs together so
00:19:33 essentially like that glues together this thing so a b i
00:19:37 right or you know branch if zero with an immediate c value
00:19:46 right so let's look at that a b c and i so that comes in here if you see an i so that becomes right a b c i
00:19:59 and since maybe she quickly revisit the
00:20:05 instruction encoding here we looked at this in the first video
00:20:09 since each of these arguments
00:20:12 are starting at the same place
00:20:16 and you know so a in the a b
00:20:22 you know w in the a b case right starts at the same place as a in the a b c d case and in all these cases right so b always starts in the same place and so on um that simplifies a bunch of stuff and
00:20:31 it simplifies this too so like a function that will print out
00:20:37 four different arguments on the screen doesn't have to you know i don't have to call things four times since you know you just say abc right and abc in this
00:20:46 case says just a b and so on this is probably super obvious to you so maybe i should just move on but uh so so that's what's going on um
00:20:54 okay so now we got a little now we got a little um
00:21:00 formatting thing and we can actually see what's uh what we're doing here so if we
00:21:04 make a mistake uh that'll be much easier to spot right so if i put in
00:21:11 a one here or let's say i mix these up right so i thought it was like this
00:21:18 then we can spot that uh what the computer actually sees is like multiply r by r zero
00:21:25 sorry by r zero by r zero right and put it in r8 that's not right so
00:21:37 okay um for now i think this is going to be just
00:21:43 fine for the formatter for the little it lacks there there are two things that
00:21:52 it lacks like first off it doesn't express the the labels and again the
00:21:57 labels are really just you know for the programmer right so a label here is this
00:22:01 b value here it's it's really just like any name that
00:22:07 you want you know it can be a little cat or whatnot but
00:22:13 this label is for the mixed instruction right so this is going to be a label for
00:22:17 instruction number three so that's the multiplication instruction we have it over here it's instruction number three um so a label is not something that is you
00:22:28 know concretely part of the program at least it's it isn't in in any of the
00:22:32 major um architectures as far as i know
00:22:39 and it certainly isn't in this little r7 hobby um instruction set
00:22:46 so either either will just like include
00:22:51 a label as like an instruction i don't even know how that would work because that would you know change the meaning of the label so that's kind of weird or more likely like just the first thing so just give labels like names like b0 b1
00:23:03 block or block like or label maybe all l0 l1 and so on um
00:23:10 but to do that would make the formatter a little bit more complicated and i'm sure i'll get to that eventually but essentially when
00:23:17 um when you get to something like this right any instruction that would name
00:23:25 an instruction offset so that includes the these two branch
00:23:30 instructions if it's zero if it's not zero branch instructions so this name is
00:23:36 an offset a positive offset of three right to jump down here
00:23:44 we'd have to encode that into the program so that
00:23:48 might be another argument in this definition list here that is like you
00:23:52 know flags maybe and maybe one of the flags that can occur in here could be um
00:23:58 you know argument c names and instruction of that
00:24:02 and then the formatting function could use that so when it's going through and
00:24:07 and printing or formatting a given instruction you can see does this have the flag argument c is a
00:24:15 an instruction offset and if it does it can uh it can then like manufacture a
00:24:19 label you know three instructions for work or whatever the the offset is right
00:24:24 so something like that could create labels so labels are still missing the other thing that's missing is that uh my little macros for
00:24:32 uh for managing um retrieval of arguments here doesn't deal
00:24:38 with sign integers and so
00:24:42 when you have a surface calling smart
00:24:46 so if we look at this thing this instruction here this is branch if
00:24:54 not zero with an immediate value of instruction offsets so it looks at yeah this the instruction of coding here
00:25:17 so let's change that okay so what's happening here what the mistake i've made is that the um brand shift not zero
00:25:23 right i thought it was it was accepting um two
00:25:29 arguments right it's not it's it accepts just one argument right it reduced your argument and then the the immediate right
00:25:38 so zero like register syria doesn't use that so let's change this
00:25:43 and now we're gonna just get some random number here which might or might not be the same
00:25:49 next time around it who knows um yeah oh there we have the number
00:25:56 okay so um that's because the formatting function is not you know it's it's based
00:26:00 on these things so we need to go here so this thing it
00:26:05 says like no it doesn't it doesn't use the the b value or the the c argument there
00:26:12 um and the the same is true for this one and i should go and update this right oops
00:26:20 so this is going to be b so um this is going to be b2 i think
00:26:25 actually all of these are going to be b um and then we drop the c
00:26:30 and just going to clean up the orientation
00:26:38 rerun that okay now we're good that's the power of macro right there
00:26:44 we didn't have to make any other changes if the formatting functions now are routed to a different function right
00:26:49 when a case statement here for that instruction hits we're just going to go to this one and before we went to this one
00:26:57 which is why i tried to print um the value of an argument that we didn't set which you just gonna have some random stuff from memory
00:27:06 so uh okay that would fix that that was good that's a little annotation for
00:27:09 cleaning us okay so back to the uh the issue here is
00:27:14 that this is a negative value right
00:27:18 so the the instruction offset here is
00:27:23 negative to the distance to this label right so this is actually a loop right
00:27:27 so what we're building here is if we're looking at this kind of um
00:27:32 to be assembly we define a label at this instruction that's that is the the start
00:27:36 of a loop so we go down here to two and we come here we do we multiply these things we
00:27:44 put in zero and then we subtract one from eight and we look and see if uh if eight is
00:27:52 not zero and if it's not zero which is sort of like the common condition until you know the function is done we just go back to b1 and we we do this
00:28:02 again right so we multiply uh and then we subtract and then we check and multiply subtract and check and eventually we'll check here and it'll be like no it's not zero meaning that it is zero
00:28:13 and it will not branch and we'll fall so that means that the register offset
00:28:23 here is negative it's going to be negative three since the
00:28:26 the programming counter will increase one after here well depends on how we implement a little evaluator later but
00:28:33 um yeah let's say that it's three um and so we need minus three and i'm not
00:28:39 really expressing that so here yeah sure this is gonna be a negative number
00:28:43 uh that we store in here but you know the way two's complement integers are stored
00:28:51 is you use one bit to say is this negative or positive and you use the
00:28:55 remaining bits to say you know what expressing what number it is right
00:29:00 but the the way we we store things like we
00:29:05 don't really say the specific bit is the sign bit we say you know just toss it in
00:29:09 there um and so we're gonna have to figure out how to get this this out as assigned uh as a
00:29:20 signed number when we extract it uh and for that we're just gonna i think
00:29:24 what we're gonna need is a uh it's an instruction encoding actually
00:29:29 to express an instruction encoding so first let's just see if we can get that working um so we're going to jump to the formatter i think now let's just let's just see if we can just print it out here
00:29:43 um so we're just gonna see if we can lock this mia's gonna grab this
00:29:52 this instruction here let's just make a copy so we can easily let's look at it
00:29:59 let's just do this so i'll make a copy of that we can look
00:30:09 at and then in here we want to get a negative value that's got i think it's going to be three um
00:30:17 of x uh and we want to
00:30:32 um so that's some you know weird number we're getting right five two four two
00:30:39 eight um i really wish that that the c libsy standard library had a printf
00:30:48 function with like binary output options i think that would be really useful sometimes to see what you know what are the bits like you know we can do hexadecimal formatting or you know
00:30:59 decimal formatting um but you can't do like you know this
00:31:03 it'll just crash i'm running this program like you know with address sensation stuff that's why
00:31:09 um but i do have a function that i can use
00:31:16 to get along here not spend too much time trying to fix things
00:31:21 so this little thing will just uh maybe i'll just copy this what i
00:31:26 gotta do okay i can break this out like simplify this a little bit so yes let's string fmt 64.
00:31:42 [Music] capacity this is some sort of destination buffer actually we got we gotta know exactly what size it is now
00:31:50 this this doesn't actually mean much in c but it's it's mostly for the programmers for most of you so we have some value
00:32:00 and we say the base and it can be you know no more than 64. base 2 is the
00:32:05 smallest base right um i guess to make this like nicer we can do
00:32:14 base 2 as the it's the smallest possible base so we just clamp that value there in case we would ever happen to give it like one or zero or something like that and otherwise it would just sort of explode i think or never finish
00:32:27 um okay and we simplify this and we can just do this and then use this thing in
00:32:41 peace [Applause] i'm sure you can write this function in a more efficient way but this this works for me i'm gonna yep it's a destination buffalo
00:32:51 i think this is good nope i'm not stopping you oh
00:32:56 um i have a length value
00:33:26 this list of functions i'm gonna end it to the end here because this is not really like an r a buff
00:33:33 function this is just some string function but you know i'll do okay back to this guy
00:33:41 so now we can have a little how we just release this buffer so now we can pass this [Music]
00:33:48 so the goal here right is to put this in um in binary so we can inspect the value
00:33:55 so we're going to take the the the the action limit update is printed and
00:34:00 then we'll take our value which we want and the base we're going
00:34:07 binary base two and we want to print this buffer
00:34:11 and yeah we can just save ourselves some is
00:34:21 okay now we see that when looking at this
00:34:25 value up here like the oh the least in significant byte
00:34:29 here um let's see let's count it three one two
00:34:35 three four it's all once and then we have another one uh and now we have our actual value
00:34:41 over here all right four
00:34:53 eight now you can all see how how like rusty i
00:35:06 am at the stuff a very long time ago i
00:35:11 a friend of mine had a a pc the dos on it and had basic we would
00:35:15 write or in um basic programs in his basement and we
00:35:19 have no idea what we're doing and it's still true today i guess
00:35:23 um so let's just look at this little macro and see what i'm doing here
00:35:31 maybe i made a mistake here so let's just break this down and mask one
00:35:45 too right so that's just called x
00:35:50 uh so we have our instruction here passing along
00:35:54 and the position right so for excuse me so we have argument
00:36:07 no yeah we're still getting the same result
00:36:23 right it's good again let's double check and make sure that there's let me say something here
00:36:31 just have this little space to separate it from the rest of the print out
00:36:35 just a different function it doesn't have that stuff um so let's see what this mask is
00:37:05 so i'm looking at as what i've done before i kind of left that in so this is
00:37:10 what i've done for this other old project tab called soul
00:37:15 so this is for extracting a um or building a uh cyan digger
00:37:28 i think i can probably just do the inverse
00:37:32 oops um let's try it okay so
00:37:42 um and max here i'm guessing what that is is
00:37:48 the maximum possible value
00:37:52 i have used the the source file over here it's just one browsing from the solid product let's read the instruction and then we
00:38:15 just start out by just upsetting to the
00:38:21 position right so position for b um
00:38:27 is the a position plus the size of a
00:38:32 so five let's say so so it's uh eight plus five
00:38:47 right should i spell right yeah so we're just shifting off thirteen and now we are at
00:38:57 so um this little guy here brings us from
00:39:04 this place to here
00:39:10 this number right there so now right here
00:39:21 and we have now a remaining 19 19 bits um and so that's this mask is is gonna
00:39:27 you know make us a number essentially that represents uh these bits
00:39:32 sounds these set um
00:39:42 actually i wonder i should be shifting no wait wait yeah no no we are
00:39:46 essentially we have essentially done this
00:40:05 so we just make sure that we have the right type it's a u32 so we could
00:40:10 probably also do that if we wanted to but you know this makes it a little bit more portable um and down but what we do is we shift the uh
00:40:20 ship this guy over gosh i should have documented this
00:40:28 butter um just look at the
00:40:54 this uh might be useful to have a reference here
00:40:59 so we have the bit count
00:41:40 so now it's here um and actually
00:41:47 this is our formula function it's not going to
00:41:53 add spaces for us and then we want to pad this out so we
00:41:57 want to be saying that this should be straight straight over there
00:42:16 um okay yeah that'll be good enough we can zero padded two if we want uh there we go
00:42:27 so now we see we have
00:42:33 18 19 uh 19 bits right that we get and that should be the total value stored
00:42:38 the next thing we want to do yeah so that's the master yes we're not that interested but let's look at our value again and we
00:42:48 know this is the those those bits right see in here i guess i can't do column selection that's terminal but um so that's the value we stored now it kind of looks that looks totally wrong to me that looks like it's like a huge number right
00:43:03 so maybe the issue we're having here is in the uh the way this is being stored here
00:43:09 so maybe x here
00:43:26 let's start by breaking this down so x equals
00:43:37 construction of this separation right so this is just going to be some small so it will be number
00:43:49 zero one two three four five six seven this guy
00:43:59 and um just add a little meditation here for ourselves don't take the position of eight
00:44:34 there and we shift this over by the position
00:44:38 right so the value for a so the value and then finally this is kind of like
00:44:47 the the number really care about so first off let's just use zero here to make sure that that we're gonna have an issue that goes through here actually first let's just stop this just to make sure we get the same output
00:45:00 um and this value will be stored in argument b this pc also maybe i may be interested
00:45:12 let's just print this out if i'll do the oldest work because they realize this is where i'm wrong
00:45:29 minus eight you're watching this now and you're like
00:45:50 wishing you can just tell me what i'm doing wrong but i'm sorry i can't hear you something obvious i'm sure
00:46:02 five minus three oh yeah i've been looking by this before
00:46:14 oh it's still it's still wrong but at least now we have the right number okay
00:46:19 um [Music]
00:46:32 so now i'm gonna we got the right number we're gonna start out so that's it's actually minus two which i think is is
00:46:39 going to be incorrect um since we don't increase the pc here
00:46:46 and the compiler is going to be it's going to be angry here because i i'm not
00:46:50 sure if this this might be undefined here
00:46:53 i'm sure let's see what it says it'll be angry yeah yeah and sequence might be i am
00:47:01 um let's just go back to this i'm actually gonna have to find a better way to actually write this
00:47:09 so this is super comfortable bad ergonomics here right so
00:47:13 this is essentially like um well there's got to be a plus here now
00:47:17 yes um so 3 is the correct answer here so after
00:47:23 this instruction we want to go back three so minus minus minus
00:47:29 back here and we so now we should have three
00:47:43 so well then when we solve this we can just go back to everywhere okay so
00:47:54 so this value is going to be minus three um on the macro
00:48:08 what happens if we just essentially cast this
00:48:13 signed negative number to use an unsigned number uh we'll see that we get this really kind of large number which looks especially similar to this might
00:48:22 actually be a number right so let's confirm first expression
00:48:28 plug this into our printing function on here for printing out a binary number
00:48:38 no that's much oh i think it's because i'm not
00:48:43 masculine that's yeah that's probably what's happening but i think i think what's size that's the
00:48:57 size of b which should be established and i forgot what it was uh let's just do slice of b up here
00:49:04 because it's all five no no i'm totally wrong that's the size
00:49:07 of the b the wide sort of thing right so that's 19 i think
00:49:26 okay uh yep that's totally different not at
00:49:36 all the same thing but it's interesting oh no that is the same thing oh look at that so
00:49:46 what we got was this result right
00:49:49 i'm just putting it here so you can see that it's the same thing
00:49:58 so that's what's going on right so um and that is what we expected to
00:50:03 happen right that is fine uh we cast this number and they are we are masking out to remove the um the
00:50:10 bits over here or yeah the bits over here that we didn't care about it was and maybe that's maybe that's where i'm
00:50:24 so this is a function that i use or micro they used
00:50:28 uh in this other project uh and i don't know maybe i figured out maybe i learned it from someone else
00:50:34 but let's see what happens if we use this instead so we're casting us that's the same thing going on right and then instead we're um
00:50:57 let's just put out the definition of okay
00:51:16 so we have the max value of that of that number which is like this in all
00:51:23 ones right um so oops 19
00:51:40 so that's what we're going to put in here there's you know operator precedence
00:51:56 obviously in different programming languages like you know which
00:52:00 which thing happens first right is like this thing added to uh to this thing then the
00:52:09 result is divided by two or is like this thing divided by two and then added
00:52:13 together like in c um this is you know this as the same result
00:52:19 like division and multiplication has high precedence happens before like
00:52:25 you know subtraction and addition um and then bitwise operators uh and bitwise a lot of different stuff like that has like lower precedence and
00:52:35 and in some cases irritating latency and this differs between bringing minors like equality operator has
00:52:43 i hope i'm not wrong like um like a higher precedence than like this
00:52:47 so if you do like you know if x is like y and
00:52:51 flag then what what happens is like this is evaluated x
00:52:57 equals y and then the result of that which is you know a
00:53:02 one or a zero is that um ended together with the flag right so so you'll you'll see you'll see programs like that written like this but then if you go to like a different programming language like go for example like this you know has higher precedence than the quality operator now
00:53:16 aside um i often try to put parentheses around so
00:53:26 not always i'm not a great like you see up here i'm just like doing
00:53:31 actually there's no other operators going on so maybe i'll give myself an okay for that one okay
00:53:36 um enough rambling uh
00:53:40 okay so we plug that in here so see where we at uh so we got this weird number where are we
00:53:54 okay let's see if we can get this so first we take the
00:54:02 um our number negative three all right we convert that to um
00:54:08 an unsigned number just recapping here since i it took me a little while to get
00:54:13 the uh the camera going here so what we got is is this number over
00:54:17 here so that's our first like
00:54:25 an unsung integer it's we're just sort of overflowing so if we take this
00:54:33 um oh i see what's happening so we add two
00:54:45 to it and then we have three to it oh we got zero so that's what's going on right um we have that this is an onsite
00:54:52 number now this essentially if we add three to this
00:54:56 right the maximum unsigned 32-bit so all bits
00:55:06 one is this number so when we take this we take this number this is essentially
00:55:12 the same as doing this all right we got this and do all um that
00:55:22 the next thing we do is take the maximum value that can be stored in this field
00:55:28 um with the half of that and we add it which is i'm just trusting my my old
00:55:34 self here so it might be the older wrong um okay so we're doing that
00:55:43 let's just skip the mask we definitely need to mask that out but now we have
00:55:48 um i have this number up here maybe i should put it's not variable so we can so let's put in uh
00:56:01 we already have a variable for this right it's the x-ray of it so you can just use that and so we print it in decimal and then
00:56:24 let's print it in binary so we got in decimal
00:57:05 inside now we'll also print it as okay so there we go we got it
00:57:42 now let's see we have the space and then let's make sure that this is actually a correct value right
00:57:59 so we have 19 so let's see we're going so five of those
00:58:06 time 20 so that's 19.
00:58:15 yeah okay so that's the maximum possible value
00:58:36 the mask and that's that doesn't make any sense it should be
00:58:44 so now working backwards this other thing so this construction thing right
00:58:48 so it takes the operation and everything is smashed together we're not going to do that but we are going to have to shift this over right and then i think it's the final piece of the puzzle here
00:58:59 um so let's let's leave the
00:59:04 mask alone for a second so we're going to shift this over by
00:59:08 um the the the size
00:59:13 is that right the position so now we'll put it in the right place
00:59:22 for the um in our instruction
00:59:31 it'll move it from over here up to here whoops right so we should be seeing if we
00:59:46 i'll look at can't do this for me but okay
01:00:02 so now
01:00:08 [Music] we are going to shift the number there we go yeah that's the same number
01:00:31 right and we have shifted over by um
01:00:36 by its its position right which is five plus eight so that's what's happening so now we have the value up there so
01:00:52 that's what we want eventually and i think debugging this is going to be easier to to do without that because we use round trip and we shift it back right so it
01:01:01 wouldn't really matter uh so this is the value we want so now
01:01:06 i'm going to do an inverse of this um [Music] okay that looks promising
01:01:21 um so this and the other solved thing just
01:01:26 extracts this value so that is equivalent to just x like this
01:01:32 this again is the max value and now this makes a lot of sense based
01:01:39 on there um so if we do x to see where we get the
01:01:47 and let's see now maybe we want this to so let me get me my sheet
01:02:05 okay so that's cool now we know what to do right first off you're gonna need a
01:02:09 max value um and i just gotta plug this in for now but we can be more clever about it uh
01:02:14 for the different elements
01:02:18 uh uh so let's do max
01:02:27 also pardon my like naming here this is like not very convenient naming is it but
01:02:34 that's it's which my editor can just be like hey shove it isn't hexadecimal i'm sure it
01:02:41 can but i probably just don't know i guess you just
01:03:13 max value and we work our way back again to some
01:03:19 sort of macro begins right so this is extract
01:03:49 so set arg and we can need one of these which does this
01:03:58 all right encode um [Music] plus you know we also need to shift it over as we was doing before to get into
01:04:09 the the right position in the um in the instruction and we have two of these actually there you see there's a make function here and then there's a
01:04:16 set function here um so we're gonna have to a
01:04:32 i guess well but i'm thinking about like this
01:04:40 qsb a little extra macro we have to use let's just try this uh define s arc
01:04:54 i'm just reaching here and i keep hitting like the the wrong key on my keyboard not just like for some reason that
01:05:07 let's just see the editor has many ways to i use like
01:05:12 different keys now to switch it has like four maybe different key combos to switch and don't know about that so sr you pass like some a science
01:05:22 number in here and then this would convert it into just like uh you know
01:05:26 an argument that's not signed so we just do this and take the x in there
01:05:32 the value we practice using that to make this much more robust
01:05:37 and keep these out to make it clear and then we can also have to bring the max
01:05:42 value here of that right so maybe we will end up actually with a
01:05:47 but a couple of helper macros but max and so what we would do is um to set an
01:05:59 argument we would set argument the number of it and b will be you know number uh number one right
01:06:06 uh sorry the value of it
01:06:10 which in our case is three uh and then the position of the arguments so we have these position
01:06:16 which are bit offsets b 13 bits maybe
01:06:25 okay it doesn't matter so the offset b um and then we have the the
01:06:32 size of b um this would not work right now this is
01:07:03 what i was doing right because this is just not going to give us the correct and this would give us the right amount
01:07:17 see if we have done nothing
01:07:22 so first off we're just gonna um do that for now
01:07:27 and make a copy here of the
01:07:34 instructions as we modify this you don't want to spend time like writing this code on here and then do um set so b
01:07:45 w right on y so we're gonna change that part of x
01:07:53 uh we have the position session
01:08:01 and we have the size of the w the white one 19 bits and then finally
01:08:10 to make [Music]
01:08:18 too few arguments oh yeah since we also have to prime the max value here so we have the max pw volume
01:08:28 and now if we do still working yeah okay
01:10:08 yeah okay good good dumb mistake there so where is the mistake done um
01:10:22 now we have to define y first [Applause]
01:10:50 see sometimes just like end up in these things i don't know this is
01:10:55 might take another hour or two for me to figure this out it's um
01:11:01 it's not my strong suit this stuff um it's also incredibly boring but you
01:11:05 know you just gotta do it but i think i'm just gonna end it here and i'll
01:11:10 loop back later about how um how i went if it's anything
01:11:14 of interest and i think beyond this um this is going to get this you know the format and this stuff working i think it's very important to get these like tiny little things that might seem very tedious to like double check everything but like
01:11:30 once i'm through with this and i've you know made sure that every 10 little thing is is working as intended i can
01:11:36 trust those things right i don't have to re revisit that when there are other
01:11:40 bugs in the future i don't have to question these things as being the course of those bugs um and that at
01:11:46 least to me is a really nice way of working um it's almost like in a in an
01:11:51 analogy a metaphor imagine like building you know a car or a house or a spaceship
01:11:56 or something like that um if you test like the screw right you
01:12:01 make sure that the screw works and then you test the sheet metal and you make sure that that works and it's the specification and then you put the screw
01:12:09 and the sheet metal together and now you test those two together right now you put the the the you know
01:12:16 this component with that component together and you test that and so on as soon as like you you test things and you have issues right then you can be fairly
01:12:24 certain that it's not the screw because that already tested clearly right so it's probably the combination of the two or maybe one of the other parts and so
01:12:32 similarly goes here so that's my maybe it seems like ridiculous to spend so much time trying to get this right and not just going like google it or something like that uh so that's what's happening also you know this project is a is a learning
01:12:43 opportunity and and in some aspects like learning about stuff that i don't know and some things to refresh the memory of things that are forgotten so yeah okay well
01:12:54 i'll catch up later see ya