Hello, this is Dr. Miller, and this
is Episode one point three of
Assembly
today we're going to be learning
about computer organization
registers, history
and the different modes and paging
and interrupts.
Computer organization,
so the way that a computer is
organized is it has registers
some flags that tell us information
about the registers memory,
which is allows us to store data and
memory addresses, which tell us
where that data is, input
output and then computational
units.
So for memory, we have the basic
unit of memory, which is eight bits,
which is one byte.
And then as we've talked about,
ASCII characters take up one
byte and then Unicode characters
take up either one, two
or four bytes.
And then inside of assembly we have
these different units.
So we have a word which
is two bytes.
We have a double word, which is four
bytes, and then we have a code word
or a Q word, which is eight
bytes.
So for the CPU, we
have that the CPU executes
machine code.
The way that it does this is it
fetches the information that it
needs. It decodes the instruction
in order to decide what it needs to
do, then executes that
instruction within itself and
then it stores the results
of it to either two registers or two
main memory.
Additionally, we have the arithmetic
logic unit or Aliu.
And so the CPU might, in
decoding, decide that in order to
execute that command, it has to send
data to the ACLU.
And the ACLU will perform basic
mathematical operations
like multiplication and division,
whereas some other operations
will execute right on the CPU.
Additionally, we have the floating
point unit, so the floating point
unit will perform floating point
math and this will allow it to
do multiplication division
addition on numbers that have a
decimal point within themselves.
Registers,
so registers are very high speed
memory, there are very small,
so they do not use
very much space, they don't have
very much information
within them, but we have a
few of them.
And so each one of these registers
is broken into multiple parts.
The next slide will show a diagram
of that, but basically it
is thirty two bits and then
X is a low half of X
the low sixteen bits.
A-L is a low eight bits
of X and H is the high
eight bits of X
and we have several general-purpose
registers. So these include yak's
SBX, X and IDEX.
As you can see, they didn't
make a lot of effort into naming
them fancy things and we see ABCDE.
So for example X again.
Yeah, X is thirty two bits
and we can see that X is the
low half of that, H
is the upper eight bits of
X as well as the lower
eight bits of X.
And so if you move data into A-L
inherently.
Right. That is modifying
X and X as
well or if you modify H
and the same is true for the
B, C and D registers.
So SBX, X and IDEX,
they're split into these smaller
parts.
Additionally, we have registers like
IACI and Eddi and
then E.S.P as our stack pointer and
EBP is our base pointer.
Register usage, so generally
registers have a particular usage
that is typical for them,
and for example, we have
X is our accumulator, so
it accumulates results and
then it's used for when a function
returns, we have X,
which is generally used as a
counter, ESP is our stack
pointer. So it's used for this
stack.
Essi and Idei are the
source and destination for data
transfers.
SBP is the extended
base pointer or frame pointer
and we use that for functions that
we'll call the stack in order to
allow us to access parameters
and arguments.
MDX and Yak's are used when
we do multiplication and division
and then IP or IP
is the current instruction that is
going to be executed on the
processor and generally
this cannot be modified directly.
So you can't directly set IP,
but it modifies itself
as the program is executing, and
then you can indirectly modify
it by using instructions like return
and call.
So Flagg's store information about
what happened in a previous
instruction,
and so you'll see them annotated
with off.
So this is the annotation and then
this is what they mean.
So we have a Kerry flag, an overflow
flag, a sign flag, a zero flag.
Each one of these means that a
specific.
Action happened while the
instruction is executing,
so, for example, an overflow, if we
try to store the result of adding
to thirty two bit numbers
and it takes thirty three bits
to store that result, then we end up
with an overflow or the sign
flag means that it was either
positive or negative or the zero
flag, meaning that the result
was zero when we did the operation.
So if I take a minus, a
zero flag will be set because the
result of that is zero
segment registers.
These are used to store information
about where different segments
are located.
So, for example, we have a segment
for the code data stack
and then we have additional ones.
And so these got added on later
on in older architectures.
They used to use the different
segments to tell the processor
where these different pieces of
memory could be.
And so we had a segmented
architecture in previous iterations.
So some more history and the
different modes that our processor
can run in.
So there are a lot of different
processor families.
You'll hear people talk about the
80, 88 or the eighty
eighty six.
So these had 16 big registers.
They were named a SBX
decs side.
So you can see names that we see
kind of later and we'll see that in
a bit.
Then we had the eighty to eighty six
or people just call it the two
eighty six.
So this introduced protected mode.
We have the three eighty six which
added thirty two bit in the mode.
So now our registers need to be
bigger.
So what they did is they just added
an E in front of each one of them.
So that way they could have more
bits and programmers could tell if
they were using the 16 bit register
or if they could using the thirty
two. But register we
got the forty six, which just was a
bump faster.
And then we have Memex.
So these added the multimedia
instructions.
Now, modern processors have
additional capabilities, including
built in a yes encryption
and decryption, if you look
at some of the phones produced
by Apple, they have a secure enclave
which implements cryptography
on another chip.
And then we have 60 forbad.
So most computers nowadays are
sixty for been enabled, and this
allows them to address more memory.
So in the past, we had a mode called
real mode. So real mode used
20 bits for an address.
So they had 16 bit
addresses for the registers,
as we can see.
So we had 16 bit registers,
but they wanted to be able to access
more memory.
And so they would use two, 16 bit
enough numbers and then they would
shift them.
So one was a selector and one was
the offset.
They would shift them in order to
get the address.
Now, this is not great because it
does waste some memory and then
addresses are unique, so there are
multiple ways to come up with the
same unique address
by picking different selectors
or offsets.
So here an example is we might have
and this is in Hex, right?
So we've got eight zero zero zero
in hex and 250 hex.
And so we shift one of these
four bits by adding another zero
and then we add the two together.
And this would give us a real
address that we have.
Now, this is used when we had the
different selectors, so the code
segment, data segment stacked,
segment registers.
But what they did is they introduced
another mode called protected mode,
and so protected mode implements
this notion called virtual memory.
So we have memory and we
load it as needed instead of loading
it all at once.
And we have these things called
virtual addresses.
Now, if it's in 16, that we still
have The Selecter pointing to a
descriptor table, but in 30
to bit, we have a whole bunch of
different segment registers that
point to a
hierarchy of descriptor tables
that we'll see in a little bit.
And then we also have sixty four
bit, so sixty four bit protective
mode would add sixty four
bed addresses and so that means that
we can access up to
16 exabytes of memory, which
is quite a bit it's a lot more than
the four gigabyte.
I remember when I had
a computer that had six gigabytes of
memory and it would only be able to
see four because it was running
a thirty two bit OS.
And so our 32 better dresses go from
zero to all F's
right in hex, and that is four
gigabytes and
we have these segment registers.
So the segment registers will point
to descriptor tables, which then
we have a global descriptor table
which describes globally and
then we have local ones for
different processes.
And so this is a memory hierarchy.
You don't need to know a lot about
it, but you just need to know that
it exists.
Paging it interrupts,
so paging is, is the notion
that not all memory is loaded
and sudden memory can be page
or swapped out to disk.
So if you have a program that might
need four gigabytes of or
10 gigabytes of memory and you only
have four gigabytes, it'll only
load the parts that it's actually
using at any one given time.
And other parts might get swapped
out to this. And this allows you to
run a program that wouldn't fit
all in RAM.
And so when you try and access a
page that isn't in
memory, it generates.
It's called a page fault.
And so that process is then
suspended.
The page that it was trying to
request is unloaded and then the
process is resumed and it continues
as though nothing ever happened.
So the process never sees the fact
that it was suspended.
But that's what happens when a page
is not in memory.
And then interrupts are a way of
interrupting the flow of our program
so you can think of it as we could
have done one way, which
is called pulling, which was where
we ask something if
we ask a device, if something
happens. So you go to the keyboard
and say, did they press the key to
the press? A key to the press, a
key.
But a computer is running
very quickly.
It's running at several gigahertz.
And so it been a lot of time asking
the keyboard if anything happened.
So what we have is when a hardware
device has some information
to the processor might want, it
generates an interrupt so we can
have that for a keyboard, a timer
or a disk, a network traffic or
a sound card.
Additionally, we have software
interrupts, there's two different
categories, so some are
for like illegal memory access
or a software timer, whereas
where you set a timer and then you
want your software to wake up when
that occurs or we
have errors.
So errors are called traps.
So you try and do something that's
totally illegal, going to break
the computer. So, for example,
if you try and divide by zero, the
computer will run
forever doing nothing and trying to
divide by zero.
So that will generate a
trap and it'll stop
the processor from doing that
or we have illegal instructions.
So, for example, you're trying to
run an instruction that
is reserved for the
colonel or you're trying to access
memory that doesn't belong to you.
It belongs to some other process.
And this helps both protect programs
from each other and
gives us security inside of the
system.
So today we talked about computer
organization.
We talked about some of the
registries that we will see later
on. We talked about a little bit of
the history of computers
and different models and when
features were introduced.
And then we talked about memory
paging and interrupts.
Looking forward, we're going to talk
about TEUs compliment in more detail
and additionally hexadecimal.
If you have questions, you can email
me at Miller, MJ at Unclutter Edu,
or you can find me on Twitter at
Milhouse 30.