Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 368 Vote(s) - 3.57 Average
  • 1
  • 2
  • 3
  • 4
  • 5
So you want to learn assembly ( Part 1 )

#1
-=-=-=={Introduction }==-=-=-
Greetings all, today I will be talking about assembly: what it is, how to use it and some external resources to learn more. I hope this will help the newcomers to get a feeling about it and know where to look for in the future.

Disclaimer: I'm by no means an expert in assembly, thus all I'm going to present it's based on self-research and experience along the years. Therefore, any productive criticism is welcomed.

-=-=-=={You need to know this in order to continue }==-=-=-


The CPU
========


The CPU is one of the most important components that computers have. Thus, understanding how it works and how it communicates with other components it's an essential part in order to learn assembly. So let's have a look at what is composed of:
  • A set of registers
  • An Arithmetic-Logic Unit (ALU)
  • Some control logic.


1. Registers
Let's start by looking first at the registers.
Registers are just a small piece of memory inside the CPU that are used to quickly accept, store, and transfer data. Because they are so close to the CPU, they are super fast at doing their job. There are different types of registers as well, that indicate different things. For example the RSP and RBP are some of those for the 64bit architecture:
  • RBP point to the base of the current stack frame
  • RSP point to the top of the current stack frame

They can be numbered starting from 0 like the memory or they can be named.
Don't bother to much for now with what they're doing and how to use them, I will explain it more later. For now, just remember that registers are a small piece of memory inside the CPU that helps it to execute, store and transfer data.



2. The ALU
The Arithmetic-Logic Unit is basically just performing arithmetic and logic operations. It can add, subtract, multiply, divide, xor, and, or, etc. That's pretty much what a computer does most of the time.
The ALU performs those operations with the values stored in the registers or values taken from memory. For storing them it uses the registers or it stores the values in a memory address. The available options actually depends on the processor. Yeah, that was pretty much it for the ALU.

3. The Control Unit
The last part of the CPU that we are interested in is the Control Unit. The Control Unit is anything else inside the processor except the registers and the ALU (branch prediction unit, cache management, bus signaling, pipeline management, etc). However, it has some functionality that we are interested in and that's pretty mandatory.
One of those being to control the CPU external interface. In other words, the state of all those little pins that go out of the CPU chip. Using these pins, the processor can talk to the memory to read and write values and can also interface to different types of hardware…

Basically when the ALU needs some data from memory for performing an operation, it asks the control unit to activate the right pins on the processor to command the memory chip to read or write a given memory position. To better visualize this I found this picture on the internet that might help:

[Image: machine-cycle.jpg]

Here are some other functions of the Control Unit:
  • Regulate transfers of information between memory and I/O.
  • Fetches and decodes instructions from microprograms.
  • Responsible for correct instruction execution between a processor's many sub-units.
  • Control unit converts received information into sequence of control signals, and transfer to computer processor.
  • It controls data flow inside the computer processor.

-=-=-=={Machine Code }==-=-=-

Machine code is binary (1's and 0's) code that can be executed directly by the CPU. If you were to open a machine code file in a text editor you would see garbage, including unprintable characters.
So in the old days, some tech savys thought of a way to be easier for us, humans, to understand and write machine code. Therefore assembly was created. You can think of it as a mapping between 0's and 1's to words.
However, keep in mind that the CPU doesn't understand assembly, thus we write assembly code and with the help of an assembler or a compiler, we convert the assembly to machine code.


-=-=-=={A simple fictional processor }==-=-=-

