13 hours 15 minutes
Hello. This is Dr Miller, and this is Episode 2.1 of Assembly.
Today we're gonna learn about assembly language and suddenly in assembly instructions identify IRS directives and then creating enlisting of a file
So machine language is the low level that a machine uses in order to execute instructions.
And so, for example, if we would like to add e x t b X and then store the result in E X,
we would run the machine instructions. 03 c three.
Now, clearly, that's not very readable. And it changes with different processor types,
and so a better
language is needed and that languages assembly.
So given the machine language 03 c three, in order to do the movement of data, we have the assembly language. Add yaks, EBX. So so add those two registers together and then store the result in E X.
Clearly, this is more readable, and it is a higher level language than writing something
in binary In hex
from a previous lecture, you should recognize that this is hex, given the zero X and the letter C in there
and then we for different architectures, we can keep the same code and end up getting the right result.
Additionally, optimization is could be made, so if you have code that is not working or is not needed, the assembler and or compiler can get rid of those or pick a different instruction at the low level that will be faster.
And then the format of incessantly instructions is we have a pneumonic or something that you can remember and then that is followed by operations.
Now there is a difference between an assembler or compiler. So with an assembler, generally there's a 1 to 1 ratio of assembly instructions to machine code,
and an assembler is machine dependent. So if I write something an assembler for X 86 I have to write completely different code for arm or for spark.
Whereas if we have a compiler again, it's one higher level abstraction
and so one high level line to create a variable or move some data. My generate many machine and assembly instructions,
but the benefit of it being higher level is that it's more portable, so you can write something in C, and if you have a compiler, it can compile a to X 86 code or can compile a tow arm code, and you don't have to change the the high level code.
Now. This is not always the case, but generally it is the case.
So the assembler we're using for this class is Nazem, and so with that were actually underneath it using the canoe compiler can collection. So this is a compiler that will compile code.
And then we're also using the C programming language to interface with GCC.
And then we should also be using make. So that's part of our template uses make in order to build the program
So again we have a pneumonic and then that is followed by operation. So the pneumonic is add, whereas the operations are what it's going to do that operation on.
We have three general types, so we have registers as we saw. Yea x ebx ccx are registers
memory locations, which will look at later
and in immediate value, so that's an actual value that's hard coded inside of the binary.
Additionally, we do have implied so, for example, an increment will
effect a register by default. It's a little add one to that register or or deck a minute will decrease the register by one.
So example instructions. So we have our demonic, which is move.
And then we have the register, e B X, and we also have the the hard coded value. Seven. Right? So the seven is an immediate and then e b X is a register.
Here we have two registers, so movie a X ebx
So that says that E B X's value is going to go get copied into E x
or increment e x or deck Ament e x. So those again would incremental deck Ament that register.
And the way that instructions are in Nazem is that we have an optional hurts. The brackets mean optional. We have a label
followed by a pneumonic, so we have to have a pneumonic. And then if a demonic doesn't have implied operations, we need some operations, and then we have an optional comment. And so here's some example. Demonic smoove ad.
Notice that they aren't necessarily spelled right. So there's no eon move.
Um, jump doesn't have a you.
Um, but those are examples of new Monix and then all of the Monix that will learn
and then comments. So a comment starts of the semicolon. So if you used to programming and see,
you might just put a semi colon at the end of your statements. But that is a Nazem comment.
So directives air, not actual instructions. They just tell the assembler that you want to do something you wanted to. For example, set the size of the stack, defined some memory to find some constants,
so directives air are for humans to make things easier, but they aren't actual assembly instructions.
So, for example, percent define.
So if you've programmed in a language like C pound, define allows us to create Constance. So also percent defined does so. It says percent define size tens every place that will see size. It just replaces it with the actual value of 10.
So this instruction would be the same as movie a X 10.
We have data directors, which we will have to do a lot of,
and so the D stands for define. So we got define a bite to find a word and define a deed word. Remember, a bite is one bite, which is a pits. A word is two bites or 16 bits and a double word is 32 bytes
So throughout the course, you're going to be creating different variables or identifiers. And so we need to know how to define them and what er actually allowed.
So we use them for variables, constants, procedures or functions
the main key here is that you need to start your variables basically with a letter. It's lets the easiest way to start it. And then you can add some of these additional characters. But generally, most of my variables
would just have letters, possibly numbers within them, and then maybe underscores to make things more readable.
All right, so here is someone examples of addition and subtraction. So movie X 100 in hex
ad E X 400 hex. So one plus four should give us five
and then subtract GX 200 hex. Right, So that should give us 300 hex.
So if you open up your editor, you can type this code in and see what the result is.
Um, the dump regs one. We'll just print off what all the registers are.
I mean, then it puts the number one in front of it. So it does
hashtag number one. And so you can call dump regs multiple times and you'll see, um, each one of those You can put a different number in there,
So if you have the template already set up, I would go ahead and positivity. Oh, and I would enter this in and see what it produces and maybe change the numbers in here and see if you get a different result
generating a listing.
So listening will give us information about offsets and binary code for commands. And it also will help us when we're trying to find Ares.
So this is to tell us that we're using the program. Nazem were using Elf because I'm on Lennox.
I'm naming the listing, and then this is the example that I want to do for it.
So I'm gonna go ahead and switch to a
terminal window and go ahead and do that,
so I'm going to create my project here.
I'll just call it 2.1
now if I look inside my directory of my projects. So I already entered that before I started. I have a directory called 2.1.
And now I should have my assembly file, so I'll go ahead and add it it.
And so let's put some
code in here.
So I'm just going to move the value of negative 10 into yea X. Maybe I do another one.
I'll go ahead and write and quit.
I can run make in order to make sure that my program will assemble and compile.
So you can see right make is the program that we've been using its running the command Nazem. And it's also running GCC in order to generate our output.
And then the driver dot c is the program that
provides a skeleton so that our program can run
And so if we want to generate a listing
All right, so Nazem minus f elf. So that's the type of execute herbal.
Um minus l is the listing father we're going to generate and then 2.1 dot es, um is a file that I want to use for that.
So now I can look at that. I can use a program like cat, which means can Katyn eight or print to the terminal
so we can see in here that
our this is our A s a main, and we can see the different instructions.
the instruction to move something into E. X
is this Be eight,
and then we can see we've got a bunch of EFS and a six.
So again, remember that this is stored in two's complement, which we talked about in a previous lecture.
So and it also stores that a little bit backwards. Right? So the first bite is right here.
The second bite is right here. The third bite is right here in the fourth bite is right here,
and we'll talk about in in subsequent lectures about little Indian versus big Indian and why it looks like this.
But this is the actual number negative 10 stored in two's complement. And then we can see that in Hex
in our listing or the number 20 so 20 is 14 and hex. It's a 16 plus a four,
and then we can see minus 30.
So if you want practice on your two's complement, pick a number that you want to do. So say negative 76 try and figure out what it's binary representation is figure out what it's hex, a decimal representation is, and then go ahead and
convert it and then build a program that does it generate a listing and then you can see what the result is.
So here is an example that I had run before again. You see the B eight, which has moved something in the X, and then we have the number 01 which is the number one.
Additionally, we have commands that we can run in order to view data. That's inexcusable.
So, like a listing. So *** D is going to give us Raw hex by default, it prints the actual data that's in the file. Amenity also can convert from its its output back into binary if you need to.
So, for example, my execute Herbal is called 2.1, so I can say *** d
internal print, all of the raw bites, and we can actually see some Maskey characters
in our file.
The represent different things that are included inside of the binary file,
so that's kind of interesting.
Additionally, we can run, object, dump social, print off the disassembly of a binary program, and so if you have a binary program that you want to look at and you want to see the assembly of
We can run, object, um, so object dump. And then we are using Intel's in tax. So you need to set the disassemble options to Intel.
The minus D is to do disassembly, and then the aid out out is the name of the program that you want to run it on.
So let's go ahead and run it on our program
and so you can scroll through here and you can look at the actual disassembly of that program
or the assembly
that a dis assembler figured out. So dis assembler is just a program that is going to
go and convert all of the
the functions in the data into assembly code.
So we can see here that we put in our numbers as negative numbers or positive numbers,
and the disassembly is going to show us that raw number and not necessarily
the number and base 10 that were used to.
All right, so in summary, we learned about assembly language and assembly instructions,
identify IRS and directives and then creating a listing of a file and looking the contents of a file that you might have that you want to look at
looking forward, We're going to talk about logical operators, segments and functions.
If you have questions, you can contact me at Miller MJ at you and Kate. I e do you or you can find me on Twitter at Milhouse 30?
How to Use GDB (BSWJ)
The GNU Debugger (GDB) is one of the most commonly-used debugging tools in the world. ...
Certificate of Completion Offered
How to Use IDA (BSWJ)
The IDA is used throughout the IT and cybersecurity industries by exploit developers, vulnerability analysts, ...
Certificate of Completion Offered