# [Crash Course]

## Hi! I'm Hanneli (@hannelita)

• Computer Engineer
• Programming
• Electronics
• Math <3 <3
• Physics
• Lego
• Meetups
• Animals
• Coffee
• GIFs
• Pokémon

## Agenda

• Why Assembly?
• The old days - 6800
• Our first program
• QA
• The 8086
• MIPS
• Discussion points
• Where to go from here
• References

## Why Assembly?

• Web Dev is high level programming (usually)
• What does it happen on low level?
• Let's talk about bits, bytes and the world beyond C
• Interesting for CPU design
• It helps on performance tuning
• Learn by curiosity

## Why Assembly?

• Logical puzzles
• Communication with hardware
• Deep understanding of computers
• I wish I had learned Assembly in a pleasant way (my experience was very, very unpleasant)

The sketch

# Old stuff

## Agenda

• Why Assembly?
• The old days - 6800
• Our first program
• QA
• The 8086
• MIPS
• Discussion points
• Where to go from here
• References

1975

# Registers

(Insert binaries here)

# Accumulator A

A

We can read and write data

A == #1h

# On 6800, besides Accumulator A, we have another similar register. (guess its name)

A

B

## Agenda

• Why Assembly?
• The old days - 6800
• Our first program
• QA
• The 8086
• MIPS
• Discussion points
• Where to go from here
• References

• LDAA #0h
• LDAB #1h
• ABA

## Agenda

• Why Assembly?
• The old days - 6800
• Our first program
• QA
• The 8086
• MIPS
• Discussion points
• Where to go from here
• References

## Questions

• What is the initial value of A and B?
• When I perform the ADDA instruction, where does the result go?
• How does the program know which is the next instruction?
• Am I free to manipulate the content of all of the registers?
• WTH is #?
• Can I manipulate hex numbers only?
• Are the numbers signed or unsigned?
• What happens if the result is larger than 8 bits?

What is the initial value of A and B?

When I perform the ADDA instruction, where does the result go?

To A. The results of almost all of the operations usually go to A.

So... Is A mutable?

Yes.

So do I loose the initial value of A after ADDA?

Yes.

Ouch.

Yes.

How does the program know which is the next instruction?

There is (for almost all of the CPUs) a special register that points to the next instruction. We call it Program Counter (PC). At the beginning of the program, it points to zero or any other value established by the manufacturer. The first instruction starts there.

So, are the instructions in memory?

For the 6800, yes.

Am I free to manipulate the content of all of the registers?

Not all of them. There are some that only accept memory addresses as parameters. Other do not support any kind of operation, except for transferring memory addresses.

Yes.

WTH is #?

What does it happen if I remove #? Fail?

Not in terms of syntax. Removing #, the CPU will load the content of the position 0h of the memory.

So removing # gives us a different address mode, right?

Yep! We call it direct addressing. With #, we have the immediate addressing.

Can I manipulate hex numbers only?

No. You can manipulate binaries, decimals. But hex is more common.

Are the numbers signed or unsigned?

We have both representations. Usually, for signed numbers, the left bit represents the signal. For example:

10000001 can be 129 or -1

Who does determine if it is signed or unsigned?

The program's context. And it is tricky. Do not mix them up!

What happens if the result is larger than 8 bits?

# Flag status register

(each CPU has its own)

## Flag status

• Carry, Parity, Zero, Sign, Overflow
• Each bit is a flag
• We need to interpret it properly.

# How can we load and manipulate numbers larger than 8 bits?

## Alternatives

• 16 bits = 8 bits + 8 bits - slice the operation (it is a lot of work!)

## Agenda

• Why Assembly?
• The old days - 6800
• Our first program
• QA
• The 8086
• MIPS
• Discussion points
• Where to go from here
• References

1978

# 8086: Your new (old) processor

Data bus - 16 bits

More registers

More instructions

# 8086: Your new (old) processor

Registers

A

B

C

D

(Accumulator)

(Base)

(Counter)

(Data)

Segmented memory model

CS

DS

SS

ES

(Code)

(Data)

(Stack)

(Extra)

(Code)

(Data)

(Stack)

# With this old new processor, we can do a lot:

• Subroutines
• Macros
• Float point arithmetics
• Manage interruptions (external devices)

# ~1980's, people started to dislike this complex instruction set

## Agenda

• Why Assembly?
• The old days - 6800
• Our first program
• QA
• The 8086
• MIPS
• Discussion points
• Where to go from here
• References

1984

# Reduced instruction set

Simplified set of instructions, similar to several processors in the market.

## Agenda

• Why Assembly?
• The old days - 6800
• Our first program
• QA
• The 8086
• MIPS
• Discussion points
• Where to go from here
• References

# I wanna do Assembly.

## Agenda

• Why Assembly?
• The old days - 6800
• Our first program
• QA
• The 8086
• MIPS
• Discussion points
• Where to go from here
• References

# Try ARM. (RISC)

## Modern Intel (simplified)

http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-instruction-set-reference-manual-325383.pdf

(2k pages)

# (Protip - several concepts are similar to the old 8086 days)

## Agenda

• Why Assembly?
• The old days - 6800
• Our first program
• QA
• The 8086
• MIPS
• Discussion points
• Where to go from here
• References

## References

• http://www.alldatasheet.com/datasheet-pdf/pdf/82499/MOTOROLA/6800.html
• http://www.ece.cmu.edu/~ece740/f11/lib/exe/fetch.php?media=wiki:8086-datasheet.pdf
• "The Art of Assembly Language" (Book)

## Thank you :)

Questions?

hannelita@gmail.com

@hannelita

#### Assembly - BuildStuff

By Hanneli Tavante (hannelita)

• 3,506