Ok, now you should have a basic understanding of how processors work, so let's make a fictional one. We will call it from now on HAM-201.
Now, in order to proceed I need to step back for a little and start explaining what the Instruction Pointer ( IP ) is. This is a special register that indicates which memory address in the main memory contains the next instruction to run. Whenever the CPU executes an instruction, this register increments by one ( unless it's a jump/branch instruction ) therefore moving to the next address to execute.

Now let's take a look at the specifications for our processor:

  1. We will have 3 registers: EBX, EBP and RIP, the last one being the instruction pointer.
  2. The ALU can perform just a MUL --> multiplying 2 numbers
  3. It will have an instruction MOV to assign values to registers

Now we need to define what instructions it can run. In our case, this will look something like this:


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.




As you can see we have 3 columns, the first one is containing the actual machine code, second one the assembly and the 3rd one is a short description.
Now let's go and build our first program ! :biggrin:


-=-=-=={Our first program }==-=-=-

Let's make a simple program that multiplies 2 numbers.


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.



So, our program requires 8 bytes of memory, thus our RIP is going to need to increment 7 times, because we start from 0.


-=-=-=={Conclusion }==-=-=-

That's it folks, I hope you learned something new and that you enjoyed the time spent to read this. I will come back with more tutorials for assembly if you guys want it. As we go down the road, I might start discussing about more complex things. Don't forget to rep me if I helped you somehow, and look at the resources section to learn more about the topics covered today.
Thanks again for your time, cheers ! :biggrin:


-=-=-=={External Resources }==-=-=-

[To see links please register here]

[To see links please register here]

[To see links please register here]

[To see links please register here]

[To see links please register here]

[To see links please register here]

Reply

#2
Bumping this because maybe someone will find it useful
Reply

#3
I shall quote @"phyrrus9".

This Is his forte, so I'm sure he'll find this of Interest.
Reply

#4
Quote:(11-10-2018, 05:08 AM)mothered Wrote:

[To see links please register here]

I shall quote @"phyrrus9".

This Is his forte, so I'm sure he'll find this of Interest.

This is more targeted for newcomers that want to learn assembly and don't know where to start, so without any doubt he already knows this stuff.
Reply

#5
Quote:(11-10-2018, 08:47 AM)Cr3aTor Wrote:

[To see links please register here]

Quote: (11-10-2018, 05:08 AM)mothered Wrote:

[To see links please register here]

I shall quote @"phyrrus9".

This Is his forte, so I'm sure he'll find this of Interest.

This is more targeted for newcomers that want to learn assembly and don't know where to start, so without any doubt he already knows this stuff.

Yes, judging by your Introduction of the CPU & Registers (which Is quite basic), It's obvious It more so targets those with minimal knowledge.

Be It the absolute basis or the utmost advanced, phyrrus9 enjoys this type of content, hence the quote.
You've documented, elaborated and formatted It quite well. Good work.
Reply

#6
Quote:(11-10-2018, 10:09 AM)mothered Wrote:

[To see links please register here]

Be It the absolute basis or the utmost advanced, phyrrus9 enjoys this type of content, hence the quote.
Oh, I hope he is going to have a great little read then.


Quote:(11-10-2018, 10:09 AM)mothered Wrote:

[To see links please register here]

You've documented, elaborated and formatted It quite well. Good work.
Thanks for the kind words.
Reply

#7
Quote:(11-10-2018, 11:31 AM)Cr3aTor Wrote:

[To see links please register here]

Quote: (11-10-2018, 10:09 AM)mothered Wrote:

[To see links please register here]

Be It the absolute basis or the utmost advanced, phyrrus9 enjoys this type of content, hence the quote.
Oh, I hope he is going to have a great little read then.


Quote:(11-10-2018, 10:09 AM)mothered Wrote:

[To see links please register here]

You've documented, elaborated and formatted It quite well. Good work.
Thanks for the kind words.

You're welcome.

Thanks for taking the time to contribute a HQ thread.
Reply

#8
While I understand this is geared towards beginners and written by someone that hasn't had to dig deep enough to know the distinction between these, I'll offer them as background material to think about.

Quote:(11-04-2018, 02:03 PM)Cr3aTor Wrote:

[To see links please register here]

today I will be talking about assembly: what it is, how to use it

Be aware that the term assembly isn't quite as unique as this thread may imply. Assembly refers to an entire class of "languages" that describe machine code. Historically every model of processor had a widely different instruction set (machine code), and therefore had a very different assembly dialect. More modern processors try to use common ISAs, and so they look similar, but they are not. There isn't enough actual assembly in this thread to tell you which ISA, but it looks pretty close to both AMD64 and 686.

Quote:(11-04-2018, 02:03 PM)Cr3aTor Wrote:

[To see links please register here]

The CPU is one of the most important components that computers have. Thus, understanding how it works and how it communicates with other components it's an essential part in order to learn assembly. So let's have a look at what is composed of:
  • A set of registers
  • An Arithmetic-Logic Unit (ALU)
  • Some control logic.

This list should also include the following:
  • Floating point or fuzzy math unit (if CPU is newer than 1987)
  • coprocessors
  • memory management unit
  • instruction queue and pipeline
  • caches

Quote:(11-04-2018, 02:03 PM)Cr3aTor Wrote:

[To see links please register here]

Let's start by looking first at the registers.
Registers are just a small piece of memory inside the CPU that are used to quickly accept, store, and transfer data. Because they are so close to the CPU, they are super fast at doing their job. There are different types of registers as well, that indicate different things.

This isn't quite true. Registers are the ONLY memory your CPU has access to. They're almost always the same width as the main bus, and these are crucial to the operation of your processor, as almost all of them (and all modern ones) only do operations on registers. AMD64 ISA includes instructions that act on RAM, however in the first set of pipeline stages, these are converted to a stream of microcode instructions that will retrieve the value, store it in a register, do the operation on the registers, then store the register back into RAM.

Quote:(11-04-2018, 02:03 PM)Cr3aTor Wrote:

[To see links please register here]

They can be numbered starting from 0 like the memory or they can be named.
Don't bother to much for now with what they're doing and how to use them, I will explain it more later. For now, just remember that registers are a small piece of memory inside the CPU that helps it to execute, store and transfer data.

This is ISA specific. AMD64 uses modern ARM-like register naming (R0-Rx), ARM used R0-R15, AArch64 uses X0-X31, SPARC uses a bunch of different letters all with a number attached to them. This is absolutely something you need to know intimately when you begin.

Quote:(11-04-2018, 02:03 PM)Cr3aTor Wrote:

[To see links please register here]

Here are some other functions of the Control Unit:
  • Regulate transfers of information between memory and I/O.
  • Fetches and decodes instructions from microprograms.
  • Responsible for correct instruction execution between a processor's many sub-units.
  • Control unit converts received information into sequence of control signals, and transfer to computer processor.
  • It controls data flow inside the computer processor.

This was true up until the late 80s, when computer processors became more complex, multicore, used caching, branch prediction, and longer pipelines. The "Control Unit" being referenced here is simply the small amount of logic that controls pipeline flow (assuming OOX doesn't exist, we're not getting into that here). If you're more curious, go look up a pipeline diagram for your specific processor. As an example, here's the PL from a relatively old Intel CPU (note, every core has one of these)
[Image: sandybridge_pipeline.jpg]


I'm not going to get into the very platform specific stuff below this, for all intents and purposes it's close enough.
Reply

#9
Thank you for taking your time to read and correct me, as said in the thread I'm by no means an expert and still learning.
So thanks for the additional information which is helping me and other users.
Reply

#10
Quote:(11-04-2018, 02:03 PM)Cr3aTor Wrote:

[To see links please register here]

-=-=-=={Introduction }==-=-=-
Greetings all, today I will be talking about assembly: what it is, how to use it and some external resources to learn more. I hope this will help the newcomers to get a feeling about it and know where to look for in the future.

Disclaimer: I'm by no means an expert in assembly, thus all I'm going to present it's based on self-research and experience along the years. Therefore, any productive criticism is welcomed.

-=-=-=={You need to know this in order to continue }==-=-=-


The CPU
========


The CPU is one of the most important components that computers have. Thus, understanding how it works and how it communicates with other components it's an essential part in order to learn assembly. So let's have a look at what is composed of:
  • A set of registers
  • An Arithmetic-Logic Unit (ALU)
  • Some control logic.


1. Registers
Let's start by looking first at the registers.
Registers are just a small piece of memory inside the CPU that are used to quickly accept, store, and transfer data. Because they are so close to the CPU, they are super fast at doing their job. There are different types of registers as well, that indicate different things. For example the RSP and RBP are some of those for the 64bit architecture:
  • RBP point to the base of the current stack frame
  • RSP point to the top of the current stack frame

They can be numbered starting from 0 like the memory or they can be named.
Don't bother to much for now with what they're doing and how to use them, I will explain it more later. For now, just remember that registers are a small piece of memory inside the CPU that helps it to execute, store and transfer data.



2. The ALU
The Arithmetic-Logic Unit is basically just performing arithmetic and logic operations. It can add, subtract, multiply, divide, xor, and, or, etc. That's pretty much what a computer does most of the time.
The ALU performs those operations with the values stored in the registers or values taken from memory. For storing them it uses the registers or it stores the values in a memory address. The available options actually depends on the processor. Yeah, that was pretty much it for the ALU.

3. The Control Unit
The last part of the CPU that we are interested in is the Control Unit. The Control Unit is anything else inside the processor except the registers and the ALU (branch prediction unit, cache management, bus signaling, pipeline management, etc). However, it has some functionality that we are interested in and that's pretty mandatory.
One of those being to control the CPU external interface. In other words, the state of all those little pins that go out of the CPU chip. Using these pins, the processor can talk to the memory to read and write values and can also interface to different types of hardware…

Basically when the ALU needs some data from memory for performing an operation, it asks the control unit to activate the right pins on the processor to command the memory chip to read or write a given memory position. To better visualize this I found this picture on the internet that might help:

[Image: machine-cycle.jpg]

Here are some other functions of the Control Unit:
  • Regulate transfers of information between memory and I/O.
  • Fetches and decodes instructions from microprograms.
  • Responsible for correct instruction execution between a processor's many sub-units.
  • Control unit converts received information into sequence of control signals, and transfer to computer processor.
  • It controls data flow inside the computer processor.

-=-=-=={Machine Code }==-=-=-

Machine code is binary (1's and 0's) code that can be executed directly by the CPU. If you were to open a machine code file in a text editor you would see garbage, including unprintable characters.
So in the old days, some tech savys thought of a way to be easier for us, humans, to understand and write machine code. Therefore assembly was created. You can think of it as a mapping between 0's and 1's to words.
However, keep in mind that the CPU doesn't understand assembly, thus we write assembly code and with the help of an assembler or a compiler, we convert the assembly to machine code.


-=-=-=={A simple fictional processor }==-=-=-

Ok, now you should have a basic understanding of how processors work, so let's make a fictional one. We will call it from now on HAM-201.
Now, in order to proceed I need to step back for a little and start explaining what the Instruction Pointer ( IP ) is. This is a special register that indicates which memory address in the main memory contains the next instruction to run. Whenever the CPU executes an instruction, this register increments by one ( unless it's a jump/branch instruction ) therefore moving to the next address to execute.

Now let's take a look at the specifications for our processor:

  1. We will have 3 registers: EBX, EBP and RIP, the last one being the instruction pointer.
  2. The ALU can perform just a MUL --> multiplying 2 numbers
  3. It will have an instruction MOV to assign values to registers

Now we need to define what instructions it can run. In our case, this will look something like this:


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.




As you can see we have 3 columns, the first one is containing the actual machine code, second one the assembly and the 3rd one is a short description.
Now let's go and build our first program ! :biggrin:


-=-=-=={Our first program }==-=-=-

Let's make a simple program that multiplies 2 numbers.


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.



So, our program requires 8 bytes of memory, thus our RIP is going to need to increment 7 times, because we start from 0.


-=-=-=={Conclusion }==-=-=-

That's it folks, I hope you learned something new and that you enjoyed the time spent to read this. I will come back with more tutorials for assembly if you guys want it. As we go down the road, I might start discussing about more complex things. Don't forget to rep me if I helped you somehow, and look at the resources section to learn more about the topics covered today.
Thanks again for your time, cheers ! :biggrin:


-=-=-=={External Resources }==-=-=-

[To see links please register here]

[To see links please register here]

[To see links please register here]

[To see links please register here]

[To see links please register here]

[To see links please register here]


great tutorial
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through